Modul:Disambiguation

Dokuméntasi antuk modul puniki prasida kakardi ring Modul:Disambiguation/doc

require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

function p._disambiguation(argsWithBlanks)
	local args = {}
	for k, v in pairs(argsWithBlanks) do
		if k == 'categories' or v ~= '' then
			args[k] = v
		end
	end
	
	local current_title = mw.title.getCurrentTitle()
	local namespace = args.namespace or current_title.nsText
	local shared = yesno(args.shared)
	
	-- info text
	local infoword1 = 'works'
	local infoword2 = 'title'
	
	if namespace == 'Pangawi' then
		infoword1 = 'pangawi'
		infoword2 = 'wastan'
	elseif namespace == 'Kori' then
		infoword1 = 'kori'
		infoword2 = 'indik'
	end
	
	local info = tostring(mw.html.create('p'):css({['font-style'] = 'italic'}):wikitext(table.concat({
		'This is a [[WS:STYLE#Disambiguation, versions and translations pages|disambiguation page]]. It lists ',
		infoword1,
		' that share the same ',
		infoword2,
		'. If an [[Special:Whatlinkshere/',
		current_title.fullText,
		'|article link]] referred you here, please consider editing it to point directly to the intended page.'
	})))
	if args.notes then
		info = info .. '<p>' .. args.notes .. '</p>'
	end
	
	-- header
	local header
	local postheader = tostring(mw.html.create('div'):addClass('subNote'):css({['margin'] = '4px auto 4px auto'}):wikitext(
		tostring(mw.html.create('span'):attr('id', 'nofooter'):wikitext(
			args.intro
			or tostring(mw.html.create('span'):css({['font-weight'] = 'bold', ['font-style'] = 'italic'}):wikitext(args.title or current_title.text)) .. ' may refer to:'
		))
	))
	local disambig_text = ' <span style="font-weight:normal;">(disambiguation)</span>'
	local cat = namespace .. ' disambiguation pages'
	if namespace == 'Author' then
		header = require('Module:Author')._author({
			firstname = current_title.text .. disambig_text,
			last_initial = '!NO_INITIALS',
			description = info,
			wikipedia = args.wikipedia,
			nocat = true,
			defaultsort = args.defaultsort,
			disambiguation = true
		})
	elseif namespace == 'Portal' then
		header = require('Module:Portal header')._portal_header({
			title = current_title.text .. disambig_text,
			class = 'none',
			nocat = true,
			reviewed = 'n/a',
			notes = info,
			disambiguation = true
		})
	elseif namespace == '' or namespace == 'Template' then
		local pretitle = 'Works'
		if shared then
			pretitle = 'Works and pages in other namespaces'
		end
		pretitle = pretitle .. ' entitled'
		
		if shared and not current_title.isSubpage then
			-- should be redundant as attached to header
			info = info .. '[[Category:' .. 'Merged disambiguation pages' .. ']]'
		end
		
		header = require('Module:Header')._header({
			pretitle = pretitle,
			title = args.title,
			section = args.section,
			author = args.author,
			notes = info,
			wikipedia = args.wikipedia,
			commonscat = args.commonscat,
			wikiquote = args.wikiquote,
			wikinews = args.wikinews,
			disambiguation = true,
			portal = args.portal,
			header_class = 'ws-dynlayout-disable',
			defaultsort = args.defaultsort
		})
		
		cat = 'Mainspace disambiguation pages'
	else
		header = require('Module:Error')['error']({'[[Module:Disambiguation]] error: {{[[Template:Disambiguation|disambiguation]]}} is only for use in the Main, Author and Portal [[Help:Namespace|namespaces]]'})
		postheader = ''
		cat = 'Disambiguation pages in inappropriate namespaces'
	end
	
	return header .. mw.getCurrentFrame():preprocess('__DISAMBIG__') .. postheader .. (args.category or '[[Category:' .. cat .. ']]')
end

function p.disambiguation(frame)
	return p._disambiguation(getArgs(frame, {removeBlanks = false}))
end

return p