From 71c77571110b601c14155cb63ec4bd54ad5aecad Mon Sep 17 00:00:00 2001 From: Rob Church Date: Fri, 29 Dec 2006 10:39:35 +0000 Subject: [PATCH] (bug 5908) Allow overriding the default category sort key for all items on a page using {{DEFAULTSORT}} --- RELEASE-NOTES | 3 ++- includes/CoreParserFunctions.php | 8 +++++++ includes/MagicWord.php | 1 + includes/Parser.php | 36 +++++++++++++++++++++++++------ languages/messages/MessagesEn.php | 1 + 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3aa48944db..4afa1647e7 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -423,7 +423,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 8401) Fix regression in SORBS lookup for some DNS setups * Use raw file descriptor in posix_isatty() check to avoid warning on Linux systems with at least some versions of PHP - +* (bug 5908) Allow overriding the default category sort key for all items on + a page using {{DEFAULTSORT}} == Languages updated == diff --git a/includes/CoreParserFunctions.php b/includes/CoreParserFunctions.php index 7974893ede..402a3ba9f2 100644 --- a/includes/CoreParserFunctions.php +++ b/includes/CoreParserFunctions.php @@ -180,6 +180,14 @@ class CoreParserFunctions { return wfMsgForContent( 'nosuchspecialpage' ); } } + + public static function defaultsort( $parser, $text ) { + $text = trim( $text ); + if( strlen( $text ) > 0 ) + $parser->setDefaultSort( $text ); + return ''; + } + } ?> diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 0b6065d049..60bfd0f4c5 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -101,6 +101,7 @@ class MagicWord { 'contentlanguage', 'pagesinnamespace', 'numberofadmins', + 'defaultsort', ); static public $mObjects = array(); diff --git a/includes/Parser.php b/includes/Parser.php index 5ea06898a5..299c221296 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -100,7 +100,7 @@ class Parser var $mOutput, $mAutonumber, $mDTopen, $mStripState; var $mIncludeCount, $mArgStack, $mLastSection, $mInPre; var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix; - var $mIncludeSizes; + var $mIncludeSizes, $mDefaultSort; var $mTemplates, // cache of already loaded templates, avoids // multiple SQL queries for the same string $mTemplatePath; // stores an unsorted hash of all the templates already loaded @@ -167,6 +167,7 @@ class Parser $this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH ); $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH ); $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) ); + $this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH ); if ( $wgAllowDisplayTitle ) { $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH ); @@ -231,6 +232,7 @@ class Parser 'post-expand' => 0, 'arg' => 0 ); + $this->mDefaultSort = false; wfRunHooks( 'ParserClearState', array( &$this ) ); wfProfileOut( __METHOD__ ); @@ -1750,11 +1752,7 @@ class Parser $s = rtrim($s . "\n"); # bug 87 if ( $wasblank ) { - if ( $this->mTitle->getNamespace() == NS_CATEGORY ) { - $sortkey = $this->mTitle->getText(); - } else { - $sortkey = $this->mTitle->getPrefixedText(); - } + $sortkey = $this->getDefaultSort(); } else { $sortkey = $text; } @@ -4667,6 +4665,32 @@ class Parser } return $this->mRevisionTimestamp; } + + /** + * Mutator for $mDefaultSort + * + * @param $sort New value + */ + public function setDefaultSort( $sort ) { + $this->mDefaultSort = $sort; + } + + /** + * Accessor for $mDefaultSort + * Will use the title/prefixed title if none is set + * + * @return string + */ + public function getDefaultSort() { + if( $this->mDefaultSort !== false ) { + return $this->mDefaultSort; + } else { + return $this->mTitle->getNamespace() == NS_CATEGORY + ? $this->mTitle->getText() + : $this->mTitle->getPrefixedText(); + } + } + } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 711b0e4593..f597086613 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -332,6 +332,7 @@ $magicWords = array( 'padleft' => array( 0, 'PADLEFT' ), 'padright' => array( 0, 'PADRIGHT' ), 'special' => array( 0, 'special', ), + 'defaultsort' => array( 1, 'DEFAULTSORT:' ), ); /** -- 2.20.1