Modul:Message box: Unterschied zwischen den Versionen
unsicher, was das eigentlich macht ....
(fix bug for data being shared between multiple message boxes called from the same module; allow boxes to be hidden; use Module:Arguments to fetch the arguments) |
(unsicher, was das eigentlich macht ....) |
||
| Zeile 2: | Zeile 2: | ||
-- Require necessary modules. | -- Require necessary modules. | ||
local htmlBuilder = require('Modul:HtmlBuilder') | |||
local htmlBuilder = require(' | local categoryHandler = require('Modul:Category handler').main | ||
local categoryHandler = require(' | local yesno = require('Modul:Yesno') | ||
local yesno = require(' | |||
-- 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 19: | Zeile 18: | ||
local trim = mw.text.trim | local trim = mw.text.trim | ||
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 61: | Zeile 58: | ||
table.sort(nums) | table.sort(nums) | ||
return nums | return nums | ||
end | end | ||
| Zeile 211: | Zeile 195: | ||
if self.isSmall then | if self.isSmall then | ||
self:addClass(cfg.smallClass or 'mbox-small') | self:addClass(cfg.smallClass or 'mbox-small') | ||
end | end | ||
self:addClass(self.typeClass) | self:addClass(self.typeClass) | ||
| Zeile 222: | 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 260: | 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 368: | Zeile 338: | ||
catTitle = getTitleObject('Category:' .. catTitle) | catTitle = getTitleObject('Category:' .. catTitle) | ||
if not catTitle or not catTitle.exists then | if not catTitle or not catTitle.exists then | ||
self:addCat('main', ' | self:addCat('main', 'Artikel mit ungültigen Datumsangaben in Vorlagen ') | ||
end | end | ||
elseif mainCat and (not date or date == '') then | elseif mainCat and (not date or date == '') then | ||
| Zeile 382: | 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 408: | Zeile 379: | ||
templateSort = tostring(count) | templateSort = tostring(count) | ||
end | end | ||
if self.categoryNums and #self.categoryNums > 0 then | -- if self.categoryNums and #self.categoryNums > 0 then | ||
-- templateCat = templateErrorCategory | |||
-- templateSort = 'C' | |||
end | -- end | ||
end | end | ||
self:addCat('template', templateCat, templateSort) | self:addCat('template', templateCat, templateSort) | ||
| Zeile 419: | Zeile 390: | ||
if self.invalidTypeError then | if self.invalidTypeError then | ||
local allSort = (self.nsid == 0 and 'Main:' or '') .. self.title.prefixedText | local allSort = (self.nsid == 0 and 'Main:' or '') .. self.title.prefixedText | ||
self:addCat('all', ' | self:addCat('all', 'Infoboxen mit falsch verwendeten Parametern ', allSort) | ||
end | end | ||
if self.isSubstituted then | if self.isSubstituted then | ||
self:addCat('all', ' | self:addCat('all', 'Vorlagen, die ersetzt statt eingebunden wurden') | ||
end | end | ||
| Zeile 445: | Zeile 416: | ||
.addClass('error') | .addClass('error') | ||
.wikitext(format( | .wikitext(format( | ||
' | 'Vorlage <code>%s[[Vorlage:%s|%s]]%s</code> wurde fälschlicherweise substituiert.', | ||
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | ||
)) | )) | ||
| Zeile 515: | 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('<br /><strong>Hinweis:</strong> Bei der Vielzahl von Vorlagen wird nicht jede Diskussionsseite beobachtet. Melde Änderungswünsche bitte in der [[Wikivoyage:Vorlagen/Werkstatt|Vorlagenwerkstatt]], Fragen auf der [[Wikivoyage Diskussion:Vorlagen/Werkstatt|Werkstatt-Diskussionsseite]] oder auch in der [[Wikivoyage:Lounge|Lounge]] an.', self.type or '')) | |||
end | end | ||
| Zeile 553: | Zeile 530: | ||
local function main(boxType, args) | local function main(boxType, args) | ||
box:setTitle(args) | |||
local cfg = box:getConfig(boxType) | |||
local cfg = | args = box:removeBlankArgs(cfg, args) | ||
args = | box:setBoxParameters(cfg, args) | ||
return box:export() | |||
return | |||
end | end | ||
local function makeWrapper(boxType) | local function makeWrapper(boxType) | ||
return function (frame) | return function (frame) | ||
local | -- If called via #invoke, use the args passed into the invoking | ||
-- template, or the args passed to #invoke if any exist. Otherwise | |||
-- assume args are being passed directly in from the debug console | |||
-- or from another Lua module. | |||
local origArgs | |||
if frame == mw.getCurrentFrame() then | |||
origArgs = frame:getParent().args | |||
for k, v in pairs(frame.args) do | |||
origArgs = frame.args | |||
break | |||
end | |||
else | |||
origArgs = frame | |||
end | |||
-- Trim whitespace. | |||
local args = {} | |||
for k, v in pairs(origArgs) do | |||
if type(v) == 'string' then | |||
v = trim(v) | |||
end | |||
args[k] = v | |||
end | |||
return main(boxType, args) | return main(boxType, args) | ||
end | end | ||