Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
K (Protected Module:Hatnote: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))) |
K (59 Versionen von wpen:Module:Hatnote importiert) |
||
| (31 dazwischenliegende Versionen von 12 Benutzern werden nicht angezeigt) | |||
| Zeile 3: | Zeile 3: | ||
-- -- | -- -- | ||
-- This module produces hatnote links and links to related articles. It -- | -- This module produces hatnote links and links to related articles. It -- | ||
-- implements the {{hatnote}} and {{format | -- implements the {{hatnote}} and {{format link}} meta-templates and includes -- | ||
-- | -- helper functions for other Lua hatnote modules. -- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Zeile 34: | Zeile 34: | ||
-- function will not work if the link is enclosed in double brackets. Colons | -- function will not work if the link is enclosed in double brackets. Colons | ||
-- are trimmed from the start of the link by default. To skip colon | -- are trimmed from the start of the link by default. To skip colon | ||
-- trimming, set the removeColon parameter to | -- trimming, set the removeColon parameter to false. | ||
checkType('findNamespaceId', 1, link, 'string') | checkType('findNamespaceId', 1, link, 'string') | ||
checkType('findNamespaceId', 2, removeColon, 'boolean', true) | checkType('findNamespaceId', 2, removeColon, 'boolean', true) | ||
| Zeile 75: | Zeile 75: | ||
end | end | ||
function p.makeWikitextError(msg, helpLink, addTrackingCategory) | function p.makeWikitextError(msg, helpLink, addTrackingCategory, title) | ||
-- Formats an error message to be returned to wikitext. If | -- Formats an error message to be returned to wikitext. If | ||
-- addTrackingCategory is not false after being returned from | -- addTrackingCategory is not false after being returned from | ||
| Zeile 83: | Zeile 83: | ||
checkType('makeWikitextError', 2, helpLink, 'string', true) | checkType('makeWikitextError', 2, helpLink, 'string', true) | ||
yesno = require('Module:Yesno') | yesno = require('Module:Yesno') | ||
title = title or mw.title.getCurrentTitle() | |||
-- Make the help link text. | -- Make the help link text. | ||
local helpText | local helpText | ||
| Zeile 109: | Zeile 109: | ||
category | category | ||
) | ) | ||
end | |||
function p.disambiguate(page, disambiguator) | |||
-- Formats a page title with a disambiguation parenthetical, | |||
-- i.e. "Example" → "Example (disambiguation)". | |||
checkType('disambiguate', 1, page, 'string') | |||
checkType('disambiguate', 2, disambiguator, 'string', true) | |||
disambiguator = disambiguator or 'disambiguation' | |||
return string.format('%s (%s)', page, disambiguator) | |||
end | end | ||
| Zeile 135: | Zeile 144: | ||
function p._formatLink(link, display) | function p._formatLink(link, display) | ||
checkType('_formatLink', 1, link, 'string') | checkType('_formatLink', 1, link, 'string') | ||
checkType('_formatLink', 2, display, 'string', true) | checkType('_formatLink', 2, display, 'string', true) | ||
-- Remove the initial colon for links where it was specified manually. | |||
link = removeInitialColon(link) | link = removeInitialColon(link) | ||
-- Find whether a faux display value has been added with the {{!}} magic | |||
if | -- word. | ||
if not display then | |||
local prePipe, postPipe = link:match('^(.-)|(.*)$') | |||
link = prePipe or link | |||
display = postPipe | |||
end | end | ||
| Zeile 153: | Zeile 162: | ||
local page, section = link:match('^(.-)#(.*)$') | local page, section = link:match('^(.-)#(.*)$') | ||
if page then | if page then | ||
display = page .. ' § ' .. section | display = page .. ' § ' .. section | ||
end | end | ||
end | end | ||
| Zeile 159: | Zeile 168: | ||
-- Assemble the link. | -- Assemble the link. | ||
if display then | if display then | ||
return string.format('[[ | return string.format( | ||
'[[:%s|%s]]', | |||
string.gsub(link, '|(.*)$', ''), --display overwrites manual piping | |||
display | |||
) | |||
else | else | ||
return string.format('[[ | return string.format('[[:%s]]', link) | ||
end | end | ||
end | end | ||
| Zeile 190: | Zeile 203: | ||
checkType('_hatnote', 1, s, 'string') | checkType('_hatnote', 1, s, 'string') | ||
checkType('_hatnote', 2, options, 'table', true) | checkType('_hatnote', 2, options, 'table', true) | ||
local classes = {'hatnote'} | options = options or {} | ||
local classes = {'hatnote', 'navigation-not-searchable'} | |||
local extraclasses = options.extraclasses | local extraclasses = options.extraclasses | ||
local selfref = options.selfref | local selfref = options.selfref | ||
| Zeile 200: | Zeile 214: | ||
end | end | ||
return string.format( | return string.format( | ||
'<div class="%s">%s</div>', | '<div role="note" class="%s">%s</div>', | ||
table.concat(classes, ' '), | table.concat(classes, ' '), | ||
s | s | ||