<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://redlettermedia.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ASort_title</id>
	<title>Module:Sort title - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://redlettermedia.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ASort_title"/>
	<link rel="alternate" type="text/html" href="https://redlettermedia.wiki/mediawiki/index.php?title=Module:Sort_title&amp;action=history"/>
	<updated>2026-05-12T17:49:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://redlettermedia.wiki/mediawiki/index.php?title=Module:Sort_title&amp;diff=715&amp;oldid=prev</id>
		<title>Orangestar: 1 revision imported: More leftover templating</title>
		<link rel="alternate" type="text/html" href="https://redlettermedia.wiki/mediawiki/index.php?title=Module:Sort_title&amp;diff=715&amp;oldid=prev"/>
		<updated>2024-06-03T13:32:00Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported: More leftover templating&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:32, 3 June 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&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;!-- diff cache key my_wiki:diff:1.41:old-714:rev-715 --&gt;
&lt;/table&gt;</summary>
		<author><name>Orangestar</name></author>
	</entry>
	<entry>
		<id>https://redlettermedia.wiki/mediawiki/index.php?title=Module:Sort_title&amp;diff=714&amp;oldid=prev</id>
		<title>en&gt;Ymblanter: Changed protection level for &quot;Module:Sort title&quot;: High-risk Lua module: request at WP:RFPP ([Edit=Require template editor access] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://redlettermedia.wiki/mediawiki/index.php?title=Module:Sort_title&amp;diff=714&amp;oldid=prev"/>
		<updated>2020-05-20T19:15:13Z</updated>

		<summary type="html">&lt;p&gt;Changed protection level for &amp;quot;&lt;a href=&quot;/w/Module:Sort_title&quot; title=&quot;Module:Sort title&quot;&gt;Module:Sort title&lt;/a&gt;&amp;quot;: &lt;a href=&quot;/mediawiki/index.php?title=WP:High-risk_templates&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:High-risk templates (page does not exist)&quot;&gt;High-risk Lua module&lt;/a&gt;: request at &lt;a href=&quot;/mediawiki/index.php?title=WP:RFPP&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:RFPP (page does not exist)&quot;&gt;WP:RFPP&lt;/a&gt; ([Edit=Require template editor access] (indefinite))&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local match = require(&amp;quot;Module:String&amp;quot;)._match&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return a number without commas.&lt;br /&gt;
For example: 4,722 will become 4722.&lt;br /&gt;
--]]&lt;br /&gt;
local function cleanNumberFromCommas(title)&lt;br /&gt;
	return string.gsub(title, &amp;quot;(%d+)(,+)&amp;quot;, &amp;quot;%1&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to check if the word is an article.&lt;br /&gt;
Returns true if it is, false if it isn&amp;#039;t.&lt;br /&gt;
--]]&lt;br /&gt;
local function isFirstWordAnArticle(word)&lt;br /&gt;
	word = string.lower(word)&lt;br /&gt;
	if (word == &amp;quot;a&amp;quot; or word == &amp;quot;an&amp;quot; or word == &amp;quot;the&amp;quot;) then&lt;br /&gt;
		return true&lt;br /&gt;
	else&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return the title without its disambiguation.&lt;br /&gt;
--]]&lt;br /&gt;
local function getTitleWithoutDisambiguation(title, disambiguation)&lt;br /&gt;
	local newTitle = string.gsub(title, &amp;quot;%(&amp;quot;.. disambiguation .. &amp;quot;%)&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	return mw.text.trim(newTitle)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return a title without its first word.&lt;br /&gt;
--]]&lt;br /&gt;
local function getTitleWithoutFirstWord(title)&lt;br /&gt;
	return mw.ustring.gsub(title, &amp;quot;^[^%s]*%s*&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return the first word from a title.&lt;br /&gt;
--]]&lt;br /&gt;
local function getFirstWord(title)&lt;br /&gt;
	return match(title, &amp;quot;^[^%s]*&amp;quot;, 1, 1, false, &amp;quot;&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return a sort key for a specific part.&lt;br /&gt;
--]]&lt;br /&gt;
local function getSortKey(title, firstWord)&lt;br /&gt;
	local sortKey = title&lt;br /&gt;
	if (isFirstWordAnArticle(firstWord) and firstWord ~= title) then&lt;br /&gt;
		title = getTitleWithoutFirstWord(title)&lt;br /&gt;
		sortKey = title .. &amp;quot;, &amp;quot; .. firstWord&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return sortKey&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return the disambiguation sort key.&lt;br /&gt;
--]]&lt;br /&gt;
local function getDisambiguationSortKey(disambiguation)&lt;br /&gt;
	if (disambiguation == &amp;quot;&amp;quot;) then&lt;br /&gt;
		return &amp;quot;&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local firstWord = getFirstWord(disambiguation)&lt;br /&gt;
	local disambiguationSortKey = getSortKey(disambiguation, firstWord)&lt;br /&gt;
	return &amp;quot;(&amp;quot; .. disambiguationSortKey .. &amp;quot;)&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Local function which is used to return the disambiguation from a title.&lt;br /&gt;
--]]&lt;br /&gt;
local function getDisambiguation(title)&lt;br /&gt;
	local disambiguation = match(title, &amp;quot;%s%((.-)%)&amp;quot;, 1, -1, false, &amp;quot;&amp;quot;)&lt;br /&gt;
	if (disambiguation == &amp;quot;&amp;quot;) then&lt;br /&gt;
		return &amp;quot;&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		return disambiguation&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
The main function.&lt;br /&gt;
--]]&lt;br /&gt;
local function _main(title)&lt;br /&gt;
	if (not title) then&lt;br /&gt;
		title = mw.title.getCurrentTitle().text&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local firstWord = getFirstWord(title)&lt;br /&gt;
	local disambiguation = getDisambiguation(title)&lt;br /&gt;
	local disambiguationSortKey = getDisambiguationSortKey(disambiguation)&lt;br /&gt;
	&lt;br /&gt;
	title = getTitleWithoutDisambiguation(title, disambiguation)&lt;br /&gt;
	title = cleanNumberFromCommas(title)&lt;br /&gt;
	title = getSortKey(title, firstWord)&lt;br /&gt;
	&lt;br /&gt;
	local sortKey = title .. &amp;quot; &amp;quot; .. disambiguationSortKey&lt;br /&gt;
	return mw.text.trim(sortKey)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Public function which allows modules to retrieve a sort key.&lt;br /&gt;
--]]&lt;br /&gt;
function p._getSortKey()&lt;br /&gt;
	return _main(nil)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Public function which allows templates to retrieve a sort key.&lt;br /&gt;
--]]&lt;br /&gt;
function p.getSortKey(frame)&lt;br /&gt;
	return _main(nil) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Public function which allows templates to retrieve the sort key inside a DEFAULTSORT.&lt;br /&gt;
--]]&lt;br /&gt;
function p.getDefaultSort(frame)&lt;br /&gt;
	local sortKey = _main(nil)&lt;br /&gt;
	return frame:preprocess{text = &amp;quot;{{DEFAULTSORT:&amp;quot; .. sortKey .. &amp;quot;}}&amp;quot;} &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Public function which is used for testing various names and not the current page name.&lt;br /&gt;
--]]&lt;br /&gt;
function p.testcases(frame)&lt;br /&gt;
	local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return _main(args[1])&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>en&gt;Ymblanter</name></author>
	</entry>
</feed>