Content deleted Content added
Fred Gandt (talk | contribs) continued efforts to refactor all the way up the chain; gotta start here though; not done yet |
Fred Gandt (talk | contribs) getting there; taking a break; note the |none_is_valid= param... |
||
Line 3:
local function notEmpty( value ) return not isEmpty( value ) end
local function isNone(
local function alarmingMessage( message, preview )
Line 21 ⟶ 23:
end
local function getWikidataDescription( title,
local wikidata_id = mw.wikibase.getEntityIdForTitle( title )
if isEmpty( wikidata_id ) then return nil end
Line 27 ⟶ 29:
if isEmpty( wikidata_description ) then return nil end
local result = { wikidata = wikidata_description }
if isEmpty(
result.language = wikidata_description_lang
result.wikidata = require( 'Module:Lang' )._lang {
wikidata_description_lang,
wikidata_description,
italic =
nocat =
size =
cat =
rtl =
}
end
Line 78 ⟶ 80:
local has_equals = param:match( '=' )
if not has_equals or param:match( '^1' ) then
-- Grab the short description.
if has_equals then param = mw.ustring.gsub( param, '^1%s*=%s*', '' ) end
▲ -- whichever comes last (ltr) will be used for the page, so overwriting works out great.
▲ possible_short_descriptions[ template_content_index ].description = param
▲ -- But we want to know the total quantity of descriptions being declared.
▲ quantity_of_things.descriptions = quantity_of_things.descriptions + 1
end
end
Line 93 ⟶ 95:
for i, possible_short_description in ipairs( possible_short_descriptions ) do
if possible_short_description.description then
-- If a description is 'noreplace'-ing or 'none'; demote it.
if ( possible_short_description.noreplace or isNone( possible_short_description.description ) ) and #possible_short_descriptions > 1 then
-- But don't demote it if it's already at the bottom.
if i > 1 then table.insert( short_descriptions, #short_descriptions, possible_short_description )
Line 103 ⟶ 105:
-- Let previewWarning() work out if these numbers are bad.
previewWarning( args_name, quantity_of_things )
if #short_descriptions >= 1 then return { explicit = short_descriptions[ #short_descriptions ].description } end
return nil
end
Line 147 ⟶ 149:
local function getDescription( args )
local args_name = args.name
if isEmpty( args_name ) then return
local title, title_table = getTitleAndTable( args_name )
if isSisterProjectLink( title ) then return nil end
local prefer = args.prefer or 'explicit'▼
local only = args.only
local
-- Pass args_name to getShortDescription() so previewWarning()s won't be confusing for redirects.
if notEmpty( only ) then
return { alarm = 'only accepts either "explicit" or "wikidata" as the value of |only=' } end
if notEmpty( prefer ) then
if short_description and ( not isNone( short_description.explicit ) or args.none_is_valid ) then
▲ if only == 'explicit' then return getShortDescription( title_table, args_name )
return short_description
▲ elseif only == 'wikidata' then return getWikidataDescription( title, lang )
end
if prefer == 'wikidata' then return getWikidataDescription( title, return { alarm = 'only accepts either "explicit" or "wikidata" as the value of |prefer=' }
end
end
▲local function isNone( desc ) return type( desc ) == 'string' and desc:match( '^[Nn]one$' ) end
local function main( args )
local
if result then
▲ mw.logObject( description )
if result.alarm then return alarmingMessage( result.alarm ) end
end
return
end
|