MediaWiki REL1_37
TrackingCategories.php
Go to the documentation of this file.
1<?php
23
31 private $config;
32
38 private static $coreTrackingCategories = [
39 'broken-file-category',
40 'duplicate-args-category',
41 'expansion-depth-exceeded-category',
42 'expensive-parserfunction-category',
43 'hidden-category-category',
44 'index-category',
45 'node-count-exceeded-category',
46 'noindex-category',
47 'nonnumeric-formatnum',
48 'post-expand-template-argument-category',
49 'post-expand-template-inclusion-category',
50 'restricted-displaytitle-ignored',
51 'template-equals-category',
52 'template-loop-category',
53 ];
54
58 public function __construct( Config $config ) {
59 $this->config = $config;
60 }
61
67 public function getTrackingCategories() {
68 $categories = array_merge(
69 self::$coreTrackingCategories,
70 ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
71 $this->config->get( 'TrackingCategories' ) // deprecated
72 );
73
74 // Only show magic link tracking categories if they are enabled
75 $enableMagicLinks = $this->config->get( 'EnableMagicLinks' );
76 if ( $enableMagicLinks['ISBN'] ) {
77 $categories[] = 'magiclink-tracking-isbn';
78 }
79 if ( $enableMagicLinks['RFC'] ) {
80 $categories[] = 'magiclink-tracking-rfc';
81 }
82 if ( $enableMagicLinks['PMID'] ) {
83 $categories[] = 'magiclink-tracking-pmid';
84 }
85
86 $trackingCategories = [];
87 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
88 foreach ( $categories as $catMsg ) {
89 /*
90 * Check if the tracking category varies by namespace
91 * Otherwise only pages in the current namespace will be displayed
92 * If it does vary, show pages considering all namespaces
93 */
94 $msgObj = wfMessage( $catMsg )->inContentLanguage();
95 $allCats = [];
96 $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
97 if ( !$catMsgTitle ) {
98 continue;
99 }
100
101 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
102 // False positives are ok, this is just an efficiency shortcut
103 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
104 $ns = $nsInfo->getValidNamespaces();
105 foreach ( $ns as $namesp ) {
106 $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
107 if ( !$tempTitle ) {
108 continue;
109 }
110 $catName = $msgObj->page( $tempTitle )->text();
111 # Allow tracking categories to be disabled by setting them to "-"
112 if ( $catName !== '-' ) {
113 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
114 if ( $catTitle ) {
115 $allCats[] = $catTitle;
116 }
117 }
118 }
119 } else {
120 $catName = $msgObj->text();
121 # Allow tracking categories to be disabled by setting them to "-"
122 if ( $catName !== '-' ) {
123 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
124 if ( $catTitle ) {
125 $allCats[] = $catTitle;
126 }
127 }
128 }
129 $trackingCategories[$catMsg] = [
130 'cats' => $allCats,
131 'msg' => $catMsgTitle,
132 ];
133 }
134
135 return $trackingCategories;
136 }
137}
const NS_MEDIAWIKI
Definition Defines.php:72
const NS_CATEGORY
Definition Defines.php:78
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This class performs some operations related to tracking categories, such as creating a list of all su...
getTrackingCategories()
Read the global and extract title objects from the corresponding messages.
__construct(Config $config)
static array $coreTrackingCategories
Tracking categories that exist in core.
Interface for configuration instances.
Definition Config.php:30