Modül:Ana

Vikipedi, özgür ansiklopedi
Modül belgelemesi[oluştur]
--[[
-- This module produces a link to a main article or articles. It implements the
-- template {{ana}}.
-- 
-- If the module is used in category or category talk space, it produces "The
-- main article for this category is xxx". Otherwise, it produces
-- "Main article: xxx".
--]]

local mHatnote = require('Modül:İlknot')
local mHatlist = require('Modül:İlknot liste')
local mArguments -- lazily initialise
local p = {}

function p.main(frame)
	mArguments = require('Modül:Bağımsız değişkenler')
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local pages = {}
	for k, v in pairs(args) do
		if type(k) == 'number' then
			local display = args['etiket ' .. k] or args['e' .. k] or args['label ' .. k] or args['l' .. k]
			local page = display and
				string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v
			pages[#pages + 1] = page
		end
	end
	if #pages == 0 and mw.title.getCurrentTitle().namespace == 0 then
		return mHatnote.makeWikitextError(
			'sayfa adı girilmedi',
			'Şablon:Ana#Hatalar',
			args.category
		)
	end
	local options = {
		selfref = args.selfref
	}
	return p._main(pages, options)
end

function p._main(args, options)
	-- Get the list of pages. If no first page was specified we use the current
	-- page name.
	local currentTitle = mw.title.getCurrentTitle()
	if #args == 0 then args = {currentTitle.text} end
	local firstPage = string.gsub(args[1], '|.*$', '')
	-- Find the pagetype.
	local pageType = mHatnote.findNamespaceId(firstPage) == 0 and 'madde' or 'sayfa'
	-- Make the formatted link text
	list = mHatlist.andList(args, true)
	-- Build the text.
	local isPlural = #args > 1
	local mainForm
	local curNs = currentTitle.namespace
	if (curNs == 14) or (curNs == 15) then --category/talk namespaces
		if isPlural then
			if pageType == 'madde' then
				mainForm = 'Bu [[Yardım:Kategori|kategori]]nin ana %sleri: %s'
			else
				mainForm = 'Bu [[Yardım:Kategori|kategori]]nin ana %sları: %s'
			end
		else
			if pageType == 'madde' then
				mainForm = 'Bu [[Yardım:Kategori|kategori]]nin ana %ssi: %s'
			else
				mainForm = 'Bu [[Yardım:Kategori|kategori]]nin ana %ssı: %s'
			end
		end
	else
		mainForm = 'Ana %s: %s'
		if isPlural then
			if pageType == 'madde' then
				mainForm = 'Ana %sler: %s'
			else
				mainForm = 'Ana %slar: %s'
			end
		end
	end
	
	-- sayfa mevcut değilse bakım kategorisi ekle
	for k, v in pairs(args) do
		if not mw.title.new(v).exists then
			if curNs == 14 then
				mainForm = mainForm .. '[[Kategori:Kırmızı bağlantıya sahip ana madde şablonu içeren kategoriler]]'
			elseif curNs == 0 then
				mainForm = mainForm .. '[[Kategori:Kırmızı bağlantıya sahip ana madde şablonu içeren maddeler]]'
			else
				mainForm = mainForm .. '[[Kategori:Kırmızı bağlantıya sahip ana madde şablonu içeren sayfalar]]'
			end
		end
	end
	
	local text = string.format(mainForm, pageType, list)
	-- Process the options and pass the text to the _rellink function in
	-- [[Modül:İlknot]].
	options = options or {}
	local hnOptions = {
		selfref = options.selfref
	}
	return mHatnote._hatnote(text, hnOptions)
end

return p