Modul:Displaytitle

A Wikipédiából, a szabad enciklopédiából

Displaytitle[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

local p = {}
local getArgs = require( 'Modul:Arguments' ).getArgs

local function testTitle( title )
	-- extract any templates, parser functions etc.
	title = mw.getCurrentFrame():preprocess( title )
	-- remove bold markers
	title = string.gsub( title, "'''", "" )
	-- remove italic markers
	title = string.gsub( title, "''", "" )
	-- remove superscript/subscript
	title = string.gsub( title, '</?su[bp]>', '' )
	
	local dbTitle = mw.title.getCurrentTitle()
	if title:find('#', 1, true) then
		return false
	elseif dbTitle == mw.title.new( title ) then
		return ''
	elseif dbTitle == mw.title.new( title, dbTitle.nsText ) then
		return dbTitle.nsText .. ':'
	else
		return false
	end
end

function p.badtitle( frame )
	local args = getArgs( frame )
	local realTitle = args[ 1 ]
	if not realTitle then
		return nil
	end
	local demo = ( args.minta ~= nil )
	local test = testTitle( realTitle )
	if demo or not test then
		return string.format( ":''A szócikk címe technikai okok miatt pontatlan. A helyes cím: '''%s'''.''", realTitle )
	else
		return mw.getCurrentFrame():preprocess( string.format( '{{DISPLAYTITLE:%s%s}}', test, realTitle ) )
	end
end

return p