יחידה:Wiki99

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

יחידה זו יוצרת טבלה של דפי פריטים בוויקינתונים, ומציגה האם קיים קישור ויקינתונים בין כל דף ויקינתונים לערך בוויקיפדיה העברית.

פרמטרים[עריכת קוד מקור]

  • פרמטרים 1, 2, 3 וכך הלאה – דפי הפריטרים בוויקינתונים.
  • תמונה – האם יש להציג עמודה של תמונה לכל דף פריט.
  • תיאור – עמודה של תיאור הפריט בעברית (במקרה ואין בעברית, הוא יציג באנגלית).

דוגמאות[עריכת קוד מקור]

ללא פרמטרים[עריכת קוד מקור]


he
1כדור הארץQ2
2הירח הירחQ405
3השמשQ525
4מיםQ283
5היסטוריהQ309
6אדםQ5
7אשQ3196
8היקוםQ1
9חייםQ3
10מוותQ4
11שמיםQ527
12דעתQ450
13אושרQ8

עם הפרמטר "תמונה"[עריכת קוד מקור]

תמונה
he
1כדור הארץQ2
2הירח הירחQ405
3השמשQ525
4מיםQ283
5היסטוריהQ309
6אדםQ5
7אשQ3196
8היקוםQ1
9חייםQ3
10מוותQ4
11שמיםQ527
12דעתQ450
13אושרQ8

עם הפרמטר "תיאור"[עריכת קוד מקור]


תיאורhe
1כדור הארץכוכב הלכת השלישי מהשמש במערכת השמשQ2
2הירח הירחהלוויין הטבעי היחיד של כדור הארץQ405
3השמשהכוכב (שמש) הקרוב ביותר לכדור הארץQ525
4מיםתרכובת כימית בסיסית ההכרחית לקיום כל צורות החייםQ283
5היסטוריהמחקר אירועי העבר ותיעודםQ309
6אדםמין בסוג אדםQ5
7אשתהליך חמצון בו משתחררים חום ואורQ3196
8היקוםמכלול הפלנטות, כוכבים, גלקסיות, החלל הבין-גלקטי, או כל החומר והאנרגיהQ1
9חייםתכונה מהותית המאפיינת אורגניזמים ביולוגייםQ3
10מוותמצב שבו גוף חי חדל לחיותQ4
11שמיםרקיעQ527
12דעתהיסוד או הכושר האנושי המאפשר לאדם לחשוב, להרגיש ולהיות מודע הן לחוויה האישית שלו והן לסביבתו החיצונית.Q450
13אושרמצב נפשי של תחושה טובה ורגשות נעימיםQ8

עם הפרמטרים "תמונה" ו-"תיאור"[עריכת קוד מקור]

תמונה
תיאורhe
1כדור הארץכוכב הלכת השלישי מהשמש במערכת השמשQ2
2הירח הירחהלוויין הטבעי היחיד של כדור הארץQ405
3השמשהכוכב (שמש) הקרוב ביותר לכדור הארץQ525
4מיםתרכובת כימית בסיסית ההכרחית לקיום כל צורות החייםQ283
5היסטוריהמחקר אירועי העבר ותיעודםQ309
6אדםמין בסוג אדםQ5
7אשתהליך חמצון בו משתחררים חום ואורQ3196
8היקוםמכלול הפלנטות, כוכבים, גלקסיות, החלל הבין-גלקטי, או כל החומר והאנרגיהQ1
9חייםתכונה מהותית המאפיינת אורגניזמים ביולוגייםQ3
10מוותמצב שבו גוף חי חדל לחיותQ4
11שמיםרקיעQ527
12דעתהיסוד או הכושר האנושי המאפשר לאדם לחשוב, להרגיש ולהיות מודע הן לחוויה האישית שלו והן לסביבתו החיצונית.Q450
13אושרמצב נפשי של תחושה טובה ורגשות נעימיםQ8

-- Wiki99: builds a table of articles translated in many languages, based on sitelinks and properties from a list of Wikidata elements.
-- Can be used to list 400+ articles on 1.
-- Derived from WikimediaCEETable by User:Voll, with additions by Halibutt, Braveheart, Jura1, Strainu, Yupik, Verdy_p
-- Original at https://meta.wikimedia.org/wiki/Module:wiki99. Please contribute amendments there and keep copies in sync with that version.

-- This must constain ONLY standard BCP 47 codes used to query Wikidata elements by language
-- (see the next table for legacy Wikimedia codes used for interwiki links).
-- SHOULD be lowercase only, and separators MUST be hyphens (-) and not underscores (_).
-- Note that sitelinks can only be queried on Wikidata by replacing hyphens (-), used in actual interwiki prefixes and domain names, by underscores (_).
local langTable = { 'he' }

-- Icons for languages indexed by their BCP 47 code
local langIcons = {
    he = "Israel-orb.png",
}

local sub = string.sub
local gfind = string.gfind
local insert = table.insert
local remove = table.remove
local clone = mw.clone
local encode = mw.uri.encode

local myFrame = mw.getCurrentFrame()
local myLang = myFrame:callParserFunction('Int', 'Lang'):lower():gsub('_', '-')
local myLangBCP47 = myLang
myLang = myLangBCP47
local myLangObj = mw.language.new(myLang)

local function formatNum(number)
    return myLangObj:formatNum(number)
end

local myFallbacks = myLangObj:getFallbackLanguages()
for i, lang in ipairs(myFallbacks) do
    lang = lang:lower():gsub('_', '-')
    if lang == myLang then
        remove(myFallbacks, i)
        break
    end
end
insert(myFallbacks, 1, myLang)

local function getLangTable()
    local t = {}
    local u = {} -- Used to detect duplicates.
    -- First insert my language and its fallbacks.
    for i, lang in ipairs(myFallbacks) do
        lang = lang:lower():gsub('_', '-')
    end
   -- Then insert the specified languages (also avoiding duplicates).
    for i, lang in ipairs(langTable) do
        lang = lang:lower():gsub('_', '-')
        if not u[lang] then
            insert(t, lang)
            u[lang] = true
         end
    end
    return t
end

local function formatNumCell(number, class)
    if number == 0 then
        return '<td class=n>' -- Empty cell (red)
    end
    return '<td' .. (class and (' class=' .. class) or '') .. '>' .. formatNum(number)
end

local fetchLanguageName = mw.language.fetchLanguageName

local function setOf(keys, set)
    set = set or {}
    for _, k in ipairs(keys) do
        set[k] = true
    end
    return set
end

-- List of properties to ignore in the count of "main" properties for the topic: exclude internal or external identifiers, 
-- wikilinks and URLs to pages or sites covering the topic, as well as presentational and sandbox properties.
local internalProperties = setOf{
    'P213', -- ISNI
    'P227', -- GND ID
    'P244', -- 	Library of Congress authority ID
    'P345', -- IMDb ID
    'P373', -- Commons category
    'P460', -- said to be the same as, identical to
    'P856', -- official website
    'P910', -- topic's main category
    'P948', -- page banner (image at top of an article about the topic, mainly used by Wikivoyage and Women in Red)
    'P973', -- described at URL
    'P1325', -- external data available at
    'P1343', -- described by source
    'P4045', -- Sandbox-Tabular data
    'P4047', -- Sandbox-Geographic shape
    'P4656', -- Wikimedia import URL
    'P7782', -- category for ship name
    'P7861', -- category for files created with program (most often on Commons)
    'P7867', -- category for maps (most often on Commons)
    'P8464', -- content partnership category (on Commons)
    'P7561', -- category for the interior of the item
    'P8596', -- category for the exterior of the item
    'P8933', -- category for the view from the item
    'P8989', -- category for the view of the item
    'P9126', -- Commons media contributed by (contributing organization)
    'P10032', -- Museu da Pessoa History
}

-- Properties for image files (in order of preference)
local fileProperties = {
    'P154', -- logo image
    'P41', -- flag image
    'P94', -- coat of arms image
    'P158', -- seal image
    'P4004', -- escutcheon image, shield
    'P2425', -- service ribbon image
    'P8766', -- rank insignia (e.g. military)

    'P18', -- image
    'P10093', -- image with color chart

    'P242', -- locator map image
    'P15', -- route map
    'P1621', -- detail map
    'P1943', -- location map
    'P1944', -- relief location map
    'P207', -- bathymetry image

    'P14', -- traffic sign
    'P3383', -- film poster (movie)
    'P3311', -- image of design plans
    'P996', -- document file, scan image, book image, PDF
    'P3030', -- sheet music, musical score
    'P2343', -- playing range image (music)

    'P109', -- signature (image), autograph
    'P7457', -- creator's signature
    'P1543', -- monogram
    'P8195', -- ex-libris, bookplate (for a person)
    'P1801', -- commemorative plaque image
    'P1442', -- image of grave
    'P9906', -- inscription image

    'P692', -- Gene Atlas Image
    'P4640', -- photosphere image

    'P491', -- orbit diagram (astronomical)
    'P367', -- astronomic symbol image
    'P5962', -- sail emblem
    'P9664', -- named place on map
    'P4896', -- 3D model
    'P117', -- chemical structure
    'P5555', -- schematic diagram
    'P6655', -- stroke order (for Han ideographs)
    'P2910', -- icon

    'P5252', -- winter view
    'P3451', -- nighttime view
    'P8592', -- aerial view of the subject, orthophoto, satellite image
    'P2713', -- sectional view

    'P1766', -- place name sign
    'P8667', -- twin town sign
    'P9721', -- image of entrance
    'P5775', -- image of interior (indoor)
    'P8517', -- view (from the from the given site)
    'P4291', -- panoramic view
    'P2716', -- collage image

    'P1846', -- distribution map
    'P181', -- taxon range map image
    'P6802', -- related image (alternate, secondary, decorative, placeholder...)

    'P10', -- video

    'P990', -- audio recording of the subject's spoken voice
    'P443', -- pronunciation audio
    'P989', -- spoken text audio
    'P51', -- audio
}

-- List of properties to count as additional informative properties on Commons 
local commonsProperties = setOf{
    'P935', -- Commons gallery
    'P1472', -- Commons Creator page
    'P1612', -- Commons Institution page
    'P2033', -- category for pictures taken with camera
    'P3896', -- geoshape (for vector maps)
    'P4150', -- weather history (tabular data)
    'P4179', -- tabular population
    'P4669', -- tabular software version
    'P8204', -- tabular case data (confirmed cases, recoveries, deaths, etc. due to a medical event)
    'P8265', -- based on tabular data
    'P10358', -- original catalog description (from institutional catalog metadata)
}
setOf(fileProperties, commonsProperties)

local wikibase = mw.wikibase
local getLabelWithLang = wikibase.getLabelWithLang
local getEntityObject = wikibase.getEntityObject
local renderSnak = wikibase.renderSnak

local function getmainsnakid(entity, property)
    local stmt = entity:getBestStatements(property)[1]
    return stmt
        and stmt.mainsnak.snaktype == 'value'
        and stmt.mainsnak.datavalue.type == 'wikibase-entityid'
        and stmt.mainsnak.datavalue.value['id']
        or nil
end

local function renderDate(entity, property)
    local stmt = entity:getBestStatements(property)[1]
    if stmt then
        local snak = stmt.mainsnak
        if snak.snaktype == 'value' and snak.datavalue.type == 'time' then
            if snak.datavalue.value.precision > 9 then
                -- More precise than year, make it year-precise.
                -- Make a deep copy to make sure we don’t change anything outside of this.
                snak = clone(snak)
                snak.datavalue.value.precision = 9 -- year:9, month:10, day:11, hour:12, minute:13, second:14, fraction:15
            end
            -- Don't render dates with a precision less than the year
            if snak.datavalue.value.precision >= 9 then
                return renderSnak(snak)
            end
        end
    end
    return nil
end

---------------------------------------------------------------------------------------------------
local p = {}

--[[
Wiki99.count: counts articles from the list in certain wiki.
Sample use:
    {{#invoke:Wiki99|table|Q1|Q2|Q3|Q4|Q5}}
    {{#invoke:Wiki99|table|Q1|Q2|Q3|Q4|Q5|lang=en,simple}}
]]
function p.table(frame)
    local result = {
        frame:extensionTag{name = 'templatestyles', args = {src = 'Template:Wiki99/styles.css'}},
        '<div class="wiki99 mw-content-', 'rtl',
        '" lang="', myLangBCP47,
        '"><table class=sortable><tr>',
    }

    -- Rank column (R)
    insert(result, '<th class=R>')

    -- Optional Image column (F)
    local image = frame.args['תמונה']
    if image then
        insert(result, '<th class="F unsortable">')
        insert(result, 'תמונה')
    end

    -- Wikipedia articles column (A)
    insert(result, '<th class=A>')
    insert(result, '[[File:Wikipedia-logo.svg|x20px|link=|alt=]]<br>')

    -- Optional description column (D)
    local description = frame.args['תיאור']
    if description then
        insert(result, '<th class="D unsortable">')
        insert(result, 'תיאור')
    end

    -- Languages columns (L)
    local langTable = getLangTable()
    for i, iw in ipairs(langTable) do
        local langBCP47 = iw
        local langName = fetchLanguageName(langBCP47, myLangBCP47)
        insert(result, '<th class="L unsortable" title="')
        insert(result, (fetchLanguageName(langBCP47, myLangBCP47):gsub('"', '&#34;')))
        insert(result, '">')
        if langIcons[langBCP47] then
            insert(result, '[[File:')
            insert(result, langIcons[langBCP47])
            insert(result, '|20px|link=|alt=]]')
        end
        insert(result, langBCP47)
    end

    -- Wikidata column (Q)
    insert(result, '<th class=Q>[[File:Wikidata-logo.svg|x20px|link=|alt=]]<br>')

    -- Enumerate QIDs in parameters and generate one table row for each
    local statementst = 0
    local coords = 0
    local images = 0
    local timeline = 0
    local wqsitems = ''
    local ids = {}
    local ctt = {}
    local commonst = 0
    for i = 1, #langTable do
        ctt[i] = 0
    end
    local anum = 0
    while true do
        local qid = frame.args[anum + 1]
        if not qid then
            break
        end
        qid = qid:gsub('^%s+', ''):gsub('%s+$', '') -- strip leading/trailing whitespace
        wqsitems = wqsitems .. ' wd:' .. qid
        local id = sub(qid, 2)
        insert(ids, id)
        local entity = getEntityObject(qid)
        if not entity then
            return '<strong class=error>Entity ' .. qid .. ' not found</strong>'
        end

        -- Count main statements on Wikidata and detect extra properties to Wikimedia Commons)
        local commons = 0
        local statements = 0
        if entity.claims then
            for property, statement in pairs(entity.claims) do
                local snak = statement[1].mainsnak
                if snak then
                    if not internalProperties[property] then
                        if snak.datatype ~= 'external-id' then
                            statements = statements + 1
                        end
                    end
                    if commonsProperties[property] then
                        commons = commons + 1
                    end
                end
            end
        end

        --- New data row
        insert(result, '<tr>')

        -- Rank column (R)
        anum = anum + 1
        insert(result, '<th class=R>')
        insert(result, formatNum(anum))

        -- Optional image column (F)
        if image then
            local file
            for i, prop in ipairs(fileProperties) do
                local stmt = entity:getBestStatements(prop)[1]
                filename = stmt
                    and stmt.mainsnak.snaktype == 'value'
                    and stmt.mainsnak.datavalue.type == 'string' --'commonsMedia'
                    and stmt.mainsnak.datavalue.value
                if filename and filename ~= '' then
                    break
                end
            end
            if not filename or filename == '' then
                insert(result, '<td class=n>') -- Empty cell (red)
            else
                insert(result, '<td class=F>[[File:')
                insert(result, filename)
                insert(result, '|80x120px|alt=]]')
                images = images + 1
            end
        end

        -- Wikipedia articles column (A)
        -- (show the best Wikidata label, linked to the first article found in a Wikipedia from the fallbacks list)
        local label, labelLang = entity:getLabelWithLang()
        if not label then
            insert(result, '<td class=An>') -- Empty cell (red)
        else
            local hrefLang, sitelinkLang, sitelink
            local usingFallback = false
            for i, lang in ipairs(myFallbacks) do
               hrefLang = lang
               sitelinkLang = lang
               sitelink = entity:getSitelink(sitelinkLang:gsub('-', '_') .. 'wiki')
               if sitelink then
                   break
               end
                usingFallback = true
            end
            insert(result, '<td class=A')
            insert(result, sitelink and not usingFallback and '' or '')
            if labelLang ~= myLangBCP47 then
                insert(result, ' lang="')
                insert(result, labelLang)
                insert(result, '" dir=auto')
            end
            insert(result, '>')
            if not sitelink then
                insert(result, label)
            else
                insert(result, '[[:')
                insert(result, sitelinkLang)
                insert(result, ':')
                insert(result, sitelink)
                insert(result, '|')
                if hrefLang == labelLang then
                    insert(result, label)
                else
                    insert(result, '<span lang="')
                    insert(result, labelLang)
                    insert(result, '">')
                    insert(result, label)
                    insert(result, '</span>')
                end
                insert(result, ']]')
            end
        end
        local date1, date2
        if getmainsnakid(entity, 'P31') == 'Q5' then -- instance of: human
            -- Gender icon
            local genderid = getmainsnakid(entity, 'P21')
            if genderid == 'Q6581097' or genderid == 'Q2449503' or genderid == 'Q27679766' then
                --  males (Q6581097), transgender males (Q2449503) transmasculines (Q27679766),
                insert(result, ' [[File:Male Icon.svg|15px|link=|alt=♂]]')
            elseif genderid == 'Q6581072' or genderid == 'Q1052281' or genderid == 'Q27679684' then
                -- females (Q6581072), transgender females (Q1052281), and transfeminines (Q27679684),
                insert(result, ' [[File:Female Icon.svg|15px|link=|alt=♀]]')
            elseif genderid == 'Q660882' then
              -- hijras (Q660882), neither male or female
                insert(result, ' [[File:MOREmoji transgender symbol 2.svg|15px|link=|alt=⚧️]]')
            end
            -- Lifespan years for humans (Q5)
            date1 = renderDate(entity, 'P569') -- date of birth
            date2 = renderDate(entity, 'P570') -- date of death
        else
            -- Years for other types
           date1 = renderDate(entity, 'P571') -- date of inception, creation, foundation
           date2 = renderDate(entity, 'P576') -- dissolved, abolished or demolished date
           if not date1 and date2 then
               date1 = ''
           elseif not date2 and date1 then
               date2 = ''
           end
           local date = renderDate(entity, 'P580') -- start time
           if date and (not date1 or date < date1) then
               date1 = date
               if not date2 then
                   date2 = ''
               end
           end
           date = renderDate(entity, 'P582') -- end time
           if date and (not date2 or date > date2) then
               date2 = date
               if not date1 then
                   date1 = ''
               end
           end
           date = renderDate(entity, 'P577') -- publication date
           if date and date1 and date < date1 then
               if not date2 then
                   date2 = date1
               end
               date1 = date
           end
        end
        -- Show dates, add to the timeline
        if date1 or date2 then
            insert(result, ' <bdi class=s>(')
            insert(result, date1 or '')
            if date1 ~= date2 then
                insert(result, '–')
                insert(result, date2 or '')
            end
            insert(result, ')</bdi>')
            timeline = timeline + 1
        end
        -- Geolocation coordinates
        local coord = entity:getBestStatements('P625')[1] -- coordinate location
        if coord then
            insert(result, ' [[File:Geographylogo.svg|18px|link=')
            insert(result, 'https://geohack.toolforge.org/geohack.php?language=en&pagename=')
            insert(result, encode(label, 'QUERY'))
            insert(result, '&params=')
            insert(result, coord.mainsnak.datavalue.value.latitude)
            insert(result, '_N_')
            insert(result, coord.mainsnak.datavalue.value.longitude)
            insert(result, '_E')
            insert(result, '|alt=')
            insert(result, label)
            insert(result, '|')
            insert(result, label)
            insert(result, ']]')
            coords = coords + 1
        end

        -- Optional description column (D)
        if description then
            local desc, descLang = entity:getDescriptionWithLang()
            if desc then
                insert(result, '<td class=D ')
                if descLang ~= myLangBCP47 then
                    insert(result, 'lang=')
                    insert(result, descLang)
                    insert(result, ' dir=auto')
                end
                insert(result, '>')
                insert(result, desc)
            else
                insert(result, '<td class=n>') -- Empty cell (red)
            end
        end

        -- Language columns (L)
        local ct = 0
        for i, lang in ipairs(langTable) do
            -- Remap BCP 47 or legacy Wikimedia Interwiki codes to the interwiki codes that are currently working (this may change over time!).
            local iw = lang
            local sitelink = entity:getSitelink(lang:gsub('-', '_') .. 'wiki')
                or iw ~= lang and entity:getSitelink(iw:gsub('-', '_') .. 'wiki')
            insert(result, '<td class=')
            if sitelink then
                insert(result, 'L>[[:')
                insert(result, iw)
                insert(result, ':')
                insert(result, sitelink)
                insert(result, '|✔]]')
                ct = ct + 1
                ctt[i] = ctt[i] + 1
            else
                insert(result, 'n>') -- ✗
            end

        end -- of loop on languages

        -- Wikidata column (Q)
        insert(result, '<td class=Q data-sort-value="')
        insert(result, id)
        insert(result, '">[[d:')
        insert(result, qid)
        insert(result, '|')
        insert(result, qid)
        insert(result, ']]')

    end -- of loop for rows on each item

    insert(result, '</table></div>')
    return table.concat(result)
end

--[[
Wiki99.count: counts articles from the list in certain wiki, based on previous "table" function stripped from all the table formatting.
Sample use:
    {{#invoke:wiki99|count|en|Q1|Q2|Q3|Q4|Q5}}
    {{#invoke:wiki99|count|en|Q1|Q2|Q3|Q4|Q5|lang=en,simple}}
]]
function p.count(frame)
    local myLang = frame.args[1]
    local myLangBCP47 = myLang
    local langTable = getLangTable()

    local ctt = {}
    for i = 1, #langTable do
        ctt[i] = 0
    end

    local anum = 0
    while true do
        local qid = frame.args[anum + 2]
        if not qid then
            break
        end
        anum  = anum + 1

        local entity = getEntityObject(qid)
        if not entity then
            return '<strong class=error>Entity ' .. qid .. ' not found</strong>'
        end
        for i = 1, #langTable do
            local iw = langTable[i]
            local sitelink = entity:getSitelink(iw:gsub('-', '_') .. 'wiki')
            if sitelink then
                ctt[i] = ctt[i] + 1
            end
        end
    end -- of loop counting rows

    -- Number of articles in certain wiki. Straight...
    local ct = 0
    for i = 1, #langTable do
        if langTable[i] == lang then
            ct = ctt[i]
        end
    end
    return wikianum .. '/' .. anum -- Result is two numbers with '/' separator
end

return p