Jump to content

Module:Drvlinks

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 02:07, 2 November 2014 (use a real error instead of a fake one). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- 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