3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 use MediaWiki\MediaWikiServices
;
25 * This class performs some operations related to tracking categories, such as creating
26 * a list of all such categories.
29 class TrackingCategories
{
34 * Tracking categories that exist in core
38 private static $coreTrackingCategories = [
41 'duplicate-args-category',
42 'expensive-parserfunction-category',
43 'post-expand-template-argument-category',
44 'post-expand-template-inclusion-category',
45 'hidden-category-category',
46 'broken-file-category',
47 'node-count-exceeded-category',
48 'expansion-depth-exceeded-category',
49 'restricted-displaytitle-ignored',
50 'deprecated-self-close-category',
51 'template-loop-category',
55 * @param Config $config
57 public function __construct( Config
$config ) {
58 $this->config
= $config;
62 * Read the global and extract title objects from the corresponding messages
63 * @return array Array( 'msg' => Title, 'cats' => Title[] )
65 public function getTrackingCategories() {
66 $categories = array_merge(
67 self
::$coreTrackingCategories,
68 ExtensionRegistry
::getInstance()->getAttribute( 'TrackingCategories' ),
69 $this->config
->get( 'TrackingCategories' ) // deprecated
72 // Only show magic link tracking categories if they are enabled
73 $enableMagicLinks = $this->config
->get( 'EnableMagicLinks' );
74 if ( $enableMagicLinks['ISBN'] ) {
75 $categories[] = 'magiclink-tracking-isbn';
77 if ( $enableMagicLinks['RFC'] ) {
78 $categories[] = 'magiclink-tracking-rfc';
80 if ( $enableMagicLinks['PMID'] ) {
81 $categories[] = 'magiclink-tracking-pmid';
84 $trackingCategories = [];
85 $nsInfo = MediaWikiServices
::getInstance()->getNamespaceInfo();
86 foreach ( $categories as $catMsg ) {
88 * Check if the tracking category varies by namespace
89 * Otherwise only pages in the current namespace will be displayed
90 * If it does vary, show pages considering all namespaces
92 $msgObj = wfMessage( $catMsg )->inContentLanguage();
94 $catMsgTitle = Title
::makeTitleSafe( NS_MEDIAWIKI
, $catMsg );
95 if ( !$catMsgTitle ) {
99 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
100 // False positives are ok, this is just an efficiency shortcut
101 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
102 $ns = $nsInfo->getValidNamespaces();
103 foreach ( $ns as $namesp ) {
104 $tempTitle = Title
::makeTitleSafe( $namesp, $catMsg );
108 $catName = $msgObj->title( $tempTitle )->text();
109 # Allow tracking categories to be disabled by setting them to "-"
110 if ( $catName !== '-' ) {
111 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
113 $allCats[] = $catTitle;
118 $catName = $msgObj->text();
119 # Allow tracking categories to be disabled by setting them to "-"
120 if ( $catName !== '-' ) {
121 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
123 $allCats[] = $catTitle;
127 $trackingCategories[$catMsg] = [
129 'msg' => $catMsgTitle,
133 return $trackingCategories;