r68060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68059‎ | r68060 | r68061 >
Date:08:37, 15 June 2010
Author:liangent
Status:deferred
Tags:
Comment:
New {{#CategoryUseMultisort: }} parser function

This parser function specifies sortkey used when a &sortkey=
parameter doesn't exist. User preference is ignored in this case.
Modified paths:
  • /trunk/extensions/CategoryMultisort/CategoryMultisort.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryMultisort/CategoryMultisort.hooks.php
@@ -50,6 +50,10 @@
5151 'CategoryDefaultMultisort',
5252 array( $this, 'parserCategoryDefaultMultisort' )
5353 );
 54+ $parser->setFunctionHook(
 55+ 'CategoryUseMultisort',
 56+ array( $this, 'parserCategoryUseMultisort' )
 57+ );
5458 if ( $this->integrate ) {
5559 $this->coreCategoryLinkHook = $parser->setLinkHook(
5660 NS_CATEGORY, array( $this, 'parserCategoryLink' )
@@ -64,6 +68,7 @@
6569 function onLanguageGetMagic( &$magicWords, $langCode ) {
6670 $magicWords['CategoryMultisort'] = array( 0, 'CategoryMultisort' );
6771 $magicWords['CategoryDefaultMultisort'] = array( 0, 'CategoryDefaultMultisort' );
 72+ $magicWords['CategoryUseMultisort'] = array( 0, 'CategoryUseMultisort' );
6873 return true;
6974 }
7075
@@ -322,6 +327,12 @@
323328 return '';
324329 }
325330
 331+ function parserCategoryUseMultisort( $parser, $use ) {
 332+ $parser->getOutput()->mCategoryUseMultisort = trim( $use );
 333+
 334+ return '';
 335+ }
 336+
326337 function onCategoryPageView( $categoryArticle ) {
327338 global $wgRequest, $wgOut, $wgUser, $wgCategoryMultisortSortkeySettings;
328339
@@ -332,8 +343,23 @@
333344 if ( $title->getNamespace() != NS_CATEGORY ) {
334345 return true;
335346 } else {
 347+ # If a sortkey is designated to be used, don't do more check
336348 if ( is_null( $skn = $wgRequest->getVal( 'sortkey' ) ) ) {
337 - $skn = $wgUser->getOption( 'categorymultisort-sortkey' );
 349+ # Check whether a sortkey is set for this category
 350+
 351+ $parsetOutput = $categoryArticle->getParserOutput();
 352+
 353+ # If a corresponding property exists, and
 354+ # (1) such property is a blank string
 355+ # or (2) such property is allowed by $wgCategoryMultisortSortkeySettings
 356+ # then use it. Otherwise, use user preference.
 357+ if ( !( isset( $parsetOutput->mCategoryUseMultisort )
 358+ && ( !( $skn = $parsetOutput->mCategoryUseMultisort )
 359+ || array_key_exists( $skn, $wgCategoryMultisortSortkeySettings )
 360+ )
 361+ ) ) {
 362+ $skn = $wgUser->getOption( 'categorymultisort-sortkey' );
 363+ }
338364 }
339365
340366 $wgOut->addHTML( $this->onCategoryPageView_buildSortkeySelectForm( $skn ) );

Status & tagging log