Content added Content deleted
m (Changed protection level of Module:Message box: High-risk Lua module: used in system messages ([Edit=Block all non-admin users] (indefinite) [Move=Block all non-admin users] (indefinite))) |
(fix talk page links, and fix bug producing spurious WhatLinksHere links (however note that a link will appear for Foo if the code "talk=Foo" is used)) |
||
Line 20: | Line 20: | ||
local box = {} |
local box = {} |
||
local function getTitleObject(page) |
local function getTitleObject(page, ...) |
||
if type(page) == 'string' then |
if type(page) == 'string' then |
||
-- Get the title object, passing the function through pcall |
-- Get the title object, passing the function through pcall |
||
-- in case we are over the expensive function count limit. |
-- in case we are over the expensive function count limit. |
||
local success, title = pcall(mw.title.new, page) |
local success, title = pcall(mw.title.new, page, ...) |
||
if success then |
if success then |
||
return title |
return title |
||
Line 203: | Line 203: | ||
self.textstyle = args.textstyle |
self.textstyle = args.textstyle |
||
-- Find if we are on the template page or not. This functionality is only used if useCollapsibleTextFields is set, |
|||
⚫ | |||
-- or if both cfg.templateCategory and cfg.templateCategoryRequireName are set. |
|||
⚫ | |||
self.useCollapsibleTextFields = cfg.useCollapsibleTextFields |
|||
if self.useCollapsibleTextFields or cfg.templateCategory and cfg.templateCategoryRequireName then |
|||
self.name = args.name |
self.name = args.name |
||
if self.name then |
|||
local templateName = mw.ustring.match(self.name, '^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$') or self.name |
|||
self.isTemplatePage = nameTitle and self.title.prefixedText == ('Template:' .. nameTitle.text) and true or false |
|||
templateName = 'Template:' .. templateName |
|||
self.templateTitle = getTitleObject(templateName) |
|||
⚫ | |||
self.isTemplatePage = self.templateTitle and mw.title.equals(self.title, self.templateTitle) or false |
|||
end |
|||
⚫ | |||
⚫ | |||
-- Get the self.issue value. |
-- Get the self.issue value. |
||
if self.isSmall and args.smalltext then |
if self.isSmall and args.smalltext then |
||
Line 233: | Line 241: | ||
-- Get the self.talk value. |
-- Get the self.talk value. |
||
local talk = args.talk |
local talk = args.talk |
||
if talk == '' -- Show talk links on the template page or template subpages if the talk parameter is blank. |
|||
if talk == '' and self.isTemplatePage then |
|||
and self.templateTitle |
|||
and (mw.title.equals(self.templateTitle, self.title) or self.title:isSubpageOf(self.templateTitle)) |
|||
then |
|||
talk = '#' |
talk = '#' |
||
elseif talk == '' then |
|||
⚫ | |||
end |
end |
||
if talk then |
if talk then |
||
-- |
-- If the talk value is a talk page, make a link to that page. Else assume that it's a section heading, |
||
-- and make a link to the talk page of the current page with that section heading. |
|||
local talkTitle = getTitleObject(talk) |
local talkTitle = getTitleObject(talk) |
||
local talkArgIsTalkPage = true |
|||
if not talkTitle or not talkTitle.isTalkPage then |
if not talkTitle or not talkTitle.isTalkPage then |
||
talkArgIsTalkPage = false |
|||
-- If we couldn't process the talk page link, get the talk page of the current page. |
|||
talkTitle = getTitleObject(self.title.text, mw.site.namespaces[self.title.namespace].talk.id) |
|||
local success |
|||
success, talkTitle = pcall(self.title.talkPageTitle, self.title) |
|||
if not success then |
|||
⚫ | |||
⚫ | |||
end |
end |
||
if talkTitle and talkTitle.exists then |
if talkTitle and talkTitle.exists then |
||
local talkText = 'Relevant discussion may be found on' |
local talkText = 'Relevant discussion may be found on' |
||
if |
if talkArgIsTalkPage then |
||
talkText = format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText) |
talkText = format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText) |
||
else |
else |
||
Line 352: | Line 363: | ||
if cfg.templateCategory then |
if cfg.templateCategory then |
||
if cfg.templateCategoryRequireName then |
if cfg.templateCategoryRequireName then |
||
self.isTemplatePage = type(self.name) == 'string' and self.title.prefixedText == ('Template:' .. self.name) |
|||
if self.isTemplatePage then |
if self.isTemplatePage then |
||
self:addCat('template', cfg.templateCategory) |
self:addCat('template', cfg.templateCategory) |