Content deleted Content added
Fred Gandt (talk | contribs) refactor in progress; unfinished and probably non-functional but real life requires my attention |
Fred Gandt (talk | contribs) continued efforts to refactor all the way up the chain; gotta start here though; not done yet |
||
Line 1:
local function pipedLink( title ) return '[[:' .. title .. '|' .. title .. ']]' end▼
local function isEmpty( value ) return value == nil or value == '' end
local function notEmpty( value ) return not isEmpty( value ) end
local function alarmingMessage( message, preview )
message = '<span style="color:#d33">[[Module:GetShortDescription]] ' .. message .. '.</span>'
▲ message = message .. '[[Category:Pages displaying alarming messages about Module:GetShortDescription]]'
end▼
return message
end
-- Grammatically reasonable concatenation of possible issues into one message per problematic link target.
local function previewWarning(
local message = ''
if quantity_of_things.params > 3 then message = message .. ' with extraneous parameters' end
if quantity_of_things.descriptions > 1 then message = message .. ', declaring ' .. quantity_of_things.descriptions .. ' short descriptions' end
if quantity_of_things.templates > 1 or notEmpty( message ) then
message = 'has detected that [[:' ..
mw.addWarning( alarmingMessage( message, true ) )
end
Line 42 ⟶ 29:
if isEmpty( lang.no ) and notEmpty( wikidata_description_lang ) and wikidata_description_lang ~= 'en' then
result.language = wikidata_description_lang
result.wikidata =
wikidata_description_lang,
wikidata_description,
Line 55 ⟶ 42:
end
local function getShortDescription(
local page_content = title_table:getContent()
if isEmpty( page_content ) then return nil end
return nil▼
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.
Line 87 ⟶ 70:
end
possible_short_descriptions[ template_content_index ] = {}
-- Look through the params:
for i, param in ipairs( short_description_template_params ) do
if param == 'noreplace' or mw.ustring.match( param, '^2%s*=%s*noreplace$' ) then
-- Take note of 'noreplace'-ing for establishment of hierarchy later.
Line 98 ⟶ 79:
if not has_equals or param:match( '^1' ) then
if has_equals then param = mw.ustring.gsub( param, '^1%s*=%s*', '' ) end
--
-- If the template has both a numbered and an unnumbered short description;
-- whichever comes last (ltr) will be used for the page, so overwriting works out great.
Line 109 ⟶ 90:
end
local short_descriptions = {}
-- Look through the short descriptions.
for i, possible_short_description in ipairs( possible_short_descriptions ) do
if possible_short_description.description then
Line 120 ⟶ 102:
end
-- Let previewWarning() work out if these numbers are bad.
previewWarning(
if #short_descriptions >= 1 then return short_descriptions[ #short_descriptions ].description end
return nil
Line 164 ⟶ 146:
local function getDescription( args )
local args_name = args.name
if isEmpty( args_name ) then return alarmingMessage( 'requires a page name (including namespace)' ) end
local title, title_table = getTitleAndTable( args_name )
▲ if isSisterProjectLink( title ) then return fallback end
local prefer = args.prefer or 'explicit'
local only = args.only
local lang = {
italic = args.lang_italic,
Line 189 ⟶ 160:
no = args.lang_no
}
-- Pass args_name to getShortDescription() so previewMessages won't be confusing.
if only == 'explicit' then return getShortDescription( title_table, args_name )
elseif prefer == 'explicit' then return getShortDescription( title_table, args_name ) or getWikidataDescription( title, lang )
▲local function
local function main( args )
local description = getDescription( args )
-- Handle requirements and formatting
▲ result = getWikidataDescription( title, lang )
▲ result = getWikidataDescription( title, lang ) or getShortDescription( args_name, title_table ) end
return
end
Line 224 ⟶ 183:
function p.main( frame )
local args = require( 'Module:Arguments' ).getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end
▲ mw.logObject( d )
end
|