r18629 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r18628‎ | r18629 | r18630 >
Date:10:39, 29 December 2006
Author:robchurch
Status:old
Tags:
Comment:
(bug 5908) Allow overriding the default category sort key for all items on a page using {{DEFAULTSORT}}
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -100,7 +100,7 @@
101101 var $mOutput, $mAutonumber, $mDTopen, $mStripState;
102102 var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
103103 var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
104 - var $mIncludeSizes;
 104+ var $mIncludeSizes, $mDefaultSort;
105105 var $mTemplates, // cache of already loaded templates, avoids
106106 // multiple SQL queries for the same string
107107 $mTemplatePath; // stores an unsorted hash of all the templates already loaded
@@ -167,6 +167,7 @@
168168 $this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH );
169169 $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH );
170170 $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) );
 171+ $this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH );
171172
172173 if ( $wgAllowDisplayTitle ) {
173174 $this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
@@ -231,6 +232,7 @@
232233 'post-expand' => 0,
233234 'arg' => 0
234235 );
 236+ $this->mDefaultSort = false;
235237
236238 wfRunHooks( 'ParserClearState', array( &$this ) );
237239 wfProfileOut( __METHOD__ );
@@ -1750,11 +1752,7 @@
17511753 $s = rtrim($s . "\n"); # bug 87
17521754
17531755 if ( $wasblank ) {
1754 - if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1755 - $sortkey = $this->mTitle->getText();
1756 - } else {
1757 - $sortkey = $this->mTitle->getPrefixedText();
1758 - }
 1756+ $sortkey = $this->getDefaultSort();
17591757 } else {
17601758 $sortkey = $text;
17611759 }
@@ -4667,6 +4665,32 @@
46684666 }
46694667 return $this->mRevisionTimestamp;
46704668 }
 4669+
 4670+ /**
 4671+ * Mutator for $mDefaultSort
 4672+ *
 4673+ * @param $sort New value
 4674+ */
 4675+ public function setDefaultSort( $sort ) {
 4676+ $this->mDefaultSort = $sort;
 4677+ }
 4678+
 4679+ /**
 4680+ * Accessor for $mDefaultSort
 4681+ * Will use the title/prefixed title if none is set
 4682+ *
 4683+ * @return string
 4684+ */
 4685+ public function getDefaultSort() {
 4686+ if( $this->mDefaultSort !== false ) {
 4687+ return $this->mDefaultSort;
 4688+ } else {
 4689+ return $this->mTitle->getNamespace() == NS_CATEGORY
 4690+ ? $this->mTitle->getText()
 4691+ : $this->mTitle->getPrefixedText();
 4692+ }
 4693+ }
 4694+
46714695 }
46724696
46734697 /**
Index: trunk/phase3/includes/MagicWord.php
@@ -101,6 +101,7 @@
102102 'contentlanguage',
103103 'pagesinnamespace',
104104 'numberofadmins',
 105+ 'defaultsort',
105106 );
106107
107108 static public $mObjects = array();
Index: trunk/phase3/includes/CoreParserFunctions.php
@@ -180,6 +180,14 @@
181181 return wfMsgForContent( 'nosuchspecialpage' );
182182 }
183183 }
 184+
 185+ public static function defaultsort( $parser, $text ) {
 186+ $text = trim( $text );
 187+ if( strlen( $text ) > 0 )
 188+ $parser->setDefaultSort( $text );
 189+ return '';
 190+ }
 191+
184192 }
185193
186194 ?>
Index: trunk/phase3/RELEASE-NOTES
@@ -423,8 +423,9 @@
424424 * (bug 8401) Fix regression in SORBS lookup for some DNS setups
425425 * Use raw file descriptor in posix_isatty() check to avoid warning on
426426 Linux systems with at least some versions of PHP
 427+* (bug 5908) Allow overriding the default category sort key for all items on
 428+ a page using {{DEFAULTSORT}}
427429
428 -
429430 == Languages updated ==
430431
431432 * Basque (eu)
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -332,6 +332,7 @@
333333 'padleft' => array( 0, 'PADLEFT' ),
334334 'padright' => array( 0, 'PADRIGHT' ),
335335 'special' => array( 0, 'special', ),
 336+ 'defaultsort' => array( 1, 'DEFAULTSORT:' ),
336337 );
337338
338339 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r22839(bug 5908) Add "DEFAULTSORTKEY" and "DEFAULTCATEGORYSORT" aliases for "DEFAUL...robchurch15:16, 8 June 2007
r22857Merged revisions 22811-22855 via svnmerge from...david00:48, 9 June 2007