---- This module is meant to allow the goodies listed in
---- http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Title_objects
---- to be accessed by people who don't want to program a Lua module.
---- Usage is: {{#invoke:Page|(function)|parameters}}
---- (function) is one of the function names from the table above:
---- id, interwiki, namespace, fragment, nsText, subjectNsText, text, prefixedText, fullText ...
---- parameters are:
---- page = (name of page to load; leave blank to call mw.title.getCurrentTitle()
---- this is "text" passed to mw.title.new or "title" passed to mw.title.makeTitle
---- makeTitle = nonblank to call mw.title.makeTitle otherwise mw.title.new is called
---- namespace = (parameter passed to new/makeTitle)
---- fragment = (parameter passed to makeTitle)
---- interwiki = (parameter passed to makeTitle)
---- p1 = first parameter passed to functions within the title object
---- p2 = second parameter " " " "
---- p3 etc. (for inNamespaces)
function main(frame, field)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {};
local makeTitle=args.makeTitle or pargs.makeTitle or "";
---- Sorry, getContents doesn't work for many applications because all templates are destroyed. It does work on plain text though.
local namespace=args.namespace or pargs.namespace or "";
local fragment=args.fragment or pargs.fragment or "";
local p = {}
local interwiki=args.interwiki or pargs.interwiki or "";
local nowiki=args.nowiki or pargs.nowiki or false;
function p.main(frame)
local argspage=frameargs.page or args[1] or pargs.page or pargs[1];
local parentid=frame.getParent tonumber(frame args.id or pargs.id );
local pargspn = { "", "", "", "", "", "", "", "", "" };
if parent then pargs=parent.args end
local makeTitle=args.makeTitle or pargs.makeTitle or ""
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 p1 = args.p1 or pargs.p1 or ""
local p2 = args.p2 or pargs.p2 or ""
local p3 = args.p3 or pargs.p3 or ""
local p4 = args.p4 or pargs.p4 or ""
local p5 = args.p5 or pargs.p5 or ""
local p6 = args.p6 or pargs.p6 or ""
local p7 = args.p7 or pargs.p7 or ""
local p8 = args.p8 or pargs.p8 or ""
local p9 = args.p9 or pargs.p9 or ""
local nowiki = args.nowiki or pargs.nowiki or false
local page=args.page or pargs.page or args[1] or pargs[1]
if page=="" then page=nil end
local title -- holds the result of the mw.title.xxx call
if not(page) then
for i = 1,9 do pn[i] = args['p'..i] or pargs['p'..i] or ""; end
title=mw.title.getCurrentTitle()
if not id ifand not mw.ustring.match(title) thenpage, return'%S' "error:) failedthen topage getCurrentTitle()"= nil; end
else if makeTitle then
if id then
title=mw.title.makeTitle(namespace,page,fragment,interwiki)
title = mw.title.new(id);
if not (title) then return "error: failed to makeTitle(" .. namespace .. "," .. page .. "," .. fragment .. "," .. interwiki .. ")" end
if not title then return "error: failed to mw.title.new(" .. id .. ")"; end
else if id then
elseif not page then
title=mw.title.new(id)
if not (title) then return "error: failed to= mw.title.newgetCurrentTitle(" .. id .. ")" end;
if not title then return "error: failed to getCurrentTitle()"; end
else
elseif makeTitle then
title=mw.title.new(page,namespace)
if not (title) then return "error: failed to= mw.title.newmakeTitle(" ..namespace, page, .. "fragment," .. namespace .. "interwiki)" end;
if not title end -- if idthen
return mw.ustring.format("error: failed to makeTitle(%s,%s,%s,%s)", namespace, page, fragment, interwiki);
end -- if makeTitle
end -- if not(page)
local result=title[field]
if type(result)=="function" then
if nowiki then
return "<pre><nowiki>" .. tostring(result(title,p1,p2,p3,p4,p5,p6,p7,p8,p9)).. [[</nowiki></pre>]] -- I *think* these are all page:x() calls
else return result(title,p1,p2,p3,p4,p5,p6,p7,p8,p9)
end
else
else return tostring(result) -- note that nil values will be returned as "nil", not ""
title=mw.title.new(page, namespace);
if not title then return "error: failed to mw.title.new(" .. page .. "," .. namespace .. ")"; end
end
local result = title[field];
if type(result) == "function" then
result = result( title, unpack(pn) );
if nowiki and result ~= nil then
return mw.text.nowiki( tostring( result ) );
elseif result == nil or result == false then
return "";
else
return tostring(result);
end
else
return tostring(result or "");
end
end
local p = {};
-- main function p.id(frame)does all the work
function p.id(frame) return main(frame, "id"); end
field="id"
function p.interwiki(frame) return main(frame, "interwiki"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.namespace(frame) return main(frame, "namespace"); end
end
function p.fragment(frame) return main(frame, "fragment"); end
function p.interwikinsText(frame) return main(frame, "nsText") end
function p.subjectNsText(frame) return main(frame, "subjectNsText"); end
field="interwiki"
function p.text(frame) return main(frame, "text"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.prefixedText(frame) return main(frame, "prefixedText"); end
end
function p.fullText(frame) return main(frame, "fullText"); end
function p.namespacerootText(frame) return main(frame, "rootText"); end
function p.baseText(frame) return main(frame, "baseText"); end
field="namespace"
function p.subpageText(frame) return main(frame, "subpageText"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.canTalk(frame) return main(frame, "canTalk"); end
end
function p.exists(frame) return main(frame, "exists"); end
function p.fragmentfileExists(frame) return main(frame, "fileExists"); end
function p.isContentPage(frame) return main(frame, "isContentPage"); end
field="fragment"
function p.isExternal(frame) return main(frame, "isExternal"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.isLocal(frame) return main(frame, "isLocal"); end
end
function p.isRedirect(frame) return main(frame, "isRedirect"); end
function p.nsTextisSpecialPage(frame) return main(frame, "isSpecialPage"); end
function p.isSubpage(frame) return main(frame, "isSubpage"); end
field="nsText"
function p.isTalkPage(frame) return main(frame, "isTalkPage"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.isSubpageOf(frame) return main(frame, "isSubpageOf"); end
end
function p.inNamespace(frame) return main(frame, "inNamespace"); end
function p.subjectNsTextinNamespaces(frame) return main(frame, "inNamespaces"); end
function p.hasSubjectNamespace(frame) return main(frame, "hasSubjectNamespace"); end
field="subjectNsText"
function p.contentModel(frame) return main(frame, "contentModel"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.basePageTitle(frame) return main(frame, "basePageTitle"); end
end
function p.rootPageTitle(frame) return main(frame, "rootPageTitle"); end
function p.texttalkPageTitle(frame) return main(frame, "talkPageTitle"); end
function p.subjectPageTitle(frame) return main(frame, "subjectPageTitle"); end
field="text"
function p.subPageTitle(frame) return main(frame, "subPageTitle"); end
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
function p.partialUrl(frame) return main(frame, "partialUrl"); end
end
function p.fullUrl(frame) return main(frame, "fullUrl"); end
function p.prefixedTextlocalUrl(frame) return main(frame, "localUrl"); end
function p.canonicalUrl(frame) return main(frame, "canonicalUrl"); end
field="prefixedText"
function p.getContent(frame) return p.main(frame, "getContent"); end
end
function p.fullText(frame)
field="fullText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.rootText(frame)
field="rootText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.baseText(frame)
field="baseText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subpageText(frame)
field="subpageText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.canTalk(frame)
field="canTalk"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.exists(frame)
field="exists"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.fileExists(frame)
field="fileExists"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isContentPage(frame)
field="isContentPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isExternal(frame)
field="isExternal"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isLocal(frame)
field="isLocal"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isRedirect(frame)
field="isRedirect"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSpecialPage(frame)
field="isSpecialPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSubpage(frame)
field="isSubpage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isTalkPage(frame)
field="isTalkPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSubpageOf(frame)
field="isSubpageOf"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.inNamespace(frame)
field="inNamespace"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.inNamespaces(frame)
field="inNamespaces"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.hasSubjectNamespace(frame)
field="hasSubjectNamespace"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.contentModel(frame)
field="contentModel"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.basePageTitle(frame)
field="basePageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.rootPageTitle(frame)
field="rootPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.talkPageTitle(frame)
field="talkPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subjectPageTitle(frame)
field="subjectPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subPageTitle(frame)
field="subPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.partialUrl(frame)
field="partialUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.fullUrl(frame)
field="fullUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.localUrl(frame)
field="localUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.canonicalUrl(frame)
field="canonicalUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.getContent(frame)
field="getContent"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
return p
|