Module:Drvlinks

This module implements {{drvlinks}}. Please see the template page for documentation.

Module:Drvlinks

-- This module implements {{drvlinks}}

local lang = mw.language.getContentLanguage()
local mToolbar = require('Module:Toolbar')

local p = {}

local function para(k, v)
	return string.format('|%s=%s', k, v or '')
end

local function makeWikilink(page, display)
	if display then
		return string.format('[[%s|%s]]', page, display)
	else
		return string.format('[[%s]]', page)
	end
end

local function makeExternalLink(url, display)
	-- The URL can be a URL string or a mw.uri object.
	url = tostring(url)
	return string.format('[%s %s]', url, display)
end

function p._main(args, frame)
	frame = frame or mw.getCurrentFrame()

	-- Get the page name
	local page = args.pg
	if not page then
		error('no page name specified; please use ' .. para('pg', "''pagename''"), 2)
	end

	-- Get the namespace table from mw.site.namespaces
	local ns = args.ns
	if type(ns) == 'string' then
		ns = ns:lower()
		ns = lang:ucfirst(ns)
	end
	ns = tonumber(ns) or ns
	if not ns or 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

	-- Get the page links
	local pageLinks
	do
		local templateTitle
		if ns.id == 0 then
			templateTitle = 'la'
		elseif ns.id == 1 then
			templateTitle = 'lat'
		elseif ns.isTalk then
			templateTitle = 'lnt'
		else
			templateTitle = 'ln'
		end

		local targs = {}
		if templateTitle == 'ln' then
			targs[1] = ns.name
			targs[2] = page
		elseif templateTitle == 'lnt' then
			targs[1] = ns.subject.name
			targs[2] = page
		else
			targs[1] = page
		end

		pageLinks = frame:expandTemplate{title = templateTitle, args = targs}
	end

	-- Get the tool links
	local toolLinks
	do
		local tlargs = {}
		local fullPageName
		if ns.id == 0 then
			fullPageName = page
		else
			fullPageName = ns.name .. ':' .. lang:ucfirst(page)
		end

		-- Restore link
		tlargs[#tlargs + 1] = makeWikilink(
			'Special:Undelete/' .. fullPageName,
			'restore'
		)

		-- Google cache link
		local pageUrl = mw.uri.fullUrl(fullPageName)
		pageUrl = tostring(pageUrl)
		tlargs[#tlargs + 1] = makeExternalLink(
			'https://www.google.com/search?q=cache:' .. pageUrl,
			'cache'
		)

		-- XfD link
		if ns.id ~= 6 and ns.id ~= 10 and ns.id ~= 14 then
			-- No XfD links for files, templates or categories.
			local xfdPage, display
			if ns.id == 0 then
				xfdPage = 'Wikipedia:Articles for deletion/' .. fullPageName
				display = 'AfD'
			else
				xfdPage = 'Wikipedia:Miscellany for deletion/' .. fullPageName
				display = 'MfD'
			end
			tlargs[#tlargs + 1] = makeWikilink(xfdPage, display)
		end

		toolLinks = mToolbar._main(tlargs)
	end

	return pageLinks .. ' ' .. toolLinks
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Drvlinks'
	})
	return p._main(args, frame)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.