Modul:Message box: Unterschied zwischen den Versionen
Test
(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)) |
(Test) |
||
| Zeile 2: | Zeile 2: | ||
-- Require necessary modules. | -- Require necessary modules. | ||
local htmlBuilder = require(' | local htmlBuilder = require('Modul:HtmlBuilder') | ||
local categoryHandler = require(' | local categoryHandler = require('Modul:Category handler').main | ||
local yesno = require(' | local yesno = require('Modul:Yesno') | ||
-- Load the configuration page. | -- Load the configuration page. | ||
local cfgTables = mw.loadData(' | local cfgTables = mw.loadData('Modul:Message box/configuration') | ||
-- Get a language object for formatDate and ucfirst. | -- Get a language object for formatDate and ucfirst. | ||
| Zeile 20: | Zeile 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 | ||
| Zeile 203: | Zeile 203: | ||
self.textstyle = args.textstyle | self.textstyle = args.textstyle | ||
-- | -- Process data for collapsible text fields. At the moment these are only used in {{ambox}}. | ||
self.useCollapsibleTextFields = cfg.useCollapsibleTextFields | |||
self.useCollapsibleTextFields = cfg.useCollapsibleTextFields | if self.useCollapsibleTextFields then | ||
if self.useCollapsibleTextFields | |||
self.name = args.name | self.name = args.name | ||
local nameTitle = getTitleObject(self.name) | |||
self.isTemplatePage = nameTitle and self.title.prefixedText == ('Template:' .. nameTitle.text) and true or false | |||
self.isTemplatePage = self | |||
-- Get the self.issue value. | -- Get the self.issue value. | ||
if self.isSmall and args.smalltext then | if self.isSmall and args.smalltext then | ||
| Zeile 241: | Zeile 233: | ||
-- Get the self.talk value. | -- Get the self.talk value. | ||
local talk = args.talk | local talk = args.talk | ||
if talk == '' | if talk == '' and self.isTemplatePage then | ||
talk = '#' | talk = '#' | ||
end | end | ||
if talk then | if talk then | ||
-- | -- See if the talk link exists and is for a talk or a content namespace. | ||
local talkTitle = getTitleObject(talk) | local talkTitle = getTitleObject(talk) | ||
if not talkTitle or not talkTitle.isTalkPage then | if not talkTitle or not talkTitle.isTalkPage then | ||
-- If we couldn't process the talk page link, get the talk page of the current page. | |||
talkTitle = | local success | ||
success, talkTitle = pcall(self.title.talkPageTitle, self.title) | |||
if not success then | |||
talkTitle = nil | |||
end | |||
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 talkTitle.isTalkPage then | ||
talkText = format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText) | talkText = format('%s [[%s|%s]].', talkText, talk, talkTitle.prefixedText) | ||
else | else | ||
| Zeile 363: | Zeile 352: | ||
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) | ||
| Zeile 496: | Zeile 486: | ||
.cssText(self.textstyle) | .cssText(self.textstyle) | ||
.wikitext(self.text) | .wikitext(self.text) | ||
end | |||
-- Add a message, if used on ns11 | |||
if self.nsid == 11 then | |||
textCell | |||
.wikitext(format('Bei der Vielzahl von Vorlagen wird nicht jede Diskussionsseite beobachtet. Melde deine Fragen bitte auf der Diskussionsseite der Vorlagenwerkstatt oder in der Lounge an.', self.type or '')) | |||
end | end | ||