Module:GetShortDescription/sandbox: Difference between revisions

Content deleted Content added
searching for descriptions for pages in sister projects is currently not possible; testing filter against wasted effort trying for sister project link targets
provide indicator if falling back to wikidata
Line 31:
end
 
local function getWikidataDescription( name, lang, not_explicit )
local wikidata_id = mw.wikibase.getEntityIdForTitle( name )
if isEmpty( wikidata_id ) then return nil end
local wikidata_description, wikidata_description_lang = mw.wikibase.getDescriptionWithLang( wikidata_id )
if isEmpty( wikidata_description ) or wikidata_description:match( '^[Nn]one$' ) then return nil end
if notEmptyisEmpty( lang.no ) orand notEmpty( wikidata_description_lang =) and wikidata_description_lang ~= 'en' then return wikidata_description end
wikidata_description, = mLang._lang {
if isEmpty( wikidata_description_lang ) then return nil end,
return mLang._lang {
wikidata_description,
wikidata_description_lang,
rtl italic = lang.rtlitalic,
wikidata_description,
italic nocat = lang.italicnocat,
nocat size = lang.nocatsize,
size cat = lang.sizecat,
cat rtl = lang.cat,rtl
}
rtl = lang.rtl
}end
if notEmpty( not_explicit ) then wikidata_description = { wikidata = wikidata_description } end
return wikidata_description
end
 
Line 123 ⟶ 125:
end
 
local function isSisterProjectPageisSisterProjectLink( name )
local sister_project_prefixes = {
'wiktionary', 'wikt',
Line 156 ⟶ 158:
if isEmpty( name ) then return alarmingMessage( 'requires a page name (including namespace)' ) end
local fallback = args.fallback
if isSisterProjectPageisSisterProjectLink( name ) then return fallback end
local prefer = args.prefer or 'explicit'
local only = args.only
Line 170 ⟶ 172:
if only == 'explicit' then result = getExplicitDescription( name )
elseif only == 'wikidata' then result = getWikidataDescription( name, lang )
elseif prefer == 'explicit' then result = getExplicitDescription( name ) or getWikidataDescription( name, lang, true )
elseif prefer == 'wikidata' then result = getWikidataDescription( name, lang ) or getExplicitDescription( name )
end
Line 181 ⟶ 183:
local args = getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end
local sdd = getShortDescription( args ) or ''
mw.loglogObject( sdd )
return sdd
end