Manual:Hooks/GetDefaultSortkey

GetDefaultSortkey
Available from version 1.18.0 (r91510, codereview)
Called when determining what the default sortkey would be for a page
Define function:
public static function onGetDefaultSortkey( $title, &$sortkey ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"GetDefaultSortkey": "MediaWiki\\Extension\\MyExtension\\Hooks::onGetDefaultSortkey"
	}
}
Called from: File(s): Title.php
Interface: GetDefaultSortkeyHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:GetDefaultSortkey extensions.


Details edit

  • $title: A Title object representing the page in question
  • &$sortkey: What sortkey to use unless a custom one is specified. If a custom sortkey was specified, this value would be used as a tie breaker for the specified sortkey.

Notes edit

After adding an extension that uses this hook, you should run php updateCollation.php --force to re-sort any existing category entries. What the default sortkey for a page is, is not stored in the DB, so things won't get updated until the category is removed and re-added to a page, or the maintenance script is run.

This should not use any information that could change other than the title object, because such sortkeys are only re-calculated on page moves or if the category is removed and re-added.