https://www.droidwiki.org/w/index.php?title=Modul:Hatnote&feed=atom&action=historyModul:Hatnote - Versionsgeschichte2024-03-29T07:32:14ZVersionsgeschichte dieser Seite in Android WikiMediaWiki 1.41.0-wmf.5https://www.droidwiki.org/w/index.php?title=Modul:Hatnote&diff=15108&oldid=prevFlorian: 1 Version importiert2016-05-27T16:28:50Z<p>1 Version importiert</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="de">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Nächstältere Version</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Version vom 27. Mai 2016, 17:28 Uhr</td>
</tr>
<!-- diff cache key droidwikiwiki:diff::1.12:old-15107:rev-15108 -->
</table>Florianhttps://www.droidwiki.org/w/index.php?title=Modul:Hatnote&diff=15107&oldid=prevdewiki>Nihiltres: Updated from sandbox: tweaked _formatLink() to overwrite, rather than stack, manual piping with "display"-based piping2016-05-12T15:30:44Z<p>Updated from sandbox: tweaked _formatLink() to overwrite, rather than stack, manual piping with "display"-based piping</p>
<p><b>Neue Seite</b></p><div>--------------------------------------------------------------------------------<br />
-- Module:Hatnote --<br />
-- --<br />
-- This module produces hatnote links and links to related articles. It --<br />
-- implements the {{hatnote}} and {{format link}} meta-templates and includes --<br />
-- helper functions for other Lua hatnote modules. --<br />
--------------------------------------------------------------------------------<br />
<br />
local libraryUtil = require('libraryUtil')<br />
local checkType = libraryUtil.checkType<br />
local mArguments -- lazily initialise [[Module:Arguments]]<br />
local yesno -- lazily initialise [[Module:Yesno]]<br />
<br />
local p = {}<br />
<br />
--------------------------------------------------------------------------------<br />
-- Helper functions<br />
--------------------------------------------------------------------------------<br />
<br />
local function getArgs(frame)<br />
-- Fetches the arguments from the parent frame. Whitespace is trimmed and<br />
-- blanks are removed.<br />
mArguments = require('Module:Arguments')<br />
return mArguments.getArgs(frame, {parentOnly = true})<br />
end<br />
<br />
local function removeInitialColon(s)<br />
-- Removes the initial colon from a string, if present.<br />
return s:match('^:?(.*)')<br />
end<br />
<br />
function p.findNamespaceId(link, removeColon)<br />
-- Finds the namespace id (namespace number) of a link or a pagename. This<br />
-- function will not work if the link is enclosed in double brackets. Colons<br />
-- are trimmed from the start of the link by default. To skip colon<br />
-- trimming, set the removeColon parameter to false.<br />
checkType('findNamespaceId', 1, link, 'string')<br />
checkType('findNamespaceId', 2, removeColon, 'boolean', true)<br />
if removeColon ~= false then<br />
link = removeInitialColon(link)<br />
end<br />
local namespace = link:match('^(.-):')<br />
if namespace then<br />
local nsTable = mw.site.namespaces[namespace]<br />
if nsTable then<br />
return nsTable.id<br />
end<br />
end<br />
return 0<br />
end<br />
<br />
function p.formatPages(...)<br />
-- Formats a list of pages using formatLink and returns it as an array. Nil<br />
-- values are not allowed.<br />
local pages = {...}<br />
local ret = {}<br />
for i, page in ipairs(pages) do<br />
ret[i] = p._formatLink(page)<br />
end<br />
return ret<br />
end<br />
<br />
function p.formatPageTables(...)<br />
-- Takes a list of page/display tables and returns it as a list of<br />
-- formatted links. Nil values are not allowed.<br />
local pages = {...}<br />
local links = {}<br />
for i, t in ipairs(pages) do<br />
checkType('formatPageTables', i, t, 'table')<br />
local link = t[1]<br />
local display = t[2]<br />
links[i] = p._formatLink(link, display)<br />
end<br />
return links<br />
end<br />
<br />
function p.makeWikitextError(msg, helpLink, addTrackingCategory, title)<br />
-- Formats an error message to be returned to wikitext. If<br />
-- addTrackingCategory is not false after being returned from<br />
-- [[Module:Yesno]], and if we are not on a talk page, a tracking category<br />
-- is added.<br />
checkType('makeWikitextError', 1, msg, 'string')<br />
checkType('makeWikitextError', 2, helpLink, 'string', true)<br />
yesno = require('Module:Yesno')<br />
title = title or mw.title.getCurrentTitle()<br />
-- Make the help link text.<br />
local helpText<br />
if helpLink then<br />
helpText = ' ([[' .. helpLink .. '|help]])'<br />
else<br />
helpText = ''<br />
end<br />
-- Make the category text.<br />
local category<br />
if not title.isTalkPage and yesno(addTrackingCategory) ~= false then<br />
category = 'Hatnote templates with errors'<br />
category = string.format(<br />
'[[%s:%s]]',<br />
mw.site.namespaces[14].name,<br />
category<br />
)<br />
else<br />
category = ''<br />
end<br />
return string.format(<br />
'<strong class="error">Error: %s%s.</strong>%s',<br />
msg,<br />
helpText,<br />
category<br />
)<br />
end<br />
<br />
function p.disambiguate(page, disambiguator)<br />
-- Formats a page title with a disambiguation parenthetical,<br />
-- i.e. "Example" → "Example (disambiguation)".<br />
checkType('disambiguate', 1, page, 'string')<br />
checkType('disambiguate', 2, disambiguator, 'string', true)<br />
disambiguator = disambiguator or 'disambiguation'<br />
return string.format('%s (%s)', page, disambiguator)<br />
end<br />
<br />
--------------------------------------------------------------------------------<br />
-- Format link<br />
--<br />
-- Makes a wikilink from the given link and display values. Links are escaped<br />
-- with colons if necessary, and links to sections are detected and displayed<br />
-- with " § " as a separator rather than the standard MediaWiki "#". Used in<br />
-- the {{format hatnote link}} template.<br />
--------------------------------------------------------------------------------<br />
<br />
function p.formatLink(frame)<br />
local args = getArgs(frame)<br />
local link = args[1]<br />
local display = args[2]<br />
if not link then<br />
return p.makeWikitextError(<br />
'no link specified',<br />
'Template:Format hatnote link#Errors',<br />
args.category<br />
)<br />
end<br />
return p._formatLink(link, display)<br />
end<br />
<br />
function p._formatLink(link, display)<br />
checkType('_formatLink', 1, link, 'string')<br />
checkType('_formatLink', 2, display, 'string', true)<br />
<br />
-- Remove the initial colon for links where it was specified manually.<br />
link = removeInitialColon(link)<br />
<br />
-- Find whether a faux display value has been added with the {{!}} magic<br />
-- word.<br />
if not display then<br />
local prePipe, postPipe = link:match('^(.-)|(.*)$')<br />
link = prePipe or link<br />
display = postPipe<br />
end<br />
<br />
-- Find the display value.<br />
if not display then<br />
local page, section = link:match('^(.-)#(.*)$')<br />
if page then<br />
display = page .. ' § ' .. section<br />
end<br />
end<br />
<br />
-- Assemble the link.<br />
if display then<br />
return string.format(<br />
'[[:%s|%s]]',<br />
string.gsub(link, '|(.*)$', ''), --display overwrites manual piping<br />
display<br />
)<br />
else<br />
return string.format('[[:%s]]', link)<br />
end<br />
end<br />
<br />
--------------------------------------------------------------------------------<br />
-- Hatnote<br />
--<br />
-- Produces standard hatnote text. Implements the {{hatnote}} template.<br />
--------------------------------------------------------------------------------<br />
<br />
function p.hatnote(frame)<br />
local args = getArgs(frame)<br />
local s = args[1]<br />
local options = {}<br />
if not s then<br />
return p.makeWikitextError(<br />
'no text specified',<br />
'Template:Hatnote#Errors',<br />
args.category<br />
)<br />
end<br />
options.extraclasses = args.extraclasses<br />
options.selfref = args.selfref<br />
return p._hatnote(s, options)<br />
end<br />
<br />
function p._hatnote(s, options)<br />
checkType('_hatnote', 1, s, 'string')<br />
checkType('_hatnote', 2, options, 'table', true)<br />
options = options or {}<br />
local classes = {'hatnote'}<br />
local extraclasses = options.extraclasses<br />
local selfref = options.selfref<br />
if type(extraclasses) == 'string' then<br />
classes[#classes + 1] = extraclasses<br />
end<br />
if selfref then<br />
classes[#classes + 1] = 'selfref'<br />
end<br />
return string.format(<br />
'<div role="note" class="%s">%s</div>',<br />
table.concat(classes, ' '),<br />
s<br />
)<br />
end<br />
<br />
return p</div>dewiki>Nihiltres