<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/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://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ASort_title"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Sort_title&amp;action=history"/>
	<updated>2026-04-29T09:39:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Sort_title&amp;diff=479507&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Sort_title&amp;diff=479507&amp;oldid=prev"/>
		<updated>2021-07-16T06:05:17Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&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'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('Module:Arguments').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>Zoran</name></author>
	</entry>
</feed>