Module:Pagetype and Module:Pagetype/sandbox: Difference between pages
(Difference between pages)
imported>MSGJ m fix for files and interface messages which do exist but are not stored locally |
imported>Awesome Aasim No edit summary |
||
| Line 7: | Line 7: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Load config. | -- Load config. | ||
local cfg = mw.loadData('Module:Pagetype/config') | local cfg = mw.loadData('Module:Pagetype/config/sandbox') | ||
-- Load required modules. | -- Load required modules. | ||
| Line 58: | Line 58: | ||
end | end | ||
-- Look up a page type specific to the title's namespace | -- Look up a page type specific to the title's namespace and content model | ||
local function getExplicitPageType(title) | local function getExplicitPageType(title) | ||
if title.isTalkPage then | if title.isTalkPage then | ||
return cfg.talkDefault | return cfg.talkDefault | ||
else | else | ||
return cfg.pagetypes[title.namespace] | return mw.getCurrentFrame():preprocess(mw.ustring.gsub(cfg.pagetypes[title.namespace] or cfg.pagetypes['#default'], '$([1-9][0-9]*)', function(match) | ||
local nmatch = tonumber(match) | |||
-- prefill $1 with name of content model and $2 with content model key | |||
if (nmatch == 1) then | |||
return cfg.contentModels[title.contentModel] or cfg.contentModels['#default'] | |||
elseif (nmatch == 2) then | |||
return title.contentModel | |||
else | |||
return match | |||
end | |||
end)) | |||
end | end | ||
end | end | ||
| Line 109: | Line 119: | ||
local function parseContent(title, args, optionsList) | local function parseContent(title, args, optionsList) | ||
if title.namespace==828 and title. | if title.namespace==828 and title.contentModel == 'Scribunto' -- don't detect modules | ||
or not title.exists -- can't check unless page exists | or not title.exists -- can't check unless page exists | ||
then | then | ||
| Line 243: | Line 253: | ||
if args.page then | if args.page then | ||
title = mw.title.new(args.page) | title = mw.title.new(args.page) | ||
if not title then | |||
error(string.format("Invalid page title '%s'", args.page)) | |||
end | |||
else | else | ||
title = mw.title.getCurrentTitle() | title = mw.title.getCurrentTitle() | ||