Module:Drvlinks: Difference between revisions
Appearance
Content deleted Content added
link template title code |
use a real error instead of a fake one |
||
Line 25: | Line 25: | ||
ns = mw.site.namespaces[ns] |
ns = mw.site.namespaces[ns] |
||
if not ns or ns.id < 0 then -- Invalid parameter or a special namespace |
if not ns or ns.id < 0 then -- Invalid parameter or a special namespace |
||
error(string.format( |
|||
' |
'Invalid %s, please use "Article" or a namespace name listed ' .. |
||
' |
'at [[Wikipedia:Namespaces]] (excluding special namespaces)', |
||
'(excluding special namespaces).</strong>', |
|||
para('ns') |
para('ns') |
||
) |
), 2) |
||
end |
end |
||
Revision as of 02:07, 2 November 2014
-- This module implements {{drvlinks}}
local lang = mw.language.getContentLanguage()
local p = {}
local function para(k, v)
local pipe = mw.text.nowiki('|')
local equals = mw.text.nowiki('=')
return '<code>' .. pipe .. k .. equals .. (v or '') .. '</code>'
end
function p._main(args)
-- Get the namespace table from mw.site.namespaces
local ns
if type(args.ns) == 'string' then
ns = lang:ucfirst(args.ns)
else
ns = args.ns
end
ns = tonumber(ns) or ns
if ns == 'Article' then
ns = 0
end
ns = mw.site.namespaces[ns]
if not ns or ns.id < 0 then -- Invalid parameter or a special namespace
error(string.format(
'Invalid %s, please use "Article" or a namespace name listed ' ..
'at [[Wikipedia:Namespaces]] (excluding special namespaces)',
para('ns')
), 2)
end
local linkTemplateTitle
if ns.id == 0 then
linkTemplateTitle = 'la'
elseif ns.id == 1 then
linkTemplateTitle = 'lat'
elseif ns.isTalk then
linkTemplateTitle = 'lnt'
else
linkTemplateTitle = 'ln'
end
end
function p.main(frame)
local args = require('Modue:Arguments').getArgs(frame, {
wrappers = 'Template:Drvlinks'
})
return p._main(args)
end
return p