Module:GetShortDescription/sandbox: Difference between revisions

Content deleted Content added
m sync with live
searching for descriptions for pages in sister projects is currently not possible; testing filter against wasted effort trying for sister project link targets
Line 121:
if #short_descriptions >= 1 then return short_descriptions[ #short_descriptions ].description end
return nil
end
 
local function isSisterProjectPage( name )
local sister_project_prefixes = {
'wiktionary', 'wikt',
'wikinews', 'n',
'wikibooks', 'b',
'wikiquote', 'q',
'wikisource', 's',
'wikispecies', 'species',
'wikiversity', 'v',
'wikivoyage', 'voy',
'commons', 'c',
'wikidata', 'd',
'mediawikiwiki', 'mw',
'wikimedia', 'foundation', 'wmf',
'meta', 'm',
'incubator',
'phabricator', 'phab'
}
local pre_colon = name:match( '^(%a+):' )
if pre_colon then
for i, sister in ipairs( sister_project_prefixes ) do
if pre_colon == sister then return true end
end
end
return false
end
 
Line 128 ⟶ 155:
local name = args.name
if isEmpty( name ) then return alarmingMessage( 'requires a page name (including namespace)' ) end
local resultfallback = args.fallback
if isSisterProjectPage( name ) then return fallback end
local prefer = args.prefer or 'explicit'
local only = args.only
local prefer = args.prefer
if isEmpty( prefer ) then prefer = 'explicit' end
local lang = {
italic = args.lang_italic,
Line 140 ⟶ 167:
no = args.lang_no
}
local result
if only == 'explicit' then result = getExplicitDescription( name )
elseif only == 'wikidata' then result = getWikidataDescription( name, lang )
Line 145 ⟶ 173:
elseif prefer == 'wikidata' then result = getWikidataDescription( name, lang ) or getExplicitDescription( name )
end
return result or args.fallback
end
 
Line 153 ⟶ 181:
local args = getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end
returnlocal sd = getShortDescription( args ) or ''
mw.log( sd )
return sd
end