Index: trunk/extensions/CategoryMultisort/CategoryMultisort.hooks.php |
— | — | @@ -50,6 +50,10 @@ |
51 | 51 | 'CategoryDefaultMultisort', |
52 | 52 | array( $this, 'parserCategoryDefaultMultisort' ) |
53 | 53 | ); |
| 54 | + $parser->setFunctionHook( |
| 55 | + 'CategoryUseMultisort', |
| 56 | + array( $this, 'parserCategoryUseMultisort' ) |
| 57 | + ); |
54 | 58 | if ( $this->integrate ) { |
55 | 59 | $this->coreCategoryLinkHook = $parser->setLinkHook( |
56 | 60 | NS_CATEGORY, array( $this, 'parserCategoryLink' ) |
— | — | @@ -64,6 +68,7 @@ |
65 | 69 | function onLanguageGetMagic( &$magicWords, $langCode ) { |
66 | 70 | $magicWords['CategoryMultisort'] = array( 0, 'CategoryMultisort' ); |
67 | 71 | $magicWords['CategoryDefaultMultisort'] = array( 0, 'CategoryDefaultMultisort' ); |
| 72 | + $magicWords['CategoryUseMultisort'] = array( 0, 'CategoryUseMultisort' ); |
68 | 73 | return true; |
69 | 74 | } |
70 | 75 | |
— | — | @@ -322,6 +327,12 @@ |
323 | 328 | return ''; |
324 | 329 | } |
325 | 330 | |
| 331 | + function parserCategoryUseMultisort( $parser, $use ) { |
| 332 | + $parser->getOutput()->mCategoryUseMultisort = trim( $use ); |
| 333 | + |
| 334 | + return ''; |
| 335 | + } |
| 336 | + |
326 | 337 | function onCategoryPageView( $categoryArticle ) { |
327 | 338 | global $wgRequest, $wgOut, $wgUser, $wgCategoryMultisortSortkeySettings; |
328 | 339 | |
— | — | @@ -332,8 +343,23 @@ |
333 | 344 | if ( $title->getNamespace() != NS_CATEGORY ) { |
334 | 345 | return true; |
335 | 346 | } else { |
| 347 | + # If a sortkey is designated to be used, don't do more check |
336 | 348 | 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 | + } |
338 | 364 | } |
339 | 365 | |
340 | 366 | $wgOut->addHTML( $this->onCategoryPageView_buildSortkeySelectForm( $skn ) ); |