Difference between revisions of "Module:Main list"
test>Codename Lisa (Undid revision 703665856 by Codename Lisa (talk)) |
test>Codename Lisa (Implemented second parameter. Last time it didn't work because I forgot line 27 ("local text"), so the variable "text" became local to the "if" block.) |
||
| Line 12: | Line 12: | ||
mArguments = require('Module:Arguments') | mArguments = require('Module:Arguments') | ||
local args = mArguments.getArgs(frame, {parentOnly = true}) | local args = mArguments.getArgs(frame, {parentOnly = true}) | ||
| − | local | + | local page1 = args[1] |
| − | if not | + | local page2 = args[2] |
| + | if not page1 then | ||
return mHatnote.makeWikitextError( | return mHatnote.makeWikitextError( | ||
'no page name specified', | 'no page name specified', | ||
| Line 20: | Line 21: | ||
) | ) | ||
end | end | ||
| − | return p._mainList( | + | return p._mainList(page1, page2) |
end | end | ||
| − | function p._mainList( | + | function p._mainList(page1, page2) |
| − | + | local text | |
| − | + | page1 = mHatnote._formatLink(page1) | |
| + | if page2 then | ||
| + | page2 = mHatnote._formatLink(page2) | ||
| + | text = string.format('For a more comprehensive list, see %s and %s.', page1, page2) | ||
| + | else | ||
| + | text = string.format('For a more comprehensive list, see %s.', page1) | ||
| + | end | ||
return mHatnote._hatnote(text) | return mHatnote._hatnote(text) | ||
end | end | ||
return p | return p | ||
Revision as of 22:23, 6 February 2016
This module produces a "For a more comprehensive list, see [...]" link. It implements the {{main list}} template.
Contents
Use from wikitext
This module cannot be used directly from #invoke. Instead, it can only be used through the {{main list}} template. Please see the template page for documentation.
Use from other Lua modules
Load the module:
local mMainList = require('Module:Main list')
You can then use the _mainList function like this:
mMainList._mainList (page1, page2)
The page1 variable is the page to be linked to, and is required. The page name can include a section link if desired. If the page includes a section link, it is automatically formatted as page § section, rather than the MediaWiki default of page#section.
The page2 variable is optional; it is a second page link.
Example 1
mMainList._mainList ('Wikipedia:Hatnote#Hatnote templates')
Produces:
<div class="hatnote">For a more comprehensive list, see [[Wikipedia:Hatnote#Hatnote templates|Wikipedia:Hatnote § Hatnote templates]].</div>
Displays as:
Example 2
mMainList._mainList ('Wikipedia:Hatnote#Hatnote templates','Wikipedia:Template messages/Cleanup#Cleanup')
Produces:
<div class="hatnote">For a more comprehensive list, see [[Wikipedia:Hatnote#Hatnote templates|Wikipedia:Hatnote § Hatnote templates]] and [[Wikipedia:Template messages/Cleanup#Cleanup|Wikipedia:Template messages/Cleanup § Cleanup]].</div>
Displays as:
Technical details
This module uses Module:Hatnote to format the hatnote text and Module:Arguments to fetch the arguments from wikitext.
--[[
-- This module produces a "For more details on this topic" link. It implements
-- the {{Main list}} template.
--]]
local mHatnote = require('Module:Hatnote')
local mArguments -- lazily initialise
local p = {}
function p.mainList(frame)
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
local page1 = args[1]
local page2 = args[2]
if not page1 then
return mHatnote.makeWikitextError(
'no page name specified',
'Template:Main list#Errors',
args.category
)
end
return p._mainList(page1, page2)
end
function p._mainList(page1, page2)
local text
page1 = mHatnote._formatLink(page1)
if page2 then
page2 = mHatnote._formatLink(page2)
text = string.format('For a more comprehensive list, see %s and %s.', page1, page2)
else
text = string.format('For a more comprehensive list, see %s.', page1)
end
return mHatnote._hatnote(text)
end
return p