Module:Compteur d'éditions automatique

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

Utilisation modifier

Fonctions exportables :

  • getEditCount(frame) – renvoie le chiffre correspondant à l'utilisateur en premier argument ou la page appelant quand il n'y a pas d'argument. Si l'utilisateur n'est pas présent dans Module:Compteur d'éditions automatique/data, renvoie "?".

Fonctions internes:

  • getFormattedData(frame, format, data) - renvoie la chaîne "data" formatée selon "format"

Modules externes et autres éléments dont ce module a besoin pour fonctionner :

  • mw.title – Récupère le titre de la page appelante pour connaître l'utilisateur quand le module est utilisé sans argument
  • mw.language - Formate le nombre

Exemples modifier

Pour des exemples, voir la page de test permettant de tester diverses modifications apportées.

--
-- WP-Editcount-Module
--
-- Wikipedia FR Lua module that handles the current edit count of users
-- Copyright (C) 2016 - GPLv2 or CC-BY-SA 3.0 or GFDL
-- <https://fr.wikipedia.org/w/index.php?title=Module:Compteur_d%27%C3%A9ditions_automatique&action=history>
--
local p = {}

-- Get data in formatnum format
local function getFormattedData(format, data)
    -- If the user want the raw data
    if format ~= nil then
        return data
    end
    -- Otherwise format the number
    return mw.language.new('fr'):formatNum(data)
end

function p.getEditCount(frame)
    -- Load and store the bot-updated data
    local data = mw.loadData( 'Module:Compteur d\'éditions automatique/data' )
    -- Get the calling page root title
    local rtitle = mw.title.getCurrentTitle().rootText
    -- Get the 1st level arguments
    local args = frame:getParent().args
    -- If there is a value for the given user (args elseif via title), return it
    if data[args[1]] ~= nil then
        return getFormattedData(args['raw'], data[args[1]])
    elseif data[rtitle] ~= nil then
        return getFormattedData(args['raw'], data[rtitle])
    end
    -- Elsewise just display a "?" until the bot get through it
    return "?"
end

return p