Module:GetShortDescription/sandbox: Difference between revisions

Content deleted Content added
cleanup and notes
testing redirect changes
Line 45:
end
 
local function getShortDescriptiongetShortDescriptionTemplates( title_table, args_name, fallback )
local page_content = title_table:getContent()
Line 63:
-- but on an appallingly formatted page, a short description template down by the categories would likely be missed.
end
return contents_of_all_short_description_templates
end
 
local function getShortDescription( args_name, args_name_title_table, title, title_table, fallback )
local contents_of_all_short_description_templates = {}
-- Check for short description templates on redirect pages.
if title ~= args_name then
contents_of_all_short_description_templates = getShortDescriptionTemplates( args_name_title_table )
end
if contents_of_all_short_description_templates.redlink then return contents_of_all_short_description_templates end
-- If the provided name was not for a redirect page, or the redirect page had no short description templates:
if #contents_of_all_short_description_templates < 1 then
contents_of_all_short_description_templates = getShortDescriptionTemplates( title_table )
end
if contents_of_all_short_description_templates.redlink then return contents_of_all_short_description_templates end
if #contents_of_all_short_description_templates < 1 then return nil end
Line 156 ⟶ 175:
end
 
-- Literally testing if title_table.isRedirect can be expensive;
-- Resolve redirects (including multiple) to their end target.
-- processing this way reolves (multiple) redirects without the possibly expensive check.
local function getTitleAndTable( orig_name )
local title_table = mw.title.new( orig_name )
Line 169 ⟶ 189:
local function getDescription( args )
local args_name = args.name
if isEmpty( args_name ) then return { alarm = 'requires a page name (including namespace)' } end
local args_name_title_table = mw.title.new( args_name )
args_name = args_name_title_table.prefixedText
local title, title_table = getTitleAndTable( args_name )
Line 182 ⟶ 203:
if notEmpty( only ) then
if only == 'explicit' then return getShortDescription( title_tableargs_name, args_nameargs_name_title_table, title, title_table ) end
if only == 'wikidata' then return getWikidataDescription( title, args ) end
return { alarm = 'accepts either "explicit" or "wikidata" as the value of |only=' }
Line 189 ⟶ 210:
if notEmpty( prefer ) then
if prefer == 'explicit' then
local short_description = getShortDescription( title_tableargs_name, args_nameargs_name_title_table, title, title_table )
if notEmpty( short_description ) then
-- Assume a Wikidata search would be a bad idea for an assumed nonexistent title.
Line 196 ⟶ 217:
return getWikidataDescription( title, args, true )
end
if prefer == 'wikidata' then return getWikidataDescription( title, args ) or getShortDescription( title_tableargs_name, args_nameargs_name_title_table, title, title_table, true ) end
return { alarm = 'accepts either "explicit" or "wikidata" as the value of |prefer=' }
end
Line 223 ⟶ 244:
local args = require( 'Module:Arguments' ).getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end -- This really would be alarming.
returnlocal d = main( args )
mw.logObject( d )
return d
end