There are no reviewed versions of this page, so it may not have been checked for adherence to standards.

Documentation for this module may be created at Module:Title/doc

local bodge = require "Module:mw"

local z = {}

-- This is used by template {{italic title}}.
function z.italicize(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local pagename = config.pagename or ""
    local namespace = config.namespace or ""
    local title, disambiguator 
    if "true" ~= args.force then -- This is a string, "true", not a boolean.
        title, disambiguator = pagename:match("(.*)(%(.*%))")
        if nil == title then
            local index = 1
            while true do
                local arg = args[index]
                if arg == nil then break end
                title, disambiguator = pagename:match("(.*)(" .. arg .. ")")
                if title ~= nil then break end
                index = index + 1
            end
        end
    end
    if nil == title then title, disambiguator = pagename, "" end
    if "" ~= namespace then namespace = namespace .. ":" end
    return frame:preprocess("{{DISPLAYTITLE:" .. namespace .. "''" .. title .. "''" .. (disambiguator or "") .. "}}")
end

function z.lowchar(ch)
    local cbyt = string.byte(ch)
    local lowch = ch
    local xlet = {
    -- 1 ----- 2 ----- 3 ----- 4 ----- 5 ----- 6 ----- 7 ----- 8 -----
      'Α','α','Β','β','Γ','γ','Δ','δ','Ε','ε','Ζ','ζ','Η','η','Θ','θ',
      'Ι','ι','Κ','κ','Λ','λ','Μ','μ','Ν','ν','Ξ','ξ','Ο','ο','Π','π',
      'Ρ','ρ','Σ','σ','Τ','τ','Υ','υ','Φ','φ','Χ','χ','Ψ','ψ','Ω','ω',
      'Á','á','À','à','Â','â','Ä','ä','Ǎ','ǎ','Ă','ă','Ā','ā','Ã','ã',
      'Å','å','Ą','ą','Æ','æ','Ć','ć','Ċ','ċ','Ĉ','ĉ','Č','č','Ç','ç',
      'É','é','È','è','Ė','ė','Ê','ê','Ë','ë','Ě','ě','Ĕ','ĕ','Ē','ē',
      'Ẽ','ẽ','Ę','ę','Ẹ','ẹ','Ġ','ġ','Ĝ','ĝ','Ğ','ğ','Ģ','ģ','Ĥ','ĥ',
      'Ħ','ħ','Ń','ń','Ň','ň','Ñ','ñ','Ņ','ņ','Ó','ó','Ò','ò','Ô','ô',
      'Ö','ö','Ŏ','ŏ','Ō','ō','Õ','õ','Ś','ś','Ŝ','ŝ','Š','š','Ş','ş',
      'Ť','ť','Ţ','ţ','Ú','ú','Ù','ù','Û','û','Ü','ü','Ŭ','ŭ','Ū','ū',
      'Ũ','ũ','Ů','ů','Ŵ','ŵ','Ý','ý','Ŷ','ŷ','Ÿ','ÿ','Ỹ','ỹ','Ź','ź',
      'Ż','ż','Ž','ž','Ð','ð','Þ','þ','Ŋ','ŋ','Ə','ə'
    }
    if (cbyt < 128) then return string.lower(ch) end
    for i = 1, 94 do  --for each pair in array xlet[]
      if ( ch == xlet[i+i-1] ) then
        lowch = xlet[i+i]   -- matches at xlet[2*i - 1]
        break end
    end
    return lowch
end

-- This is used by template {{lowercase title}}.
function z.lowercase(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local pagename = config.pagename or ""
    local pn0 = pagename
    local namespace = config.namespace or ""
    local debugsw = config.debug or ""
    local ch1 = '?'
    if "" ~= namespace then namespace = namespace .. ":" end
    if #pagename > 0 then 
      local more
      ch1 = pagename:sub(1,1)
      if (string.byte(ch1) < 128 and string.byte(ch1) > 64) then 
        ch1 = z.lowchar( ch1 )
        more = string.sub(pagename,2)
      else 
        ch1 = z.lowchar( pagename:sub(1,2) )
        more = string.sub(pagename,3) end
      pagename = ch1 .. more
    end
    local title = namespace .. pagename
    if debugsw ~= "" then
      return "{{DISPLAYTITLE:"..title.."}} - pagnam:" ..pn0:sub(1,1)..'/'..pn0:sub(2,2)..'/'..pn0:sub(3,3).."="..string.byte(pn0:sub(1,1))..'/'..string.byte(pn0:sub(2,2))..'/'..string.byte(pn0:sub(3,3))
    else
      return frame:preprocess("{{DISPLAYTITLE:" .. title .. "}}")
    end
end

return z