<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.cern.ch/index.php?action=history&amp;feed=atom&amp;title=Module%3ACategory_main_article</id>
	<title>Module:Category main article - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cern.ch/index.php?action=history&amp;feed=atom&amp;title=Module%3ACategory_main_article"/>
	<link rel="alternate" type="text/html" href="https://wiki.cern.ch/index.php?title=Module:Category_main_article&amp;action=history"/>
	<updated>2026-04-04T13:32:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.cern.ch/index.php?title=Module:Category_main_article&amp;diff=7725&amp;oldid=prev</id>
		<title>Vigen: 1 revision imported from :wikipedia:Module:Category_main_article</title>
		<link rel="alternate" type="text/html" href="https://wiki.cern.ch/index.php?title=Module:Category_main_article&amp;diff=7725&amp;oldid=prev"/>
		<updated>2026-03-19T08:09:37Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported from &lt;a href=&quot;https://en.wikipedia.org/wiki/Module:Category_main_article&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Module:Category main article&quot;&gt;wikipedia:Module:Category_main_article&lt;/a&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 08:09, 19 March 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Vigen</name></author>
	</entry>
	<entry>
		<id>https://wiki.cern.ch/index.php?title=Module:Category_main_article&amp;diff=7724&amp;oldid=prev</id>
		<title>wikipedia&gt;Pigsonthewing: per talk page request</title>
		<link rel="alternate" type="text/html" href="https://wiki.cern.ch/index.php?title=Module:Category_main_article&amp;diff=7724&amp;oldid=prev"/>
		<updated>2025-12-08T18:37:11Z</updated>

		<summary type="html">&lt;p&gt;per talk page request&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements {{Category main article}}.&lt;br /&gt;
&lt;br /&gt;
local mHatnote = require(&amp;#039;Module:Hatnote&amp;#039;)&lt;br /&gt;
local mFormatLink = require(&amp;#039;Module:Format link&amp;#039;)&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
local mTableTools -- lazily initialise&lt;br /&gt;
local mArguments -- lazily initialise&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Helper: true if the page is in Template: or Module: namespace&lt;br /&gt;
local function isTemplateOrModule(title)&lt;br /&gt;
	local t = (type(title) == &amp;#039;string&amp;#039; and title) or (title and title.prefixedText) or &amp;#039;&amp;#039;&lt;br /&gt;
	if t == &amp;#039;&amp;#039; then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	local ok, tt = pcall(mw.title.new, t)&lt;br /&gt;
	if not ok or not tt then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	local ns = tt.namespace&lt;br /&gt;
	return ns == 10 or ns == 828&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.catMain(frame)&lt;br /&gt;
	mTableTools = require(&amp;#039;Module:TableTools&amp;#039;)&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	-- Grab args&lt;br /&gt;
	local args = mArguments.getArgs(frame, {wrappers = &amp;#039;Template:Category main article&amp;#039;})&lt;br /&gt;
	local pages = mTableTools.compressSparseArray(args)&lt;br /&gt;
	if #pages == 0 and args[1] then&lt;br /&gt;
		pages = { args[1] }&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local options = {&lt;br /&gt;
		article = args.article,&lt;br /&gt;
		selfref = args.selfref,&lt;br /&gt;
		_rawPages = pages,&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	-- Determine the outer page (the page using the template)&lt;br /&gt;
	local thisTitle = frame and frame.getParent and frame:getParent() and frame:getParent().title or mw.title.getCurrentTitle()&lt;br /&gt;
	local titleText = thisTitle and thisTitle.prefixedText or &amp;#039;&amp;#039;&lt;br /&gt;
	local ns = thisTitle and thisTitle.namespace or nil&lt;br /&gt;
&lt;br /&gt;
	-- Skip tracking categories on template/module pages&lt;br /&gt;
	local isTemplate = isTemplateOrModule(titleText)&lt;br /&gt;
&lt;br /&gt;
	-- Remember original arg count&lt;br /&gt;
	local origCount = #pages&lt;br /&gt;
&lt;br /&gt;
	-- Generate hatnote text&lt;br /&gt;
	local text, firstLink, usedAutoFill = p._catMain(options, thisTitle, unpack(pages))&lt;br /&gt;
&lt;br /&gt;
	if isTemplate then&lt;br /&gt;
		-- On templates/modules, just return the hatnote (no tracking categories)&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Add tracking categories&lt;br /&gt;
	local cats = {}&lt;br /&gt;
&lt;br /&gt;
	-- Wrong namespace detection (Article, Draft)&lt;br /&gt;
	if ns == 0 or ns == 118 then&lt;br /&gt;
		table.insert(cats, &amp;#039;[[Category:Articles using category hatnotes]]&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Title mismatch detection&lt;br /&gt;
	if firstLink and (origCount == 1 or (origCount == 0 and usedAutoFill)) then&lt;br /&gt;
		local function normalizeTitle(s)&lt;br /&gt;
			return (s or &amp;#039;&amp;#039;):gsub(&amp;#039;^%s+&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;%s+$&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;^[^:]*:&amp;#039;, &amp;#039;&amp;#039;):gsub(&amp;#039;%s+&amp;#039;, &amp;#039; &amp;#039;):gsub(&amp;#039;^%l&amp;#039;, string.upper)&lt;br /&gt;
		end&lt;br /&gt;
		local compareStr&lt;br /&gt;
		if usedAutoFill then&lt;br /&gt;
			compareStr = normalizeTitle(firstLink)&lt;br /&gt;
		else&lt;br /&gt;
			local raw = (options._rawPages and options._rawPages[1]) or firstLink&lt;br /&gt;
			compareStr = normalizeTitle(raw:gsub(&amp;quot;|.*&amp;quot;, &amp;quot;&amp;quot;))&lt;br /&gt;
		end&lt;br /&gt;
		local catName = normalizeTitle(thisTitle and thisTitle.text or &amp;#039;&amp;#039;)&lt;br /&gt;
		if compareStr ~= catName then&lt;br /&gt;
			table.insert(cats, &amp;#039;[[Category:Category main article does not match category title]]&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if #cats &amp;gt; 0 then&lt;br /&gt;
		text = text .. &amp;#039;\n&amp;#039; .. table.concat(cats, &amp;#039;\n&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._catMain(options, thisTitle, ...)&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	local pages = {...}&lt;br /&gt;
&lt;br /&gt;
	thisTitle = thisTitle or mw.title.getCurrentTitle()&lt;br /&gt;
	local fullTitle = thisTitle and thisTitle.prefixedText or &amp;#039;&amp;#039;&lt;br /&gt;
	local thisText = thisTitle and thisTitle.text or (pages[1] or &amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	local isTemplate = isTemplateOrModule(fullTitle)&lt;br /&gt;
&lt;br /&gt;
	-- Red link detection&lt;br /&gt;
	local rawLinks = mFormatLink.formatPages({&lt;br /&gt;
		categorizeMissing = not isTemplate and &amp;#039;Categories with hatnote templates targeting a non-existent page&amp;#039; or nil&lt;br /&gt;
	}, pages)&lt;br /&gt;
&lt;br /&gt;
	-- Convert to plain strings&lt;br /&gt;
	local links = {}&lt;br /&gt;
	for i, link in ipairs(rawLinks or {}) do&lt;br /&gt;
		links[i] = tostring(link)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Auto-fill if empty&lt;br /&gt;
	local firstOutputLink = nil&lt;br /&gt;
	local usedAutoFill = false&lt;br /&gt;
&lt;br /&gt;
	if not links[1] or links[1] == &amp;#039;&amp;#039; then&lt;br /&gt;
		local title = mw.title.new(thisText)&lt;br /&gt;
		if title and title.isRedirect then&lt;br /&gt;
			title = title.redirectTarget&lt;br /&gt;
		end&lt;br /&gt;
		firstOutputLink = title and title.text or thisText&lt;br /&gt;
		usedAutoFill = true&lt;br /&gt;
		links[1] = tostring(mFormatLink._formatLink{&lt;br /&gt;
			link = firstOutputLink,&lt;br /&gt;
			categorizeMissing = not isTemplate and &amp;#039;Categories with hatnote templates targeting a non-existent page&amp;#039; or nil&lt;br /&gt;
		})&lt;br /&gt;
		pages = { firstOutputLink }&lt;br /&gt;
	else&lt;br /&gt;
		local visible = links[1]&lt;br /&gt;
		visible = visible:gsub(&amp;quot;^&amp;#039;&amp;#039;&amp;#039;&amp;quot;, &amp;quot;&amp;quot;):gsub(&amp;quot;&amp;#039;&amp;#039;&amp;#039;$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		visible = visible:gsub(&amp;quot;%[%[&amp;quot;, &amp;quot;&amp;quot;):gsub(&amp;quot;%]%]&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		visible = visible:gsub(&amp;quot;|.*$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		visible = visible:gsub(&amp;quot;#.*$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		firstOutputLink = visible&lt;br /&gt;
		usedAutoFill = false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Bold links&lt;br /&gt;
	for i, link in ipairs(links) do&lt;br /&gt;
		links[i] = string.format(&amp;quot;&amp;#039;&amp;#039;&amp;#039;%s&amp;#039;&amp;#039;&amp;#039;&amp;quot;, link)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Determine pagetype&lt;br /&gt;
	local pagetype&lt;br /&gt;
	if options.article ~= nil then&lt;br /&gt;
		pagetype = yesno(options.article) ~= false and &amp;#039;article&amp;#039; or &amp;#039;page&amp;#039;&lt;br /&gt;
	elseif pages and pages[1] then&lt;br /&gt;
		local page = pages[1]:gsub(&amp;quot;|.*&amp;quot;,&amp;quot;&amp;quot;)&lt;br /&gt;
		local tt = mw.title.new(page)&lt;br /&gt;
		pagetype = tt and tt.namespace == 0 and &amp;quot;article&amp;quot; or &amp;quot;page&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		pagetype = &amp;quot;article&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Work out whether we need to be singular or plural&lt;br /&gt;
	local stringToFormat&lt;br /&gt;
	if #links &amp;gt; 1 then&lt;br /&gt;
		stringToFormat = &amp;#039;The main %ss for this [[Help:Categories|category]] are %s.&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		stringToFormat = &amp;#039;The main %s for this [[Help:Categories|category]] is %s.&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Build hatnote text&lt;br /&gt;
	local text = string.format(&lt;br /&gt;
		stringToFormat,&lt;br /&gt;
		pagetype,&lt;br /&gt;
		mw.text.listToText(links)&lt;br /&gt;
	)&lt;br /&gt;
&lt;br /&gt;
	-- Pass through Module:Hatnote&lt;br /&gt;
	local hnOptions = { selfref = options.selfref }&lt;br /&gt;
	text = mHatnote._hatnote(text, hnOptions)&lt;br /&gt;
&lt;br /&gt;
	return text, firstOutputLink, usedAutoFill&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>wikipedia&gt;Pigsonthewing</name></author>
	</entry>
</feed>