Module:basis

E Victionario

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

-- Copy of the [[:fr:Module:bases]]
-- Modified and maintained by: Usor:DenisWasRight

local b = {}

-- Doit-on faire une élision devant ce mot ?
function b.is_elidable(word)
    if (mw.ustring.match( word, "^[aáàâäeéèêëiíìîïoóòôöuúùûüǘǜ]" ) ~= nil) then
        return true
    else
        return false
    end
end

-- S'agit-il d'une locution ?
function b.is_phrase(word)
    if word==nil then return nil end
    if (mw.ustring.find(word, ". .") ~= nil) then
        return true
    else
        return false
    end
end

function b.page_exist(title)
    if title == nil then return nil end
    -- On crée un objet "mw.title" avec le titre de la page dont on cherche à vérifier l'existence
    local article = mw.title.new(title)
    return article.exist
end

-- Renvoie le texte avec la première lettre en majuscule (si le texte est en français)
function b.ucfirst(text)
    if (text == nil) then return text end
    return (mw.ustring.gsub(text, "^([’ǂǃǀǁ]*.)", b.uc))
end
-- Renvoie le texte avec la première lettre en minuscule (si le texte est en français)
function b.lcfirst(text)
    if (text == nil) then return text end
    locale = mw.language.new('la')
    return locale:lcfirst(text)
end
-- Renvoie le texte en majuscule (si le texte est en français)
function b.uc(text)
    if (text == nil) then return text end
    locale = mw.language.new('la')
    return locale:uc(text)
end
-- Renvoie le texte en minuscule (si le texte est en français)
function b.lc(text)
    if (text == nil) then return text end
    locale = mw.language.new('la')
    return locale:lc(text)
end

-- Renvoie vrai si on est dans une page de contenu (principal, annexe, thésaurus)
function b.page_of_content()
    local ns = mw.title.getCurrentTitle().namespace
    
    -- 0 = normal, 100 = Annexe, 106 = Thésaurus
    if ns == 0 or ns == 100 or ns == 106 then
        return true
    else
        return false
    end
end

-- Renvoie une catégorie bien formée
function b.fact_category(text, key, writing)
    local cat = writing and ':Categoria:' or 'Categoria:'
    
    if (text ~= nil) then
        if (key ~= nil and key ~= '') then
            return '[[' .. cat .. text .. '|' .. key .. ']]'
        else
            return '[[' .. cat .. text .. ']]'
        end
    else
        return ''
    end
end

-- Renvoie une catégorie bien formée, si elle est dans un espace principal: normal, annexe, thésaurus
function b.fact_category_content(text, key, writing)
    if b.page_of_content() then
        return b.fact_category(text, key, writing) or ''
    else
        return ''
    end
end

-- Crée l'entête d'un tableau wiki triable (avec les titres en paramètre)
function b.border_header(titles)
    local header = '{| class="wikitable sortable"\r\n'
    header = header .. '|-\r\n!' .. table.concat(titles, ' !! ')
    return header
end

-- Crée une ligne du tableau wiki
function b.border_row(elements)
    local row = '|-\r\n|' .. table.concat(elements, ' || ')
    return row
end

-- Crée la fin d'un tableau
function b.border_fin()
    return "|}\r\n"
end

-- Texte en exposant
function b.exponent(txt)
    return '<sup style="font-size:83%;line-height:1">'..txt..'</sup>'
end

-- balise un texte écrit en langue étrangère
function b.language_tag(txt, code)
	return '<span lang="' .. code .. '">' .. txt .. '</span>'
end

-- Enlève les espaces de part et d'autre de tous les paramètres fournis à arg
function b.trim_parametres(args)
    if args==nil then return nil end
    
    local trim_args = {}
    for k, v in pairs(args) do
        trim_args[k] = mw.text.trim(v)
    end
    return trim_args
end

return b