From 247ecab445dcfee7b75dda887e1e889639c090c7 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 17 Dec 2014 11:18:49 -0800 Subject: [PATCH] SpecialTrackingCategories: Read from the extension registry This demonstrates how we can transition from extensions putting things into the global scope ($wgTrackingCategories) to instead storing them in the extension registry. This will increase the overall performance of the extension registry since it no longer needs to do an array_merge with $wgTrackingCategories. For extensions already converted to using the registry no change is needed as the schema is still the same. Change-Id: Ie0df4c20b123dac784a1c02eb991edc609a911b6 --- includes/DefaultSettings.php | 16 +++--------- includes/parser/ParserOutput.php | 7 +++--- includes/registration/ExtensionProcessor.php | 1 - .../specials/SpecialTrackingCategories.php | 25 ++++++++++++++++++- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index ee462d84ad..6d399cf4d7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3845,20 +3845,12 @@ $wgNamespacesWithSubpages = array( * A message with the suffix '-desc' should be added as a description message * to have extra information on Special:TrackingCategories. * + * @deprecated since 1.25 Extensions should now register tracking categories using + * the new extension registration system. + * * @since 1.23 */ -$wgTrackingCategories = array( - 'index-category', - 'noindex-category', - 'duplicate-args-category', - 'expensive-parserfunction-category', - 'post-expand-template-argument-category', - 'post-expand-template-inclusion-category', - 'hidden-category-category', - 'broken-file-category', - 'node-count-exceeded-category', - 'expansion-depth-exceeded-category', -); +$wgTrackingCategories = array(); /** * Array of namespaces which can be deemed to contain valid "content", as far diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 117e04a122..e9e72beca8 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -489,9 +489,10 @@ class ParserOutput extends CacheTime { * Add a tracking category, getting the title from a system message, * or print a debug message if the title is invalid. * - * Please add any message that you use with this function to - * $wgTrackingCategories. That way they will be listed on - * Special:TrackingCategories. + * Any message used with this function should be registered so it will + * show up on Special:TrackingCategories. Core messages should be added + * to SpecialTrackingCategories::$coreTrackingCategories, and extensions + * should add to "TrackingCategories" in their extension.json. * * @param string $msg Message key * @param Title $title title of the page which is being tracked diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index 459d95b17b..27c8148222 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -11,7 +11,6 @@ class ExtensionProcessor implements Processor { 'ResourceLoaderSources', 'ResourceLoaderLESSVars', 'ResourceLoaderLESSImportPaths', - 'TrackingCategories', 'DefaultUserOptions', 'HiddenPrefs', 'GroupPermissions', diff --git a/includes/specials/SpecialTrackingCategories.php b/includes/specials/SpecialTrackingCategories.php index 7684c05117..d219c99d03 100644 --- a/includes/specials/SpecialTrackingCategories.php +++ b/includes/specials/SpecialTrackingCategories.php @@ -36,6 +36,24 @@ class SpecialTrackingCategories extends SpecialPage { parent::__construct( 'TrackingCategories' ); } + /** + * Tracking categories that exist in core + * + * @var array + */ + private static $coreTrackingCategories = array( + 'index-category', + 'noindex-category', + 'duplicate-args-category', + 'expensive-parserfunction-category', + 'post-expand-template-argument-category', + 'post-expand-template-inclusion-category', + 'hidden-category-category', + 'broken-file-category', + 'node-count-exceeded-category', + 'expansion-depth-exceeded-category', + ); + function execute( $par ) { $this->setHeaders(); $this->outputHeader(); @@ -120,8 +138,13 @@ class SpecialTrackingCategories extends SpecialPage { * @return array Array( 'msg' => Title, 'cats' => Title[] ) */ private function prepareTrackingCategoriesData() { + $categories = array_merge( + self::$coreTrackingCategories, + ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ), + $this->getConfig()->get( 'TrackingCategories' ) // deprecated + ); $trackingCategories = array(); - foreach ( $this->getConfig()->get( 'TrackingCategories' ) as $catMsg ) { + foreach ( $categories as $catMsg ) { /* * Check if the tracking category varies by namespace * Otherwise only pages in the current namespace will be displayed -- 2.20.1