Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Sort title
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local match = require("Module:String")._match local p = {} --[[ Local function which is used to return a number without commas. For example: 4,722 will become 4722. --]] local function cleanNumberFromCommas(title) return string.gsub(title, "(%d+)(,+)", "%1") end --[[ Local function which is used to check if the word is an article. Returns true if it is, false if it isn't. --]] local function isFirstWordAnArticle(word) word = string.lower(word) if (word == "a" or word == "an" or word == "the") then return true else return false end end --[[ Local function which is used to return the title without its disambiguation. --]] local function getTitleWithoutDisambiguation(title, disambiguation) local newTitle = string.gsub(title, "%(".. disambiguation .. "%)", "") return mw.text.trim(newTitle) end --[[ Local function which is used to return a title without its first word. --]] local function getTitleWithoutFirstWord(title) return mw.ustring.gsub(title, "^[^%s]*%s*", "") end --[[ Local function which is used to return the first word from a title. --]] local function getFirstWord(title) return match(title, "^[^%s]*", 1, 1, false, "") end --[[ Local function which is used to return a sort key for a specific part. --]] local function getSortKey(title, firstWord) local sortKey = title if (isFirstWordAnArticle(firstWord) and firstWord ~= title) then title = getTitleWithoutFirstWord(title) sortKey = title .. ", " .. firstWord end return sortKey end --[[ Local function which is used to return the disambiguation sort key. --]] local function getDisambiguationSortKey(disambiguation) if (disambiguation == "") then return "" end local firstWord = getFirstWord(disambiguation) local disambiguationSortKey = getSortKey(disambiguation, firstWord) return "(" .. disambiguationSortKey .. ")" end --[[ Local function which is used to return the disambiguation from a title. --]] local function getDisambiguation(title) local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "") if (disambiguation == "") then return "" else return disambiguation end end --[[ The main function. --]] local function _main(title) if (not title) then title = mw.title.getCurrentTitle().text end local firstWord = getFirstWord(title) local disambiguation = getDisambiguation(title) local disambiguationSortKey = getDisambiguationSortKey(disambiguation) title = getTitleWithoutDisambiguation(title, disambiguation) title = cleanNumberFromCommas(title) title = getSortKey(title, firstWord) local sortKey = title .. " " .. disambiguationSortKey return mw.text.trim(sortKey) end --[[ Public function which allows modules to retrieve a sort key. --]] function p._getSortKey() return _main(nil) end --[[ Public function which allows templates to retrieve a sort key. --]] function p.getSortKey(frame) return _main(nil) end --[[ Public function which allows templates to retrieve the sort key inside a DEFAULTSORT. --]] function p.getDefaultSort(frame) local sortKey = _main(nil) return frame:preprocess{text = "{{DEFAULTSORT:" .. sortKey .. "}}"} end --[[ Public function which is used for testing various names and not the current page name. --]] function p.testcases(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return _main(args[1]) end return p
Summary:
Please note that all contributions to Red Letter Media Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
RLMWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:High-use
(
edit
)
Template:Lua
(
edit
)
Template:Mlx
(
edit
)
Template:Module link expanded
(
edit
)
Module:Arguments
(
edit
)
Module:High-use
(
edit
)
Module:List
(
edit
)
Module:Lua banner
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Separated entries
(
edit
)
Module:Sort title/doc
(
edit
)
Module:TableTools
(
edit
)
Module:Transclusion count
(
edit
)
Module:Transclusion count/data/S
(
edit
)
Module:Yesno
(
edit
)
Toggle limited content width