Module:Article link count
Appearance
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
Returns the count of unique article (namespace 0) links on a page. While usable with any wiki page, this is especially useful in conjunction with the results of {{Database report}}-based or other internally generated reports that list articles using a standard wikilink format ([[link|pipe]]).
Usage
[edit]{{#invoke:Article link count|pagename}}
Or via template:
{{Article link count|pagename}}
Notes:
- Links within html comments or nowiki tags will not be counted.
- For performance reasons, this module does not check for the existence of any article linked on the page. Therefore, red links will be counted.
-- Article link count module
-- Initial code by Stefen đower nĂ© Steve Magruder (5 March 2026) [[User:StefenTower]].
-- @module Article link count
local p = {}
function p.countUniqueArticleLinks(frame)
local args = frame.args
if args[1] == nil and args.page == nil then
args = frame:getParent().args
end
local pageName = args[1] or args.page or ""
if pageName == "" then return "0" end
local targetTitle = mw.title.new(pageName)
if not targetTitle or not targetTitle.exists then
return "0" -- Returns 0 if the page doesn't exist
end
local text = targetTitle:getContent()
-- Disregard links within html comments or nowiki tags
text = text:gsub("<!%-%-.-%-%->", "")
text = text:gsub("<[Nn][Oo][Ww][Ii][Kk][Ii]>.-</[Nn][Oo][Ww][Ii][Kk][Ii]>", "")
local uniqueLinks = {}
local count = 0
for linkText in text:gmatch("%[%[([^%[%]|]+)") do
linkText = mw.text.trim(linkText)
if linkText ~= "" and not uniqueLinks[linkText] then
local linkTitle = mw.title.new(linkText)
if linkTitle and linkTitle.namespace == 0 then
uniqueLinks[linkText] = true
count = count + 1
end
end
end
return count
end
return p