وحدة:Cite/functions

من أرابيكا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث
local p = {}
local quall =  require('Module:Cite/quall')
p.Known_properties = {
    "P304", "P50", "P957", "P478", "P98", "P393", "P1476", "P123", "P577", "P433",
    "P275", "P698", "P356", "P958", "P1433", "P1680", "P1683", "P1065" ,"P212",
    "P854","P170","P248","P143"
    } --,"P536","P227"
    
function p.make_P345_link_o( s )
	if not s or s == "" then return "" end
	local IMDB_Table = {
		['tt'] = 'https://www.imdb.com/title/$1/',
		['co'] = 'https://www.imdb.com/search/title?companies=$1',
		['ev'] = 'https://www.imdb.com/event/$1/',
		['nm'] = 'https://www.imdb.com/name/$1/',
		['ni'] = 'https://www.imdb.com/news/$1/',
	}
	local s2 = s:sub(1,2)
	--mw.log("s2" .. s2 )
	if IMDB_Table[s2] then 
		local fo = mw.ustring.gsub( IMDB_Table[s2], '$1', s )
		return fo
	end
	return s
end

function p.authorlist(auth,name)
	if not auth or auth == '' then return nil end
	local list = mw.text.split( auth, '، و')
	local s = {}
	for i, auth in pairs(list) do
		local str = '|' .. name .. i .. '=' .. auth
	if str then table.insert(s, str) end
	end
	return table.concat(s, '\n')
end

function p.labeel(property,text)
    if text then 
        return text
    end
    local pro = mw.wikibase.label( property ) 
    return pro
end


function p.get_property_label( Id )
	local label = mw.wikibase.label( Id )
	return label
end

function p.geturl(url,text)
	if url and url ~= '' then 
		return '[' .. url .. ' ' .. (text or url) .. ']'
	end
end


function p.listquall(frame)
	local list = mw.html.create("table")
	    :addClass("wikitable sortable")
		:addClass('mw-collapsible')
		:addClass('mw-collapsed')
	local head = list:tag("tr")
	head:tag("th"):wikitext("#")
	head:tag("th"):wikitext("العنصر")
	head:tag("th"):wikitext("الخاصية")
	local number = 0
	for v, nam in pairs(quall) do
		for _1, nam1 in pairs(nam) do
			number = number + 1
			local row = list:tag("tr")
			row:tag("td"):tag("span"):wikitext(number)
			local th = row:tag("td")
			local rr = row:tag("td")
			local dd = frame:preprocess("{{Q|Q".. v .."}}") 
			th:tag("span"):wikitext(dd)
			local u = frame:preprocess("{{P|".. nam1[1] .."}}") 
			rr:tag("span"):wikitext(u)
		end
	end
	return list
end

return p