Module:Page: Difference between revisions

Content deleted Content added
Split a confusing multiple declaration with assignment
Get rid of repeated code, use Lua errors without ___location information for error handling
Line 16:
---- p2 = second parameter " " " "
---- p3 etc. (for inNamespaces)
 
local function callAssert(func, funcName, ...)
local result = { func(...) }
if not titleresult[1] then
error(mw.ustring.format('%s(%s) failed', funcName, join(', ', ...)), 0)
end
return unpack(result)
end
 
function main(frame, field)
Line 32 ⟶ 40:
if id then
title = callAssert(mw.title.new(, 'mw.title.new', id);
if not title then
return '<span class="error"> error: failed to mw.title.new(' .. id .. ')</span>'
end
elseif not page then
title = callAssert(mw.title.getCurrentTitle(, 'getCurrentTitle');
if not title then return '<span class="error"> error: failed to getCurrentTitle()</span>'; end
elseif makeTitle then
title = callAssert(mw.title.makeTitle(, 'makeTitle', namespace, page, fragment, interwiki);
if not title then
return mw.ustring.format('<span class="error"> error: failed to makeTitle(%s,%s,%s,%s)</span>',
namespace, page, fragment, interwiki);
end
else
title = callAssert(mw.title.new(, 'mw.title.new', page, namespace);
if not title then
return '<span class="error"> error: failed to mw.title.new(' .. page .. ',' .. namespace .. ')</span>'
end
end
Line 57 ⟶ 54:
success, result = pcall( result, title, unpack(pn) );
if not success then
return mw.ustring.format("error: failed to title:%s(%s)", field, table.concat(pn, 'result,' )0);
end
end
Line 67 ⟶ 64:
 
-- main function does all the work
local meta = {};
function p.id(frame) return main(frame, "id"); end
function pmeta.interwiki__index(frame) return main(frametable, "interwiki"key); end
function p.namespace(frame) return mainfunction(frame, "namespace"); end
function p.fragment(frame) return main(frame, "fragment"key); end
end
function p.nsText(frame) return main(frame, "nsText") end
end
function p.subjectNsText(frame) return main(frame, "subjectNsText"); end
setmetatable(p, meta)
function p.text(frame) return main(frame, "text"); end
 
function p.prefixedText(frame) return main(frame, "prefixedText"); end
function p.fullText(frame) return main(frame, "fullText"); end
function p.rootText(frame) return main(frame, "rootText"); end
function p.baseText(frame) return main(frame, "baseText"); end
function p.subpageText(frame) return main(frame, "subpageText"); end
function p.canTalk(frame) return main(frame, "canTalk"); end
function p.exists(frame) return main(frame, "exists"); end
function p.fileExists(frame) return main(frame, "fileExists"); end
function p.isContentPage(frame) return main(frame, "isContentPage"); end
function p.isExternal(frame) return main(frame, "isExternal"); end
function p.isLocal(frame) return main(frame, "isLocal"); end
function p.isRedirect(frame) return main(frame, "isRedirect"); end
function p.isSpecialPage(frame) return main(frame, "isSpecialPage"); end
function p.isSubpage(frame) return main(frame, "isSubpage"); end
function p.isTalkPage(frame) return main(frame, "isTalkPage"); end
function p.isSubpageOf(frame) return main(frame, "isSubpageOf"); end
function p.inNamespace(frame) return main(frame, "inNamespace"); end
function p.inNamespaces(frame) return main(frame, "inNamespaces"); end
function p.hasSubjectNamespace(frame) return main(frame, "hasSubjectNamespace"); end
function p.contentModel(frame) return main(frame, "contentModel"); end
function p.basePageTitle(frame) return main(frame, "basePageTitle"); end
function p.rootPageTitle(frame) return main(frame, "rootPageTitle"); end
function p.talkPageTitle(frame) return main(frame, "talkPageTitle"); end
function p.subjectPageTitle(frame) return main(frame, "subjectPageTitle"); end
function p.subPageTitle(frame) return main(frame, "subPageTitle"); end
function p.partialUrl(frame) return main(frame, "partialUrl"); end
function p.fullUrl(frame) return main(frame, "fullUrl"); end
function p.localUrl(frame) return main(frame, "localUrl"); end
function p.canonicalUrl(frame) return main(frame, "canonicalUrl"); end
function p.getContent(frame)
local args, pargs = frame.args, ( frame:getParent() or {} ).args or {};