Content deleted Content added
Fred Gandt (talk | contribs) fix returning empty explicits + identify fellback |
Fred Gandt (talk | contribs) cleanup and notes |
||
Line 30:
local result = { wikidata = wikidata_description }
if isEmpty( args.lang_no ) and notEmpty( wikidata_description_lang ) and wikidata_description_lang ~= 'en' then
-- According to the docs this is
result.wikidata = require( 'Module:Lang' )._lang {
wikidata_description_lang,
Line 47:
local function getShortDescription( title_table, args_name, fallback )
local page_content = title_table:getContent()
-- Assume no content
if isEmpty( page_content ) then return { redlink = true } end
local contents_of_all_short_description_templates = {}
-- Because there could be any number of short description templates, and not all where there should be; get all the templates.
for template in page_content:gmatch( '{%b{}}' ) do
Line 60 ⟶ 63:
-- but on an appallingly formatted page, a short description template down by the categories would likely be missed.
end
if #contents_of_all_short_description_templates < 1 then return nil end
local quantity_of_things = {
templates = #contents_of_all_short_description_templates,
Line 66 ⟶ 71:
params = 0
}
local possible_short_descriptions = {}
for template_content_index, short_description_template_contents in ipairs( contents_of_all_short_description_templates ) do
-- Split the contents at pipes and trim.
Line 93 ⟶ 101:
end
end
local short_descriptions = {}
▲ -- Look through the short descriptions.
-- Look through the possible short descriptions for definite short descriptions,
-- and prepare for working out which of possibly multiple short descriptions is actually being applied for the page:
for i, possible_short_description in ipairs( possible_short_descriptions ) do
if possible_short_description.description then
Line 105 ⟶ 116:
end
end
-- Let previewWarning() work out if these numbers are bad.
previewWarning( args_name, quantity_of_things )
if #short_descriptions >= 1 then
-- Pop!
local short_description = short_descriptions[ #short_descriptions ].description
if notEmpty( short_description ) then return { explicit = short_description, fellback = fallback } end
end
return nil
end
Line 154 ⟶ 169:
local function getDescription( args )
local args_name = args.name
if isEmpty( args_name ) then return { alarm = 'requires a page name (including namespace)' } end
local title, title_table = getTitleAndTable( args_name )
if isSisterProjectLink( title ) then return nil end
local only = args.only
local prefer = args.prefer or 'explicit'
-- Pass args_name to getShortDescription() so previewWarning()s won't be confusing for redirects.
if notEmpty( only ) then
if only == 'explicit' then return getShortDescription( title_table, args_name ) end
if only == 'wikidata' then return getWikidataDescription( title, args ) end
return { alarm = 'accepts either "explicit" or "wikidata" as the value of |only=' }
end if notEmpty( prefer ) then
if prefer == 'explicit' then
local short_description = getShortDescription( title_table, args_name )
if notEmpty( short_description ) then
-- Assume a Wikidata search would be a bad idea for an assumed nonexistent title.
if short_description.redlink or ( not isNone( short_description.explicit ) or args.none_is_valid ) then return short_description end
end
return getWikidataDescription( title, args, true )
end if prefer == 'wikidata' then return getWikidataDescription( title, args ) or getShortDescription( title_table, args_name, true ) end
return { alarm = 'accepts either "explicit" or "wikidata" as the value of |prefer=' }
Line 197 ⟶ 222:
function p.main( frame )
local args = require( 'Module:Arguments' ).getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end -- This really would be alarming.
▲ local result = main( args )
end
return p
|