Module:Count

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]

Usage[edit]

{{#invoke:count|targets|Global message delivery/Targets/Wikidata}}

This will output:

353

local p = {}

--[[Just count the number of occurences of '{{target' found
    in the wikitext content of page specified in parameter 1.
  ]]
function p.targets( frame )
    title = mw.title.new(frame.args[1])
    page_text = title:getContent()
    -- result of substitution is discarded, just keep the number of matches
    local _, occurences = string.gsub(page_text, '{{target', '')
    return occurences
end

return p