Module:voir

Définition, traduction, prononciation, anagramme et synonyme sur le dictionnaire libre Wiktionnaire.

 Documentation[voir] [modifier] [historique] [purger]

Ce module réunit des fonctions pour afficher les modèles {{voir}}, {{voir autres systèmes}} et {{voir autres scripts}}.

Fonctions :

templateSee(frame)
Utilisable indirectement dans un modèle voir. Crée une liste formatée à partir de la liste d'éléments donnés au modèle. Le bandeau n’est pas inclus.
templateSeeOtherScripts(frame)
Utilisable indirectement dans un modèle voir autres scripts. Crée une liste formatée « script : symbole » à partir de la liste de paires d’éléments donnés au modèle. Le bandeau n’est pas inclus.

-- Avant de publier toute modification, testez l’affichage dans [[Discussion module:voir]]
local m_bases = require("Module:bases")

local p = {}

--- Parses the raw arguments.
--- @param rawTable table Raw parameters table.
--- @param title string Current page’s title.
--- @return table The parsed list.
local function _toTable(rawTable, title)
  local i = 1
  local maxLinks = 200
  local paramsTable = {}

  while rawTable[i] and i <= maxLinks do
    local item = mw.text.trim(rawTable[i])

    -- Pour traiter [[page (explication)]]
    local description = (mw.ustring.match(item, " %(([^%(%)%|]*)%)$")) or ""
    if description ~= "" then
      description = " ''(" .. description .. ")''"
      item = mw.ustring.gsub(item, " %([^%(%)%|]*%)$", "")
    end

    -- Caractères spéciaux non représentables avec une page : à écrire comme Lien{{!}}Caractère
    -- (Bricolage : pas possible de faire mieux ?)
    local link = mw.ustring.gsub(item, "|.*", "")

    if link ~= "" and link ~= title then
      table.insert(paramsTable, "[[" .. item .. "]]" .. description)
    end
    i = i + 1
  end
 
  return paramsTable
end

local function containsDuplicates(list)
  local maxLinks = 200
  local i = 1
  while list[i] and i <= maxLinks do
    local j = i + 1
    while list[j] and j <= maxLinks do
      if list[i] == list[j] then
      	return true
      end
      j = j + 1
    end
    i = i + 1
  end
  return false	
end

--- Actually builds the list of values. The entry corresponding to the title of
--- the current page is hidden.
--- @param values table The values to display as a list.
--- @return string The formatted list.
local function _makeText(values)
  local title = mw.title.getCurrentTitle().fullText
  local list = _toTable(values, title)
  local text = ''

  if #list > 0 then
    text = table.concat(list, ", ")
    if containsDuplicates(list) then
  	  text = text .. '<br><span style="color: red">Le modèle voir contient des doublons. Merci de les retirer.</span>[[Catégorie:Wiktionnaire:Modèle voir avec doublons]]'
    end
  else
    text = "(Merci de rajouter les articles en paramètres, ou à défaut d’enlever ce modèle)"
    text = text .. m_bases.fait_categorie_contenu('Modèle voir sans paramètre valide')
  end

  return text
end

--- Builds the list for [[Modèle:voir]] and [[Modèle:voir autres systèmes]].
function p.templateSee(frame)
  return _makeText(frame:getParent().args)
end

--- Builds the list for [[Modèle:voir autres scripts]].
function p.templateSeeOtherScripts(frame)
  local args = frame:getParent().args
  local values = {}

  local i = 1
  while args[i] do
    table.insert(values, args[i + 1] .. " (" .. args[i] .. ")")
    i = i + 2
  end

  return _makeText(values)
end

--- Builds the list for [[Modèle:voir autres systèmes]].
function p.templateSeeOtherSystems(frame)
  local args = frame:getParent().args
  local values = {}
  local lang_code = args[1]

  local i = 2
  while args[i] do
    table.insert(values, args[i] .. "#" .. lang_code .."|" .. args[i])
    i = i + 1
  end

  return _makeText(values)
end

return p