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
23 * This class performs some operations related to tracking categories, such as creating
24 * a list of all such categories.
26 class TrackingCategories
{
31 * Tracking categories that exist in core
35 private static $coreTrackingCategories = [
38 'duplicate-args-category',
39 'expensive-parserfunction-category',
40 'post-expand-template-argument-category',
41 'post-expand-template-inclusion-category',
42 'hidden-category-category',
43 'broken-file-category',
44 'node-count-exceeded-category',
45 'expansion-depth-exceeded-category',
46 'restricted-displaytitle-ignored',
47 'deprecated-self-close-category',
51 * @param Config $config
53 public function __construct( Config
$config ) {
54 $this->config
= $config;
58 * Read the global and extract title objects from the corresponding messages
59 * @return array Array( 'msg' => Title, 'cats' => Title[] )
61 public function getTrackingCategories() {
62 $categories = array_merge(
63 self
::$coreTrackingCategories,
64 ExtensionRegistry
::getInstance()->getAttribute( 'TrackingCategories' ),
65 $this->config
->get( 'TrackingCategories' ) // deprecated
68 // Only show magic link tracking categories if they are enabled
69 $enableMagicLinks = $this->config
->get( 'EnableMagicLinks' );
70 if ( $enableMagicLinks['ISBN'] ) {
71 $categories[] = 'magiclink-tracking-isbn';
73 if ( $enableMagicLinks['RFC'] ) {
74 $categories[] = 'magiclink-tracking-rfc';
76 if ( $enableMagicLinks['PMID'] ) {
77 $categories[] = 'magiclink-tracking-pmid';
80 $trackingCategories = [];
81 foreach ( $categories as $catMsg ) {
83 * Check if the tracking category varies by namespace
84 * Otherwise only pages in the current namespace will be displayed
85 * If it does vary, show pages considering all namespaces
87 $msgObj = wfMessage( $catMsg )->inContentLanguage();
89 $catMsgTitle = Title
::makeTitleSafe( NS_MEDIAWIKI
, $catMsg );
90 if ( !$catMsgTitle ) {
94 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
95 // False positives are ok, this is just an efficiency shortcut
96 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
97 $ns = MWNamespace
::getValidNamespaces();
98 foreach ( $ns as $namesp ) {
99 $tempTitle = Title
::makeTitleSafe( $namesp, $catMsg );
103 $catName = $msgObj->title( $tempTitle )->text();
104 # Allow tracking categories to be disabled by setting them to "-"
105 if ( $catName !== '-' ) {
106 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
108 $allCats[] = $catTitle;
113 $catName = $msgObj->text();
114 # Allow tracking categories to be disabled by setting them to "-"
115 if ( $catName !== '-' ) {
116 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
118 $allCats[] = $catTitle;
122 $trackingCategories[$catMsg] = [
124 'msg' => $catMsgTitle,
128 return $trackingCategories;