Модуль:WikimediaCEETable-uk![]() {{Module rating }} Використання
-- Attribution: [[user:Voll]], with additions by Halibutt, Braveheart, Jura1
-- Localised version based on https://uk.wikipedia.org/wiki/Модуль:WikimediaCEETable as per 22:35, 20 March 2016
-- WikimediaCEETable: builds a list of articles based on information from Wikidata
-- Sample use: {{#invoke:WikimediaCEETable-uk|table|Q1|Q2|Q3|Q4|Q5}}
-- Can be used to list 400+ articles on 1 page
local langTable = { 'uk','en','pl','de','ru','be','be_x_old','bg','crh','cs','hr','hu','ro','sk','sr','tr' }
local p = {}
local function def(bla)
local zdef = {}
for _, l in ipairs(bla) do zdef[l] = true end
return zdef
end
function p.table(frame)
-- header/init
header = {'{| class="wikitable sortable" width=100%\n|-\n! № !! style="width:18%"|Стаття ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="українська мова">укр.</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="англійська мова">англ.</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="польська мова">пол.</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="німецька мова">нім.</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="російська мова">рос.</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="білоруська мова">be</span> ',
'!! class="unsortable" style="font-size:0.8em;line-height:12px"|<span style="border-bottom:1px dotted;cursor:help" title="білоруська мова (тарашкевиця)">be<br/>-t</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="болгарська мова">bg</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="кримськотатарська мова">crh</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="чеська мова">cs</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="хорватська мова">hr</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="угорська мова">hu</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="румунська мова">ro</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="словацька мова">sk</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="сербська мова">sr</span> ',
'!! class="unsortable"|<span style="border-bottom:1px dotted;cursor:help" title="турецька мова">tr</span> ',
'!! Σ <br> !! Вікідані !! <span title="кількість головних тверджень в елементі">st.</span> !! \n|-'}
add_lang_index = 1
while(frame.args["additional_lang"..add_lang_index]) do
table.insert(langTable, frame.args["additional_lang"..add_lang_index])
local img = frame.args["additional_lang_img"..add_lang_index] and '[[File:'..frame.args["additional_lang_img"..add_lang_index]..'|link=|15px]] ' or ''
table.insert(header, #header, '!! class="unsortable"|'..img..frame.args["additional_lang"..add_lang_index]..' ')
add_lang_index = add_lang_index + 1
end
resultTable = table.concat(header);
index = 1
if(frame.args["start_from"]) then offset=frame.args["start_from"]-1 else offset=0 end
ctt = {}
statementst = 0
coords = 0
images = 0
wqsitems = ""
qids = ""
timeline = 0
mylang = frame:preprocess('uk')
for langCount = 1, #langTable do
ctt[langCount] = 0
end
-- rows
while frame.args[index] do
Id = frame.args[index]
local entity = mw.wikibase.getEntityObject(Id)
-- if not entity or not entity.sitelinks then
if not entity then
return '<b>Елемент ' .. Id .. ' не знайдено</b>'
end
Label = entity:getLabel( 'uk' )
local nonuklabel = false
if not Label then
Label = ''
nonuklabel = true
end
local uksitelink = entity:getSitelink( 'ukwiki' )
if ensitelink then
if Label == '' then
Label = uksitelink
end
end
result2 = ''
ct = 0
wqsitems = wqsitems .. "wd%3A" .. Id .. "%20"
qids = qids .. string.sub(Id, 2) .. ","
idinternal = def { "P373", "P948", "P935", "P460", "P856", "P910", "P213", "P1343", "P973", "P345", "P227", "P244","P1612", "P1472", "P1325" }
commonsp = def {'P18','P10','P14','P15','P41','P51','P94','P109','P117','P154','P158','P181','P207','P242','P367', 'P373','P443','P491','P692','P935','P948','P989','P990','P996','P1442','P1472','P1543','P1612','P1621','P1766','P1801','P1846','P1943','P1944'}
-- columns per row
for langCount = 1, #langTable do
local sitelink = entity:getSitelink( langTable[langCount] .. 'wiki' )
if sitelink then
iw = langTable[langCount]
if iw == "be_x_old" then iw = "be-tarask" end
result2 = result2 .. '\n| style="background:#cfc;"|' .. '[[' .. ':' .. iw .. ':' .. sitelink .. '| +]]'
ct = ct + 1
ctt[langCount] = ctt[langCount] + 1
if Label == '' then
Label = sitelink
end
else
result2 = result2 .. '\n| -'
end
end
-- first cells of row
result1 = '|-\n|align=right|' .. (index+offset) .. '\n|'
if uksitelink then
result1 = result1 .. '[[uk:' .. uksitelink .. '|' .. Label ..']]'
else
if not nonuklabel then
result1 = result1 .. '[[' .. Label .. ']]'
else
result1 = result1 .. Label
end
end
local sex = entity:formatPropertyValues( 'P21' ).value
if sex then
if sex == 'жіноча' then
result1 = result1 .. ' [[File:Female Icon.svg|link=|18px]]'
end
end
local p31 = entity:formatPropertyValues( 'P31' ).value
if p31 then
if p31 == 'людина розумна' then
local yr = "%d%d%d%d$"
local p569 = entity:formatPropertyValues( 'P569' ).value
if p569 ~= "" then
if p569:match(yr) ~= nil then
p569 = p569:match(yr)
end
local p570 = entity:formatPropertyValues( 'P570' ).value
if p570 ~= "" then
if p570:match(yr) ~= nil then
p570 = p570:match(yr)
end
result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(' .. p569 .. '-' .. p570 .. ')</span> '
else
result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(b. ' .. p569 .. ')</span>'
end
else
result1 = result1 .. ' <span style="font-size:smaller;font-weight:100">(?)</span>'
end
end
end
local tl = ""
tl = tl .. entity:formatPropertyValues( 'P580' ).value
tl = tl .. entity:formatPropertyValues( 'P569' ).value
tl = tl .. entity:formatPropertyValues( 'P571' ).value
tl = tl .. entity:formatPropertyValues( 'P582' ).value
tl = tl .. entity:formatPropertyValues( 'P576' ).value
tl = tl .. entity:formatPropertyValues( 'P577' ).value
if tl ~= "" then
timeline = timeline + 1
end
local p625 = entity:formatPropertyValues( 'P625' ).value
if p625 ~= "" then
result1 = result1 .. " [[File:Geographylogo.svg|18px|view on maps|link=https://tools.wmflabs.org/geohack/geohack.php?language=en&pagename=" .. mw.uri.encode( Label, "PATH" ) .. "¶ms=" .. entity.claims.P625[1].mainsnak.datavalue.value.latitude .. "_N_" .. entity.claims.P625[1].mainsnak.datavalue.value.longitude .. "_E]]"
coords = coords + 1
end
local p18 = entity:formatPropertyValues( 'P18' ).value
if p18 ~= "" then
images = images + 1
end
-- last cells of row
index = index + 1
local commons = false
local statements = 0
if entity.claims then
for i, statement in pairs( entity.claims ) do
if statement then
if statement[1].mainsnak then
if not idinternal[i] then
if statement[1].mainsnak.datatype ~= 'external-id' then
statements = statements+1
end
end
if commonsp[i] then
commons = true
end
end
end
end
end
-- local statements = #entity:getProperties()
-- todo : check for Commons sitelinks
local commonsstr = ""
if commons then
commonsstr = '<span title="Wikidata item includes Commons resources">+</span>'
-- commonsstr = "[https://commons.wikimedia.org/w/index.php?fulltext=1&search=".. mw.uri.encode( Label, "PATH" ) .. " +]"
end
statementst = statementst + statements
if statements == 0 then
bgcolor = ''
else
bgcolor = 'background:#cfc;'
end
resultTable = resultTable .. result1 .. result2 ..'\n| align=right style="font-size:smaller;"| ' .. ct .. '\n| style="background:#cfc;" data-sort-value="' .. string.sub(Id, 2) .. '"|[[d:' .. Id .. '|' .. Id .. ']] \n|style="' .. bgcolor .. 'font-size:smaller;" align=right title="number of main statements on Wikidata item"|'.. statements .. '\n|style="background:#cfc;"|' .. commonsstr .. '\n'
end
-- footer
tline = ""
if timeline > 2 then
tline = "[https://tools.wmflabs.org/wikidata-timeline/#/timeline?query=" .. mw.uri.encode("items[" .. qids .. "]", "PATH" ) .. " → по часу]"
end
mapme = ""
if coords > 0 or images > 0 then
mapme = "[https://query.wikidata.org/#%23%20click%20%22Execute%22%20to%20run%20the%20query%2C%20then%20%28on%20the%20right%20side%29%20below%20%22Display%22%20select%20the%20link%20%22Map%22%20or%20%22Image%20Grid%22%0ASELECT%20%0A%09%3Fitem%20%0A%09%3FitemLabel%20%0A%09%28GROUP_CONCAT%28%3FinstanceLabel%3B%20separator%3D%22%2C%20%22%29%20as%20%3Finstance_of%29%0A%09%28SAMPLE%28%3Fcoord%29%20as%20%3Fcoordinates%29%0A%09%28SAMPLE%28%3Fimg%29%20as%20%3Fimage%29%0AWHERE%0A{%0A%09VALUES%20%3Fitem%20{%20" .. wqsitems .. "%20}%0A%09OPTIONAL%20{%3Fitem%20wdt%3AP625%20%3Fcoord%20}%20.%20%20%0A%09OPTIONAL%20{%3Fitem%20wdt%3AP31%20%3Finstance%20}%20.%20%20%20%0A%20%20%09OPTIONAL%20{%3Fitem%20wdt%3AP18%20%3Fimg%20}%20.%20%20%20%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. mylang .. "%2Cen%22%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%3Fitem%20rdfs%3Alabel%20%3FitemLabel%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%3Finstance%20rdfs%3Alabel%20%3FinstanceLabel%20}%0A}%0AGROUP%20BY%20%3Fitem%20%3FitemLabel%20 →"
if coords > 0 then
mapme = mapme .. " карта"
end
if images > 0 then
mapme = mapme .. " галерея"
end
mapme = mapme .. "]"
end
local autolist = "[https://tools.wmflabs.org/autolist/?language=" .. mylang .. "&project=wikipedia&wdq=" .. mw.uri.encode("items[" .. qids .. "]", "PATH" ) .. "&run=Run&mode_manual=or&mode_cat=or&mode_wdq=not&mode_wdqs=or&mode_find=or&chunk_size=10000 → Автосписок]"
result1 = '|- align=right style="font-size:smaller" class="sortbottom"\n! Σ \n|' .. autolist .. mapme .. tline
result2 = ''
ct = 0
for langCount = 1, #langTable do
result2 = result2 .. '\n |' .. ctt[langCount]
ct = ct + ctt[langCount]
end
resultTable = resultTable .. result1 .. result2 ..'\n| ' .. ct .. '\n| data-sort-value="999999999999"| сер: <span title="середня кількість мовних версій (' .. #langTable .. ') на статтю">' .. math.floor(ct/(index-1)+0.5) .. '</span>\\<span title="середня кількість статей (' .. (index-1) .. ') на мову">' .. math.floor(ct / #langTable + 0.5) .. '</span>\\<span title="загалом у відсотках (усі: '.. (#langTable * (index-1)) .. ')">' .. math.floor( ct / #langTable / (index-1)*100 + 0.5) .. '%</span>\n|' .. statementst .. '\n| [[File:Commons-logo.svg|link=|16px|Вікісховище]]'
resultTable = resultTable .. '\n|}\n'
return resultTable
end
return p
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia