This Lua module is used in system messages, and on
approximately 109,000 pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module is meant to allow the goodies listed in mw:Extension:Scribunto/Lua reference manual § Title objects to be accessed by people who do not want to write a Lua module.
Usage is: {{#invoke:Page|function|parameters}}
In the usage above, function is one of the following fields or functions for title objects:
local callAssert = require('Module:CallAssert')
local function main(frame, field)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
local makeTitle=args.makeTitle or pargs.makeTitle
local namespace=args.namespace or pargs.namespace or ""
local fragment=args.fragment or pargs.fragment or ""
local interwiki=args.interwiki or pargs.interwiki or ""
local page=args.page or args1 or pargs.page or pargs1 or ""
local id= tonumber( args.id or pargs.id )
local pn = {}
local title -- holds the result of the mw.title.xxx call
for i = 1,9 do pni = args'p'..i or pargs'p'..i end
if not id and not mw.ustring.match( page, '%S' ) then page = nil end
if id then
title = callAssert(mw.title.new, 'mw.title.new', id)
elseif not page then
title = callAssert(mw.title.getCurrentTitle, 'getCurrentTitle')
elseif makeTitle then
title = callAssert(mw.title.makeTitle, 'makeTitle', namespace, page, fragment, interwiki)
else
title = callAssert(mw.title.new, 'mw.title.new', page, namespace)
end
local result = titlefield
if type(result) == "function" then
result = result(title, unpack(pn))
end
return tostring(result or "")
end
-- handle all errors in main
main = require('Module:Protect')(main)
local p = {}
-- main function does all the work
local meta = {}
function meta.__index(self, key)
return function(frame)
return main(frame, key)
end
end
setmetatable(p, meta)
function p.getContent(frame)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {}
local fmt = args.as or pargs.as or "pre"
local text = main(frame, "getContent")
fmt = mw.text.split( fmt, ", ?" )
for _, how in ipairs( fmt ) do
if how == "pre" then
text = table.concat{ "<pre>", text, "</pre>" }
elseif how == "expand" then
text = frame:preprocess(text)
elseif how == "nowiki" then
text = mw.text.nowiki(text)
end
end
return text
end
return p