יחידה:ערך לא קיים

מתוך ויקיפדיה, האנציקלופדיה החופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:ערך לא קיים/תיעוד

local jsonlist = mw.text.jsonDecode(mw.title.new('ערך לא קיים/רשימה.json','Module'):getContent())
local jsonparams = mw.text.jsonDecode(mw.title.new('ערך לא קיים/פרמטרים.json','Module'):getContent())
local blacklist = {}

function draft(frame)
    local ans = {}
    local bl
    for m,n in pairs(jsonlist) do
        bl = false
        for u,v in pairs(blacklist) do
            if (m == v) then
                bl = true
            end
        end
        if (bl == false) then
            ans[m] = n
        end
    end
    table.sort(ans)
    return mw.text.jsonEncode(ans)
end

function checkparam(template, param, value)
	local entry = jsonparams[template]
	local foundparam
	if (entry) then
		foundparam = entry[param]
		if (foundparam) then
			for k,v in pairs(foundparam) do
				if (v == value) then
					return "|" .. param .. "=" .. value
				end
				return throw('ערך לא קיים "' .. value .. '" של פרמטר "' .. param .. '" ב"תבנית:' .. template .. '"')
			end
		end
	end
	return throw('פרמטר לא קיים "' .. param .. '" ב"תבנית:' .. template .. '"')
end

function throw(text)
	return "<br clear=all/><div class=error>" .. text .. "</div><br clear=all/>"
end

function main(frame)
    local pagename = frame:preprocess("{{#titleparts:{{FULLPAGENAME}}}}")
    local template, item, links, parameters, param, value
    local entry = jsonlist[pagename]
    local paramtext = ''
    local allowedparams = jsonlist.temporal
    if (entry) then
        template = entry[2]
        item = entry[1]
        parameters = entry.param
        if (parameters) then
        	param = parameters[1]
        	value = parameters[2]
        	paramtext = checkparam(template, param, value)
        end
        links = getSitelinksFromQid(item, pagename)
        return frame:preprocess('<div class="registered_only hlist plainlinks">{{אזהרה כללית|שימו לב! החלק הבא נוצר '
            .. 'בתור ניסוי, והוא מוצג למשתמשים הרשומים בלבד.}}<br/>'
            .. '<div id="new_page_warning">'
            .. '<div style="border: 1px solid #aaaaaa; background-color: #fafafa; padding: 5px;">'
            .. '<div style="font-size: 115%;">'
            .. "'''{{מגדר:|הגעת|הגעת|הגעתם}} לערך שעדיין אינו קיים.''' "
            .. 'ניתן ליצור את הערך בהתאם להנחיות [[#הנחיות|בהמשך הדף]]. '
            .. 'עד שהערך יווצר, מוצג {{מגדר:|בפניך|בפניך|בפניכם}} מידע גולמי הנקרא [[וק:ערכי הארגמן|ערך ארגמן]]. '
            .. 'נעשה שימוש ב[[תבנית:' .. template .. ']].</div></div></div><br/>'
            .. '{{' .. template .. paramtext .. '|skip parameters validation = 1|qid=' .. item
            .. '}}<table class=wikitable style="text-align:center;">'
            .. links .. '<tr><td colspan=2>{{בקרת זהויות|purple=yes|qid=' .. item .. '}}</td></tr></table></div>'
            .. '<br clear="all"/>')
    else
        return ''
    end
end

function list(frame)
    local ans = {}
    for k,v in pairs(jsonlist)
        do table.insert(ans, '[[' .. k .. ']]<br/>')
    end
    table.sort(ans)
    return frame:preprocess('{{טורים|רוחב=20em|תוכן=' .. table.concat(ans) .. '}}')
end

function count(frame)
    local ans = 0
    for k,v in pairs(jsonlist)
        do
            ans = ans + 1
    end
    return ans
end

function getfirst(t)
    local ans = {}
    for k,v in pairs(t) do
        ans[k] = t[k][1]
    end
return ans
end

function getSitelinksFromQid(item, pagename)
    local converted, app, con, text, needu, langpart, google, googlerest, wresult
    local resTable = mw.wikibase.getEntity(item)['sitelinks']
    if (resTable == nil) then
    	return ''
    end
    local replacedpagename = mw.ustring.gsub(pagename, ' ', '+')
    local rows = 1
    local s = {}
    local t = {}
    local u = {}
    local w = {}
    local upart = ''
        for k,v in pairs(resTable) do
            if v.title then
               converted = convert(k)
               text = converted[3] or converted[1]
               langpart = ''
               if (converted[4]) then
                      langpart = ' lang=' .. converted[4]
               end
               if (converted[2] == 'en.wikipedia') then
                      text = '<span class=nowrap' .. langpart .. ' style="background:yellow;">' .. text .. '</span>'
                   google = v.title
               else
                      text = '<span class=nowrap' .. langpart .. ' dir=auto><bdi>' .. text .. '</bdi></span>'
                   if (converted[4] == 'en') then
                       googlerest = v.title
                   end
               end
               app = '* <span title="' .. (converted[6] or converted[3]) .. ' – ' .. v.title .. '">[https://'
                   .. converted[2] .. '.org/wiki/'.. mw.ustring.gsub(v.title, ' ', '_') .. ' '
                   .. text .. ']</span>\n'
               if (converted[5]) then 
                   table.insert(u, app)
                   needu = true
               elseif (converted[3]) then 
                   table.insert(t, app)
               else
                      table.insert(s, app)
                   con = {'* <span title="' .. (converted[6] or converted[3]) .. ' – ' .. v.title
                           .. '">[https://he.wikipedia.org/w/index.php?title=Special:ContentTranslation&to=he&page=' ..
                        mw.ustring.gsub(v.title, ' ', '+') .. '&from=' .. converted[4] .. '&targettitle=' ..
                        replacedpagename .. ' ' .. text .. ']</span>\n', converted[2]}
                   table.insert(w, con)
               end
            end
        end
    table.insert(t, '* <span title="ויקינתונים – ' .. item .. '">[https://www.wikidata.org/wiki/' .. item
        .. ' [[File:Wikidata-logo.svg|x16px|link=|alt=]] ויקינתונים]</span>\n')
    table.sort(s)
    table.sort(t)
    table.sort(u)
    if (#s == 0) then
    	table.insert(s, 'אין תרגומים')
    	wresult = ''
    else
    	wresult = '<tr><td colspan=2><table class="wikitable mw-collapsible mw-collapsed" style="width:100%;margin:auto">'
        .. '<tr><th>כלי התרגום</th></tr><tr><td>\n'
        .. table.concat(getfirst(w)) .. '</td></tr></table></td></tr>'
    end
    table.sort(w, function(a, b) return a[2] < b[2] end)
    if (needu) then
        upart = '<tr><td>\n' .. table.concat(u) .. '</td></tr>'
        rows = rows + 1
    end
    google = google or googlerest
    if (google) then
        google = '[https://www.google.com/search?q=' .. mw.ustring.gsub(google, ' ', '+') .. ' Google]'
	else
		google = ''
    end
    return '<tr><th>דף זה בשפות אחרות</th><td rowspan=2>'
        .. '[https://www.google.com/search?q=' .. mw.ustring.gsub(pagename, ' ', '+')
        .. ' חיפוש בגוגל]</td></tr><tr><td>\n' .. table.concat(s) .. '</td></tr><tr><td>\n'
        .. table.concat(t) .. '</td><td rowspan=' .. rows .. '>' .. google .. '</td></tr>'
        .. upart .. wresult
end

--[==[
|wikisource.org=[[File:Wikisource-logo.svg|x16px|link=|alt=]]
|wikibooks.org=[[File:Wikibooks-logo.svg|x18px|link=|alt=]]
|wikinews.org=[[File:Wikinews-logo.svg|x18px|link=|alt=]]
|wikipedia.org=[[File:Wikipedia-logo-v2.svg|x18px|link=|alt=]]
|wikiquote.org=[[File:Wikiquote-logo.svg|x18px|link=|alt=]]
|wikisource.org=[[File:Wikisource-logo.svg|x18px|link=|alt=]]
|wikiversity.org=[[File:Wikiversity-logo.svg|x18px|link=|alt=]]
|wiktionary.org=[[File:Wiktionary-logo.svg|x18px|link=|alt=]]
]==]

function convert(code)
    local a, langcode, langname, locallangname, wikicode
    if (code == 'incubatorwiki' or code == 'wikimaniawiki') then
        return
    elseif (code == 'mediawikiwiki') then
        return {'mediawiki', 'www.mediawiki', '[[File:MediaWiki-2020-icon.svg|x16px|link=|alt=]] מדיהוויקי'}
    elseif (code == 'commonswiki') then
        return {'commons', 'commons.wikimedia', '[[File:Commons-logo.svg|x16px|link=|alt=]] ויקישיתוף'}
    elseif (code == 'metawiki') then
        return {'meta', 'meta.wikimedia', '[[File:Wikimedia Community Logo.svg|x18px|link=|alt=]] מטא'}
    elseif (code == 'specieswiki') then
        return {'species', 'species.wikimedia', '[[File:Wikispecies-logo.svg|x16px|link=|alt=]] ויקימינים'}
    else
        a = mw.ustring.find(code, 'wik')
        if (a ~= nil) then
            langcode = mw.ustring.sub(code, 1, a-1)
            langname = '{{#language:' .. langcode .. '}}'
            locallangname = '{{#language:' .. langcode .. '|he}}'
            wikicode = mw.ustring.sub(code, a)
            if (wikicode == 'wiki') then
                return {langname, langcode .. '.wikipedia', nil, langcode, nil, locallangname}
            else
            	if (wikicode == 'wikivoyage') then
            		wikicodename = '[[File:Wikivoyage-Logo-v3-icon.svg|x18px|link=|alt=]] ויקימסע'
            	else
            		wikicodename = wikicode
            	end
                return {langname, langcode .. '.' .. wikicode, langname .. ' (' .. wikicodename .. ')', langcode, true, locallangname}
            end
        end
    end
end

function mobileview(frame)
    local pagename = mw.ustring.gsub(frame:preprocess("{{FULLPAGENAME}}"), "&#39;", "'")
    local entry = jsonlist[pagename]
    if (entry) then
		return frame:preprocess('<div class="registered_only hlist plainlinks">{{אזהרה כללית|שימו לב! החלק הבא נוצר '
            .. 'בתור ניסוי, והוא מוצג למשתמשים הרשומים בלבד.}}') ..
            '<br/>[[$1|ערך ארגמן]]'
	else
		return ''
	end
end

return {main = main, draft = draft, list = list, count = count, mobileview = mobileview}