Content deleted Content added
Fred Gandt (talk | contribs) correction for redirect title conversion; will properly test later; so tired |
Fred Gandt (talk | contribs) refactor in progress; unfinished and probably non-functional but real life requires my attention |
||
Line 3:
local mLang = require( 'Module:Lang' )
local function pipedLink(
local function isNone( desc ) return type( desc ) == 'string' and desc:match( '^[Nn]one$' ) end
Line 24:
-- 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 ' .. pipedLink(
mw.addWarning( alarmingMessage( message, true ) )
end
end
local function getWikidataDescription(
local wikidata_id = mw.wikibase.getEntityIdForTitle(
if isEmpty( wikidata_id ) then return nil end
local wikidata_description, wikidata_description_lang = mw.wikibase.getDescriptionWithLang( wikidata_id )
if isEmpty
if isEmpty( lang.no ) and notEmpty( wikidata_description_lang ) and wikidata_description_lang ~= 'en' then
result.language = wikidata_description_lang
wikidata_description_lang,
wikidata_description,
Line 50 ⟶ 52:
}
end
return result
▲ return wikidata_description
end
local function
local page_content =
if isEmpty( page_content ) then
-- Try to avoid asking if the page exists; it can be expensive.
if report_redlinks and not
return nil
end
Line 119 ⟶ 120:
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
end
local function isSisterProjectLink(
local sister_project_prefixes = {
'wiktionary', 'wikt',
Line 142 ⟶ 143:
'phabricator', 'phab'
}
local pre_colon =
if pre_colon then
for i, sister in ipairs( sister_project_prefixes ) do
Line 151 ⟶ 152:
end
-- Resolve redirects (including multiple) to their end target.
local function getShortDescription( args )▼
local function getTitleAndTable( orig_name )
local title_table = mw.title.new( orig_name )
if title == orig_name then
return title, title_table
end
return getTitleAndTable( title )
end
objectify_alarm = args.objectify_alarm
report_redlinks = args.report_redlinks
local args_name = args.name
if isEmpty( args_name ) then return alarmingMessage( 'requires a page name (including namespace)' ) end
local
▲ new_title = new_title.redirectTarget or new_title
▲ local name = new_title.prefixedText
local fallback = args.fallback
if isSisterProjectLink(
local prefer = args.prefer or 'explicit'
local only = args.only
local lang = {
italic = args.lang_italic,
Line 173 ⟶ 189:
no = args.lang_no
}
local result
if only == 'explicit' then
result = getShortDescription( args_name, title_table )
elseif only == 'wikidata' then result = getWikidataDescription( name, lang )▼
elseif only == 'wikidata' then
elseif prefer == 'explicit' then
result =
▲ if isEmpty( result ) then result = getWikidataDescription( name, lang, true )
▲
elseif isNone( result ) then
local wikidata_description = getWikidataDescription(
if notEmpty( wikidata_description ) then
wikidata_description.none = true
Line 187 ⟶ 212:
end
end
elseif prefer == 'wikidata' then result = getWikidataDescription( name, lang ) or getExplicitDescription( args_name, new_title ) end▼
elseif prefer == 'wikidata' then
▲
if isNone( result ) then result = nil end
Line 199 ⟶ 226:
local args = getArgs( frame )
if isEmpty( args ) then return alarmingMessage( 'could not getArgs' ) end
mw.logObject( d )
return d
end
|