Module:GetShortDescription/sandbox: Difference between revisions

Content deleted Content added
if the shortdesc follows WP:SDNONE, treat it as a valid explicit description
testing indication of wikidata fallback being the result of an explicit none
Line 4:
 
local function pipedLink( name ) return '[[:' .. name .. '|' .. name .. ']]' end
 
local function isNone( desc ) return type( desc ) == 'string' and desc:match( '^[Nn]one$' ) end
 
local function isEmpty( value ) return value == nil or value == '' end
Line 36 ⟶ 38:
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:matchisNone( '^[Nn]one$'wikidata_description ) then return nil end
if isEmpty( lang.no ) and notEmpty( wikidata_description_lang ) and wikidata_description_lang ~= 'en' then
wikidata_description = mLang._lang {
Line 89 ⟶ 91:
-- Because regular expressions haven't been invented yet...
-- ignore everything that isn't a declaration of 'noreplace'
-- or a short description that isn't 'none'.
if param == 'noreplace' or mw.ustring.match( param, '^2%s*=%s*noreplace$' ) then
-- Take note of 'noreplace'-ing for establishment of hierarchy later.
Line 96 ⟶ 99:
if not has_equals or param:match( '^1' ) then
if has_equals then param = mw.ustring.gsub( param, '^1%s*=%s*', '' ) end
--if not param:matchisNone( '^[Nn]one$'param ) then
-- If we made it this far; grab the short description.
-- If the template has both a numbered and an unnumbered short description;
Line 103 ⟶ 106:
-- But we want to know the total quantity of descriptions being declared.
quantity_of_things.descriptions = quantity_of_things.descriptions + 1
--end
else
-- If the short description is intentionally blank per [[WP:SDNONE]], treat it
-- as a valid explicit description and return an empty string rather than nil
possible_short_descriptions[ template_content_index ].description = ''
quantity_of_things.descriptions = quantity_of_things.descriptions + 1
end
end
end
Line 175 ⟶ 173:
}
local result
if only == 'explicit' then result = getExplicitDescription( name )
elseif only == 'wikidata' then result = getWikidataDescription( name, lang )
elseif prefer == 'explicit' then
result = getExplicitDescription( name )
if orisEmpty( result ) then result = getWikidataDescription( name, lang, true )
elseif isNone( result ) then
elseif prefer == 'wikidata' then result = getWikidataDescription( name, lang ) or getExplicitDescription( name )
local wikidata_description = getWikidataDescription( name, lang, true )
end
if notEmpty( wikidata_description ) then
wikidata_description.none = true
result = wikidata_description
end
end
elseif prefer == 'wikidata' then result = getWikidataDescription( name, lang ) or getExplicitDescription( name ) end
if isNone( result ) then result = nil end
return result or fallback
end