Modul:Reference score
Dokumentasjon for denne modulen kan opprettes på Modul:Reference score/dok
local i18n = mw.loadData( 'Module:References/i18n' ) local conf = mw.loadData( 'Module:References/conf' ) local highScore = 5 local midScore = 15 local lowScore = 25 local maxRefs = 4 local h = {} -- Can be tested in the console with -- `=p.categories()` -- `=p.categories(0)` -- `=p.categories(1)` -- `=p.categories(2)` function h.categories( num ) local t = {} if num then table.insert( mw.message.newRawMessage( i18n['category-pages-using-references-from-statement'] ):plain() ) if num == 1 then table.insert( mw.message.newRawMessage( i18n['category-pages-using-single-reference-from-statement'] ):plain() ) elseif num > 1 then table.insert( mw.message.newRawMessage( i18n['category-pages-using-multiple-references-from-statement'], num ):plain() ) end end return t 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.score( list ) local t = {} for i=1,lowScore do t[i] = false end for _,v in ipairs( list ) do -- do not include any "imported from" if v.snaks and not( v.snaks.P143 or v.snaks.P3452 ) then --mw.logObject(v.snaks) --do return end local keep = lowScore -- try language of "title" if v.snaks.P1476 then for _,w in ipairs(v.snaks.P1476) do if w.snaktype == 'value' and w.datatype == 'monolingualtext' and w.datavalue.type == 'monolingualtext' then local score = conf.languageScore[w.datavalue.value.language] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- try root domain of "reference url" if v.snaks.P854 then for _,w in ipairs(v.snaks.P854) do if w.snaktype == 'value' and w.datatype == 'url' and w.datavalue.type == 'string' then local uri = mw.uri.new( w.datavalue.value ) local root = string.match( uri.path, '%.[^.]+$' ) local score = conf.domainScore[root] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- try reference to entity for _,u in pairs(v.snaks) do for _,w in ipairs(u) do if w.snaktype == 'value' and w.datatype == 'wikibase-item' and w.datavalue.type == 'wikibase-entityid' then local score = conf.entityScore[w.datavalue.value.id] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- some properties that usually imply somewhat quality if v.snaks.P92 or v.snaks.P248 then -- note that higher number means lower prority keep = (keep < midScore) and keep or midScore end table.insert( t, keep, v ) end end return t end -- Can be somewhat tested by -- =mw.dumpObject(p.compact(p.score(mw.wikibase.getAllStatements('Q40826', 'P569')[1].references))) function h.compact( list, limit ) limit = limit or maxRefs local t = {} local counter = 0 for _,v in ipairs( list ) do if v then counter = counter + 1 if limit and counter <= limit then table.insert( t, v ) elseif not limit then table.insert( t, v ) end end end return t end function h.renderReferences( frame ) local wiki = '' for _,v in ipairs( h.categories( num ) ) do wiki = wiki .. mw.ustring.format('[[Category:%s]]', v ) end return wiki end return h