Jump to content

Module:Interwiki extra

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 01:36, 21 January 2015 (make a start on using this with mw.site.interwikiMap). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module provides functions and objects for dealing with interwiki links.

local checkType = require('libraryUtil').checkType
local interwikiData = mw.loadData('Module:Interwiki/data')

--------------------------------------------------------------------------------
-- Prefix class
--------------------------------------------------------------------------------

local Prefix = {}
Prefix.__index = Prefix

function Prefix.new(code)
	checkType('Prefix.new', 1, code, 'string')
	local obj = setmetatable({}, Prefix)
	local data = interwikiData.prefixes[code]
	if not data then
		return nil
	end
	for k, v in pairs(data) do
		obj[k] = v
	end
	return obj
end

function Prefix:makeUrl(page)
	-- Interlanguage links are wiki-encoded (spaces are encoded as underbars),
	-- even if the page is not a wiki and it doesn't make sense on that site.
	page = mw.uri.encode(page, 'WIKI')
	return mw.message.newRawMessage(self.url, page):plain()
end

return Prefix