Module:Namespace other: Difference between revisions
fix error
m (1 revision imported) |
enws>CalendulaAsteraceae (fix error) |
||
| Line 4: | Line 4: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local yesno = require('Module:Yesno') | |||
function p._namespace_other(args) | function p._namespace_other(args) | ||
local namespace = string.lower(args.demospace or mw.title.getCurrentTitle().nsText) | local namespace = string.lower(args.demospace or mw.title.getCurrentTitle().nsText) | ||
namespace = string.gsub(namespace, ' ', '_') | |||
namespace = ' | local target = string.lower(args.target or 'main') | ||
if yesno(args['include-talk']) then | |||
namespace = string.gsub(namespace, '[%s_]*talk', '') | |||
end | end | ||
local special_targets = { | local special_targets = { | ||
[' | ['talk'] = function (ns) | ||
return mw.title.new(mw.title.getCurrentTitle().rootText, ns).isTalkPage | |||
end, | |||
['main'] = function (ns) | |||
return ns == '' or ns == 'main' | |||
end | |||
} | } | ||
if namespace == target or (special_targets[target] and special_targets[target] | if namespace == target or (special_targets[target] and special_targets[target](namespace)) then | ||
return args[1] | return args[1] | ||
else | else | ||
| Line 25: | Line 33: | ||
function p.namespace_other(frame) | function p.namespace_other(frame) | ||
return p._namespace_other(getArgs(frame)) | return p._namespace_other(getArgs(frame)) | ||
end | |||
local function _page_index_other(args) | |||
local page_entry = args['page index'] or args['page'] or args[1] | |||
local index_entry = args['page index'] or args['index'] or args[2] | |||
local other_entry = args['other'] or args[3] | |||
local namespace = string.lower(args.demospace or mw.title.getCurrentTitle().nsText) | |||
namespace = string.gsub(namespace, ' ', '_') | |||
namespace = string.gsub(namespace, '[%s_]*talk', '') | |||
return (namespace == 'page' and page_entry) or (namespace == 'index' and index_entry) or other_entry | |||
end | |||
function p.page_index_other(frame) | |||
return _page_index_other(getArgs(frame)) | |||
end | end | ||
return p | return p | ||