Jump to content

Module:Article by Quality and Importance

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Lopullinen (talk | contribs) at 10:43, 5 December 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function genQuery(t)
    local ret = ""

    local q, i = mw.ustring.match(t, "^([^,]*),%s*(.*)$")

    if q ~= "" then ret = "%?quality=" .. q .. "%-Class" end
    if i ~= "" then
        ret = ret .. (ret and "&" or "%?") .. "importance=" .. i .. "%-Class"
    end
    ret = ret .. "%s+" .. "([0-9,]+)"

    return ret
end

function p.main(frame)
    local args = getArgs(frame)
    return p._main(args)
end

function p._main(args)
    local count = 0
    local text =
        mw.title.new("User:WP 1.0 bot/Tables/Project/" .. args.subpage):getContent()

    for _, v in ipairs(args) do
        count = count + mw.ustring.gsub(mw.ustring.match(text, genQuery(v)) or 0,",", "")
    end

    return count
end

return p