![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
local getArgs = require( 'Module:Arguments' ).getArgs
local function getImplicitDescription()
local current_title = mw.title.getCurrentTitle()
if not current_title then
return errorMessage( 'could not getCurrentTitle' )
end
local page_content = mw.title.new( current_title ):getContent()
if not page_content then
return errorMessage( 'could not getContent of ' .. safePipedLink( name ) )
end
local all_templates = string.match( page_content, '{%b{}}' )
return mw.text.nowiki( all_templates )
--[[
for m in string.gmatch( 'string', 'pattern' ) do
mw.log( m )
end
--]]
-- let's assume that implicit descriptions will generally be set by infoboxes, but could be from anywhere
-- it would therefore makes sense to cycle through any infoboxes first
--[[ get the lead infoboxes (there might be none or many) first, since they're the most likely to place any implicit description ]]
--[[ since we will be preprocessing them, strip a bunch of stuff we definitely don't need or want ]]
--[[ being infoboxes; there SHOULD be no references, but since when did that stop anyone? -_- ]]
--local lead_infoboxes = getTransclusion( 'The Partisan#', { only = 'templates', categories = 0, references = 0, files = 0, templates = '[Ii]nfobox' } )
--mw.log( lead_infoboxes )
--[[ split the results, and loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if we didn't get a hit...
--[[ get any remaining infoboxes; multiple infoboxes is unusual, but this will unfortunately get the lead infobox again if there is one ]]
--[[ why not just do this first? because it's much more expensive and a lot less likely to be useful ]]
--[[ again; strip the stuff we don't need or want ]]
--local all_infoboxes = getTransclusion( 'The Partisan', { only = 'templates', categories = 0, references = 0, files = 0, templates = '[Ii]nfobox' } )
--mw.log( all_infoboxes )
--[[ split the results ]]
--[[ obviously, we don't want to preprocess the same infobox again, so ignore it ]]
--[[ if there are any more, loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if they weren't helpful, it's probably a good idea to stop doing this, but if you insist...
--[[ get all templates that aren't {{cite*}}s; it would be nice to not get infoboxes too, but that doesn't seem possible ]]
--[[ again; strip the stuff we don't need or want ]]
--local all_other_templates = getTransclusion( 'The Partisan', { only = 'templates', categories = 0, references = 0, files = 0, templates = '-[Cc]ite' } )
--mw.log( all_other_templates )
--[[ split the results ]]
--[[ obviously, we don't want to preprocess the infoboxes again, so ignore them ]]
--[[ if there are any more, loop through them ]]
--[[ preprocess and check for a description match ]]
--[[ if we get a hit; return the description ]]
-- if they didn't spit one out, we consider ourselves lucky to have survived
-- NOTE: if there are multiple implicit descriptions being set, it's theoretically possible we could find one that's redundant
-- I have zero intention to address this possibility
--[[
local current_title_lead_infobox = getTransclusion( tostring( current_title ), { only = 'templates' } )
if not current_title_lead_infobox then
return nil
end
current_title_lead_infobox = mw.text.trim( current_title_lead_infobox )
if not current_title_lead_infobox or current_title_lead_infobox == '' then
return nil
end
local current_frame = mw.getCurrentFrame()
if not current_frame then
return errorMessage( 'could not getCurrentFrame' )
end
local preprocessed_current_title_lead_infobox = current_frame:preprocess( current_title_lead_infobox )
if not preprocessed_current_title_lead_infobox then
return errorMessage( 'could not preprocess current_title_lead_infobox' )
end
-- <div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">19th episode of the 7th season of Star Trek: Voyager</div>
-- right at the start too :)
return mw.text.nowiki( preprocessed_current_title_lead_infobox )
--]]
end
local p = {}
function p.getImplicitDescription( frame )
local args = getArgs( frame )
local implicit_description = getImplicitDescription() -- this is going to be horrible
mw.log( implicit_description )
return implicit_description
end
local sisters = {
'wiktionary', 'wikt',
'wikinews', 'n',
'wikibooks', 'b',
'wikiquote', 'q',
'wikisource', 's',
'wikispecies', 'species',
'wikiversity', 'v',
'wikivoyage', 'voy',
'wikimedia', 'foundation', 'wmf',
'commons', 'c',
'wikidata', 'd',
'meta', 'm',
'incubator',
'mediawikiwiki', 'mw',
'phabricator', 'phab'
}
function p.test( frame )
local args = getArgs( frame )
local name = args.name
if name then
local pre_colon = name:match( '^(%a+):' )
if pre_colon then
for i, sister in ipairs( sisters ) do
if pre_colon == sister then
mw.log( sister )
return nil end
end
end
end
local foo = mw.title.new( name )
foo = foo.redirectTarget or foo
mw.log( foo )
end
return p