Module:section article
Ce module définit des fonctions pour manipuler les titres de sections des articles (synonymes, étymologie, etc.) autres que les sections de langue et les sections de mots. Il utilisé essentiellement par Module:section.
La définition des sections standardisées et des alias autorisés est écrite dans Module:section article/data.
Fonctions exportées
isValidSectionType()
Indique si la valeur passée est un titre de section valide.
- Paramètres
code
(string) : La valeur à tester.
- Type de retour
- boolean
isSectionTypeAlias()
Indique si la valeur passée est un alias de titre de section.
- Paramètres
code
(string) : La valeur à tester.
- Type de retour
- boolean
getSectionTypeName()
Retourne le nom d’un titre de section ou nil
s’il n’en possède pas (très certainement un bug dans ce cas).
code
(string) : Le code de la section dont le nom doit être retourné.
- Type de retour
- string|nil
getSectionTypeClass()
Retourne la classe CSS d’un titre de section ou nil
s’il n’en possède pas.
code
(string) : Le code de la section dont la classe CSS doit être retournée.
- Type de retour
- string|nil
getSectionTypeCategoryName()
Retourne le nom de la catégorie d’un titre de section ou nil
s’il n’en possède pas.
code
(string) : Le code de la section dont le nom doit être retourné.
- Type de retour
- string|nil
getSectionTypePopupText()
Retourne le texte d’infobulle d’un titre de section ou nil
s’il n’en possède pas. Il s’agit du texte de l’attribut title
de la balise HTML du titre.
code
(string) : Le code de la section dont le texte d’infobulle doit être retourné.
- Type de retour
- string|nil
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Module:section article/Documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local data = mw.loadData("Module:section article/data")
local p = {}
--- Get the data for the given section type code.
--- @param code string The section type code to get the data of.
--- @return table|nil A `table` containing the data for the given section type, or `nil` if the code is `nil` or `invalid`.
local function getSectionData(code)
if code == nil then
return nil
end
if p.isSectionTypeAlias(code) then
code = data["alias"][code]
end
if data["texte"][code] then
return data["texte"][code]
end
return nil
end
--- Check whether the given value is a valid section type code from [[Module:section article/data]].
--- @param code string The string to check.
--- @return boolean True if the argument is a valid section type code, false otherwise.
function p.isValidSectionType(code)
return code and getSectionData(code)
end
--- Check whether the given value is a valid section type code alias from [[Module:section article/data]].
--- @param code string The string to check.
--- @return boolean True if the argument is a valid section type code alias, false otherwise.
function p.isSectionTypeAlias(code)
return code and data["alias"][code]
end
--- Return the value of the given property for a specific section type.
--- @param code string The code of a section type as defined in [[Module:section article/data]].
--- @param propertyName string The name of the property.
--- @return string|nil The property’s value or `nil` if it there is no data for the given code or the property is undefined.
local function getProperty(code, propertyName)
local sectionTypeData = getSectionData(code)
return sectionTypeData and sectionTypeData[propertyName]
end
--- Get the name of the given section type code.
--- @param code string The code of a section type as defined in [[Module:section article/data]].
--- @return string|nil The section type’s name or `nil` if the code is `nil` or invalid.
function p.getSectionTypeName(code)
return getProperty(code, "nom")
end
--- Get the CSS class of the given section type code.
--- @param code string The code of a section type as defined in [[Module:section article/data]].
--- @return string|nil The section type’s CSS class or `nil` if the section type has none or the code is `nil` or invalid.
function p.getSectionTypeClass(code)
return getProperty(code, "class")
end
--- Get the category name of the given section type code.
--- @param code string The code of a section type as defined in [[Module:section article/data]].
--- @return string|nil The section type’s category name or `nil` if the section type has none or the code is `nil` or invalid.
function p.getSectionTypeCategoryName(code)
return getProperty(code, "category")
end
--- Get the popup text of the given section type code.
--- @param code string The code of a section type as defined in [[Module:section article/data]].
--- @return string|nil The section type’s popup text or `nil` if the section type has none or the code is `nil` or invalid.
function p.getSectionTypePopupText(code)
return getProperty(code, "infobulle")
end
return p