r71576 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71575‎ | r71576 | r71577 >
Date:19:58, 24 August 2010
Author:nikerabbit
Status:resolved
Tags:
Comment:
Added a hook into MWNamespace::getCanonicalNamespaces() to provide safe way to
define new namespaces in extensions.

Without the hook the list could be initialised too early and some namespaces
would be left undefined. Was causing problems at translatewiki.net.
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Namespace.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -569,6 +569,9 @@
570570 'BookInformation': Before information output on Special:Booksources
571571 $isbn: ISBN to show information for
572572 $output: OutputPage object in use
 573+
 574+'CanonicalNamespaces': For extensions adding their own namespaces or altering the defaults
 575+&$namespaces: Array of namespace numbers with they canonical names
573576
574577 'CategoryPageView': before viewing a categorypage in CategoryPage::view
575578 $catpage: CategoryPage instance
Index: trunk/phase3/includes/Namespace.php
@@ -135,6 +135,7 @@
136136 $namespaces = $wgCanonicalNamespaceNames;
137137 }
138138 $namespaces[NS_MAIN] = '';
 139+ wfRunHooks( 'CanonicalNamespaces', array( &$namespaces ) );
139140 }
140141 return $namespaces;
141142 }
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -21,14 +21,18 @@
2222 define( 'LQT_NEWEST_THREADS', 'nt' );
2323 define( 'LQT_OLDEST_THREADS', 'ot' );
2424
25 -$wgExtensionFunctions[] = 'wgLqtSetupCanonicalNamespces';
 25+if ( version_compare( $wgVersion, '1.17alpha', '>=' ) ) {
 26+ $wgHooks['CanonicalNamespaces'][] = 'wgLqtSetupCanonicalNamespaces';
 27+} else {
 28+ wgLqtSetupCanonicalNamespaces( &$wgExtraNamespaces );
 29+}
2630
27 -function wgLqtSetupCanonicalNamespces() {
28 - global $wgCanonicalNamespaceNames;
29 - $wgCanonicalNamespaceNames[NS_LQT_THREAD] = 'Thread';
30 - $wgCanonicalNamespaceNames[NS_LQT_THREAD_TALK] = 'Thread_talk';
31 - $wgCanonicalNamespaceNames[NS_LQT_SUMMARY] = 'Summary';
32 - $wgCanonicalNamespaceNames[NS_LQT_SUMMARY_TALK] = 'Summary_talk';
 31+function wgLqtSetupCanonicalNamespaces( &$list ) {
 32+ $list[NS_LQT_THREAD] = 'Thread';
 33+ $list[NS_LQT_THREAD_TALK] = 'Thread_talk';
 34+ $list[NS_LQT_SUMMARY] = 'Summary';
 35+ $list[NS_LQT_SUMMARY_TALK] = 'Summary_talk';
 36+ return true;
3337 }
3438
3539 // Localisation
Index: trunk/extensions/Translate/Translate.php
@@ -49,6 +49,7 @@
5050
5151 // Register initialization hook
5252 $wgExtensionFunctions[] = 'efTranslateInit';
 53+$wgHooks['CanonicalNamespaces'][] = 'efTranslateNamespaces';
5354
5455 // Register special pages into MediaWiki
5556 $wgSpecialPages['Translate'] = 'SpecialTranslate';
@@ -401,6 +402,12 @@
402403
403404 # Startup code
404405
 406+function efTranslateNamespaces( &$list ) {
 407+ $list[NS_TRANSLATIONS] = 'Translations';
 408+ $list[NS_TRANSLATIONS_TALK] = 'Translations_talk';
 409+ return true;
 410+}
 411+
405412 /**
406413 * Initialises the extension.
407414 * @private
@@ -459,24 +466,19 @@
460467 $wgJobClasses['RenderJob'] = 'RenderJob';
461468 $wgJobClasses['MoveJob'] = 'MoveJob';
462469
463 - /**
464 - * Namespaces
465 - */
466 - global $wgPageTranslationNamespace, $wgCanonicalNamespaceNames;
 470+ // Namespaces
 471+ global $wgPageTranslationNamespace, $wgExtraNamespaces;
467472 global $wgNamespacesWithSubpages, $wgNamespaceProtection;
468 - global $wgTranslateMessageNamespaces;
 473+ global $wgTranslateMessageNamespaces, $wgVersion;
469474
470 - /**
471 - * Defines for nice usage
472 - */
 475+ // Define constants for more readable core
473476 define ( 'NS_TRANSLATIONS', $wgPageTranslationNamespace );
474477 define ( 'NS_TRANSLATIONS_TALK', $wgPageTranslationNamespace + 1 );
475478
476 - /**
477 - * Register them as namespaces
478 - */
479 - $wgCanonicalNamespaceNames[NS_TRANSLATIONS] = 'Translations';
480 - $wgCanonicalNamespaceNames[NS_TRANSLATIONS_TALK] = 'Translations_talk';
 479+ if ( version_compare( $wgVersion, '1.17alpha', '<' ) ) {
 480+ efTranslateNamespaces( &$wgExtraNamespaces );
 481+ }
 482+
481483 $wgNamespacesWithSubpages[NS_TRANSLATIONS] = true;
482484 $wgNamespacesWithSubpages[NS_TRANSLATIONS_TALK] = true;
483485

Follow-up revisions

RevisionCommit summaryAuthorDate
r71578Someone made a typo in r71576nikerabbit20:12, 24 August 2010
r71867Fix bug introduced in untested r71576. getNamespaces() did not use getCanonic...werdna03:03, 29 August 2010

Status & tagging log