Module:Gebruiker:Bdijkstra/DisplayTitle

Uit Wikipedia, de vrije encyclopedie

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Gebruiker:Bdijkstra/DisplayTitle/doc

-- Module for DISPLAYTITLE stuff
local p = {}

function p.test(frame)
	local str = frame.args[1]
	local str1 = string.gsub(str, "^(.*)( %(.*%))$", "''%1''%2")
	local eq1 = tostring(str == str1)
	local str2 = string.gsub(str, "^(.*)$", "''%1''")
	local eq2 = tostring(str == str2)
	return str..": 1="..str1.."("..eq1..") 2="..str2.."("..eq2..")"
end

-- Returns a new page title where the (sub)pagename without parenthesized
-- suffix is surrounded by double quotes ('').
-- i.e. "Sinterklaas (film)" results in "''Sinterklaas'' (film)"
-- i.e. "User:Zwarte Piet/Kladblok/Sinterklaas (film)" results in 
--      "User:Zwarte Piet/Kladblok/''Sinterklaas'' (film)"
function p.cursief(frame)
    -- Voor welke pagina?
    local title = frame.args.pagina or frame.args[1]
	if ( not title or title == "" ) then
		title = mw.title.getCurrentTitle()
	else
		title = mw.title.new(title)
	end

    local namespace = title.namespace
    local base = title.baseText
    local subpage = title.subpageText

    local subpagei = string.gsub(subpage, "^(.*)( %(.*%))$", "''%1''%2")
    if subpage == subpagei then
    	subpagei = "''"..subpage.."''"
    end
    local pagename
    if base == subpage then
		pagename = subpagei
	else
		pagename = base.."/"..subpagei
	end
    title = mw.title.makeTitle(namespace, pagename)
    local r = title.prefixedText
    return r
end

return p