http://coastalplainplants.org/wiki/index.php?title=Module:Redirect_hatnote&feed=atom&action=historyModule:Redirect hatnote - Revision history2024-03-29T12:14:59ZRevision history for this page on the wikiMediaWiki 1.31.3http://coastalplainplants.org/wiki/index.php?title=Module:Redirect_hatnote&diff=191&oldid=prevIDigBioAdmin: 1 revision imported: Wikipedia Taxobox2015-03-02T22:33:03Z<p>1 revision imported: Wikipedia Taxobox</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">Revision as of 22:33, 2 March 2015</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>IDigBioAdminhttp://coastalplainplants.org/wiki/index.php?title=Module:Redirect_hatnote&diff=190&oldid=prevFayenatic london: update category, see Wikipedia:Categories for discussion/Log/2015 February 212015-03-02T11:20:27Z<p>update category, see <a href="http://en.wikipedia.org/wiki/Categories_for_discussion/Log/2015_February_21" class="extiw" title="wikipedia:Categories for discussion/Log/2015 February 21">Wikipedia:Categories for discussion/Log/2015 February 21</a></p>
<p><b>New page</b></p><div>--[[<br />
-- This module produces a "redirect" hatnote. It looks like this:<br />
-- '"X" redirects here. For other uses, see Y.'<br />
-- It implements the {{redirect}} template.<br />
--]]<br />
<br />
local mHatnote = require('Module:Hatnote')<br />
local libraryUtil = require('libraryUtil')<br />
local checkType = libraryUtil.checkType<br />
<br />
local p = {}<br />
<br />
local function getTitle(...)<br />
local success, titleObj = pcall(mw.title.new, ...)<br />
if success then<br />
return titleObj<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.redirect(frame)<br />
-- Get the args table and work out the maximum arg key.<br />
local origArgs = frame:getParent().args<br />
local args = {}<br />
local maxArg = 0<br />
for k, v in pairs(origArgs) do<br />
if type(k) == 'number' and k > maxArg then<br />
maxArg = k<br />
end<br />
v = v:match('^%s*(.-)%s*$') -- Trim whitespace<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
end<br />
<br />
-- Return an error if no redirect was specified.<br />
local redirect = args[1]<br />
if not redirect then<br />
return mHatnote.makeWikitextError(<br />
'no redirect specified',<br />
'Template:Redirect#Errors',<br />
args.category<br />
)<br />
end<br />
<br />
-- Create the data table.<br />
local data = {}<br />
local iArg = 0<br />
local iData = 1<br />
repeat<br />
iArg = iArg + 2<br />
local useTable = data[iData] or {}<br />
local pages = useTable.pages or {}<br />
local use = args[iArg]<br />
local page = args[iArg + 1]<br />
local nextUse = args[iArg + 2]<br />
pages[#pages + 1] = page<br />
useTable.pages = pages<br />
if use ~= 'and' then<br />
useTable.use = use<br />
end<br />
data[iData] = useTable<br />
if nextUse ~= 'and' then<br />
iData = iData + 1<br />
end<br />
until iArg >= maxArg - 1<br />
<br />
-- Create the options table.<br />
local options = {}<br />
options.selfref = args.selfref<br />
<br />
return p._redirect(redirect, data, options)<br />
end<br />
<br />
local function formatUseTable(useTable, isFirst, redirect)<br />
-- Formats one use table. Use tables are the tables inside the data array.<br />
-- Each one corresponds to one use. (A use might be the word "cats" in the<br />
-- phrase "For cats, see [[Felines]]".)<br />
-- Returns a string, or nil if no use was specified.<br />
-- The isFirst parameter is used to apply special formatting for the first<br />
-- table in the data array. If isFirst is specified, the redirect parameter<br />
useTable = useTable or {}<br />
local use<br />
if isFirst then<br />
use = useTable.use or 'other uses'<br />
elseif not useTable.use then<br />
return nil<br />
elseif tonumber(useTable.use) == 1 then<br />
use = 'other uses'<br />
else<br />
use = useTable.use<br />
end<br />
local pages = useTable.pages or {}<br />
if isFirst then<br />
redirect = redirect or error(<br />
'isFirst was set in formatUseTable, but no redirect was supplied',<br />
2<br />
)<br />
pages[1] = pages[1] or redirect .. ' (disambiguation)'<br />
else<br />
pages[1] = pages[1] or useTable.use .. ' (disambiguation)'<br />
end<br />
pages = mHatnote.formatPages(unpack(pages))<br />
pages = mw.text.listToText(pages)<br />
return string.format(<br />
'For %s, see %s.',<br />
use,<br />
pages<br />
)<br />
end<br />
<br />
function p._redirect(redirect, data, options, currentTitle, redirectTitle, targetTitle)<br />
-- Validate the input. Don't bother checking currentTitle, redirectTitle or<br />
-- targetTitle, as they are only used in testing.<br />
checkType('_redirect', 1, redirect, 'string')<br />
checkType('_redirect', 2, data, 'table', true)<br />
checkType('_redirect', 3, options, 'table', true)<br />
data = data or {}<br />
options = options or {}<br />
currentTitle = currentTitle or mw.title.getCurrentTitle()<br />
<br />
-- Generate the text.<br />
local text = {}<br />
text[#text + 1] = '"' .. redirect .. '" redirects here.'<br />
text[#text + 1] = formatUseTable(data[1] or {}, true, redirect)<br />
if data[1] and data[1].use and data[1].use ~= 'other uses' then<br />
for i = 2, #data do<br />
text[#text + 1] = formatUseTable(data[i] or {}, false)<br />
end<br />
end<br />
text = table.concat(text, ' ')<br />
<br />
-- Generate the tracking category.<br />
-- We don't need a tracking category if the template invocation has been<br />
-- copied directly from the docs, or if we aren't in mainspace.<br />
local category<br />
if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM' -- <br />
and currentTitle.namespace == 0<br />
then<br />
redirectTitle = redirectTitle or getTitle(redirect)<br />
if not redirectTitle or not redirectTitle.exists then<br />
category = 'Missing redirects'<br />
elseif not redirectTitle.isRedirect then<br />
category = 'Articles with redirect hatnotes needing review'<br />
else<br />
local mRedirect = require('Module:Redirect')<br />
local target = mRedirect.getTarget(redirectTitle)<br />
targetTitle = targetTitle or target and getTitle(target)<br />
if targetTitle and targetTitle ~= currentTitle then<br />
category = 'Articles with redirect hatnotes needing review'<br />
end<br />
end<br />
end<br />
category = category and string.format('[[Category:%s]]', category) or ''<br />
<br />
-- Generate the options to pass to [[Module:Hatnote]].<br />
local mhOptions = {}<br />
if currentTitle.namespace == 0<br />
and redirectTitle and redirectTitle.namespace ~= 0<br />
then<br />
-- We are on a mainspace page, and the hatnote starts with something<br />
-- like "Wikipedia:Foo redirects here", so automatically label it as a<br />
-- self-reference.<br />
mhOptions.selfref = true<br />
else<br />
mhOptions.selfref = options.selfref<br />
end<br />
<br />
return mHatnote._hatnote(text, mhOptions) .. category<br />
end<br />
<br />
return p</div>Fayenatic london