Module:Namespace other: Difference between revisions

m
1 revision imported
enws>CalendulaAsteraceae
No edit summary
 
m (1 revision imported)
 
(2 intermediate revisions by 2 users not shown)
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)
if namespace == '' then
namespace = string.gsub(namespace, ' ', '_')
namespace = 'main'
local target = string.lower(args.target or 'main')
if yesno(args['include-talk']) then
namespace = string.gsub(namespace, '[%s_]*talk', '')
end
end
local target = string.lower(args.target or 'main')
local special_targets = {
local special_targets = {
['page index'] = {page = true, index = true}
['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][namespace]) then
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