Modul:Reference score
Dokumentasjon for denne modulen kan opprettes på Modul:Reference score/dok
local i18n = mw.loadData( 'Module:References/i18n' ) local langPriority = { -- primary language nb=1, -- important languages nn=2, da=3, sv=4, fo=5, is=6, -- main languages en=7, de=8, fr=9, it=10, es=11, pt=12, pl=13, ru=14, ja=15, zh=16 } local domainPriority = { -- primary domain no=1, -- important domains dk=2, se=3, fo=4, is=5, -- main domains eu=6, de=7, fr=8, it=9, es=10, pt=11, pl=12, ru=13, ja=14, zh=15, com=16, org=17, net=18 } local priorityHigh = 5 local priorityLow = 25 local h = {} -- Can be tested in the console with -- `=p.renderCategories()` -- `=p.renderCategories(0)` -- `=p.renderCategories(1)` -- `=p.renderCategories(2)` function h.renderCategories( num ) local wiki = '' if num then wiki = wiki .. mw.ustring.format('[[Category:%s]]', mw.message.newRawMessage( i18n['category-pages-using-references-from-statement'] ):plain() ) if num == 1 then wiki = wiki .. mw.ustring.format('[[Category:%s]]', mw.message.newRawMessage( i18n['category-pages-using-single-reference-from-statement'] ):plain() ) elseif num > 1 then wiki = wiki .. mw.ustring.format('[[Category:%s]]', mw.message.newRawMessage( i18n['category-pages-using-multiple-references-from-statement'], num ):plain() ) end end return wiki end function h.standardFormat(frame, prop) local found = false local hits = 0 local refs = '' for i,v in ipairs( prop.references or {} ) do if v.snaks and not v.snaks.P143 then found = found or true hits = hits + 1 -- hash will merge similar entries refs = refs .. frame:extensionTag( 'ref', mw.wikibase.formatValues( v.snaks ), { name = v.hash } ) end end return mw.wikibase.formatValue( prop.mainsnak ) .. refs .. cats end -- Can be tested in the console with -- `=p.prioritize(mw.wikibase.getAllStatements('Q20', 'P31')[2].references)` -- `=p.prioritize(mw.wikibase.getAllStatements('Q66363708', 'P31')[2].references)` function h.prioritize( list ) local t = {} for _,v in ipairs( list ) do -- do not include any "imported from" if not v.snacks.P143 or not v.snacks.P3452 then local keep = priorityLow -- try language of "title" if v.snacks.P1476 then for _,w in ipairs(v.snacks.P1476) do if w.snaktype == 'value' and w.datatype == 'monolingualtext' then if w.datavalue.type == 'monolingualtext' then local priority = langPriority[w.datavalue.value.language] if priority then -- note that higher number means lower prority keep = (keep < priority) and keep or priority end end end end end -- try root domain of "reference url" if v.snacks.P854 then for _,w in ipairs(v.snacks.P854) do if w.snaktype == 'value' and w.datatype == 'url' then if w.datavalue.type == 'string' then local uri = mw.uri.new( w.datavalue.value ) local root = string.match( uri.path, '%.[^.]+$' ) local priority = domainPriority[root] if priority then -- note that higher number means lower prority keep = (keep < priority) and keep or priority end end end end end -- some entries that usually imply high quality if v.snacks.P92 or v.snacks.P248 then -- note that higher number means lower prority keep = (keep < priorityHigh) and priorityHigh or priority end table.insert( t, keep, v ) end end local compacted = {} for _,v in ipairs(t) do table.insert( compacted, v ) end return compacted end function h.renderReferences( frame ) --return h. ..h.renderCategories( ) end return h