Template:NameSort/doc

NameSort — like its sister template, TitleSort — allows for apparently automatic sorting of pages. It uses the magic word, DEFAULTSORT, to make sure that the page is put into all categories later added to the page on the basis of the person's last name. As such, this template should only be used on templates about people who have at least two names. If there are more than two names, the template will still work, looking only for the final name.

Usage
Usage is super easy. Just type NameSort at the bottom of a page. Then, when you add categories to the page you no longer have to define the sort key for every individual category. It will automatically sort the person by their last name.

Note that this will sort up to the 6th letter of a person's last name, but will sort by the entire last name if the name is 6 letters or shorter. For names that are 7 letters or longer, sorting will continue after having established the first six letters, which still results in proper alphabetisation.

For instance, take the last names, "Smith-Jones" and "Smith-Klein". The template will result in the same sort key for both, Smith-. However, it will still put Smith-Jones ahead of Smith-Klein in the category list, because the MediaWiki software will continue looking for further letters if it finds that two entries have exactly the same sort keys.

Even so, it's fairly unlikely that there will be too many instances of exact sort key matches, since the sort key is 6 letters long.

Demonstration
It's impossible to show the results of this template directly, as it acts in the background of page management.

However, here are some of the ways this template will sort personal names: Russell T Davies --> Davies William Ash --> Ash Juanita Maria Perez Garcia --> Garcia John Ainsworth --> Ainswo Cassandra (actress) --> (actre

Multi-word last names
One kind of name that won't be handled properly by this template are people like Francis De Wolff or Raf De La Torre or even Vincent van Gogh. In these cases, the template will read "Wolff", "Torre" and "Gogh" as the last name, and will file the page under the wrong letter. This can be overcome by some clever #switching coding, but, as of 18:11, April 11, 2011 (UTC), this template doesn't attempt to handle "multi-word" last names like this.

Note, though, that template is absolutely fine with true double-barrelled names, or names that include an apostrophe. So Charlie De'Ath would sort under "De'Ath", as he should.

For the time being, people with multi-word last names will have to have a manual edit of their DEFAULTSORT.

Sorting of people with same last names
Asserted above is the belief that two people with the same last name will sort alphabetically by first name. This does seem to generally be the case, as can be observed with the three Smiths who are in category:Big Finish Doctor Who voice actors. All three are using NameSort to sort them in that category, and they line up neatly: Dot, Hannah, Sheridan.

However, there are other cases where this doesn't seem to be happening, and it's unclear why, as of 23:25, April 11, 2011 (UTC). In time, this will be fixed to definitively look for the first name. For now, though, it's a massive improvement just to have all the Smiths, for example, line up under the letter S.

Disambiguated articles
NameSort does not work correctly in articles whose titles end in a disambiguating element such as "(actor)." The NameSort template uses the last word in the title, which in these cases would be the disambiguating element and lead to the article being alphabetised under the character "(". Such articles presently require a manual implementation of DEFAULTSORT, as in the case of Paul Bennett (actor).

Best practices
Note that even if a person currently exists in a single category, and that category has a sort key defined for it, you should still use this template. The use of DEFAULTSORT should be universal on all pages about people and characters with at least two names. It should be possible for a person to add a category to a page — without having to edit it — and for that page to be automatically sorted properly.

In other words, the default condition of every "person page" should be that it sorts automatically by last name. This template ensures that goal is achieved.

Authorship
Even if there are other templates out there on wikis that do this same thing, this template's original form was developed entirely here at Tardis.

Widespread implementation
This template is being mass-added to pages by bot as of 17:49, April 11, 2011 (UTC). It's also being added to preloadable formats so that it will be automatically placed on new pages, so long as editors use those preloadable formats to create pages. Otherwise, if you create a new page about a person without the preloadable format after about 15 April 2011, you'll have to remember to go back and place this template manually.

Note that implementation will take two runs through both the real world and in-universe categories having to do with individuals. On the first run, the template will be placed on the page. If a DEFAULTSORT key already exists on the page, this will automatically cause a red-lettered warning to appear on the page, saying something to the effect of "you can't have two DEFAULTSORT keys". The second run, which will happen after the first run is complete, will come back through and remove the DEFAULTSORT key, leaving only NameSort behind. The process in total will take anywhere from two to five days from the start time given in the paragraph above.