3 * Implements Special:TrackingCategories
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that displays list of tracking categories
26 * Tracking categories allow pages with certain characteristics to be tracked.
27 * It works by adding any such page to a category automatically.
28 * Category is specified by the tracking category's system message.
30 * @ingroup SpecialPage
34 class SpecialTrackingCategories
extends SpecialPage
{
35 function __construct() {
36 parent
::__construct( 'TrackingCategories' );
40 * Tracking categories that exist in core
44 private static $coreTrackingCategories = [
47 'duplicate-args-category',
48 'expensive-parserfunction-category',
49 'post-expand-template-argument-category',
50 'post-expand-template-inclusion-category',
51 'hidden-category-category',
52 'broken-file-category',
53 'node-count-exceeded-category',
54 'expansion-depth-exceeded-category',
55 'restricted-displaytitle-ignored',
58 function execute( $par ) {
60 $this->outputHeader();
61 $this->getOutput()->allowClickjacking();
62 $this->getOutput()->addHTML(
63 Html
::openElement( 'table', [ 'class' => 'mw-datatable',
64 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
67 $this->msg( 'trackingcategories-msg' )->escaped() . "
70 $this->msg( 'trackingcategories-name' )->escaped() .
73 $this->msg( 'trackingcategories-desc' )->escaped() . "
78 $trackingCategories = $this->prepareTrackingCategoriesData();
80 $batch = new LinkBatch();
81 foreach ( $trackingCategories as $catMsg => $data ) {
82 $batch->addObj( $data['msg'] );
83 foreach ( $data['cats'] as $catTitle ) {
84 $batch->addObj( $catTitle );
89 foreach ( $trackingCategories as $catMsg => $data ) {
91 $catDesc = $catMsg . '-desc';
93 $catMsgTitleText = Linker
::link(
95 htmlspecialchars( $catMsg )
98 foreach ( $data['cats'] as $catTitle ) {
99 $catTitleText = Linker
::link(
101 htmlspecialchars( $catTitle->getText() )
103 $allMsgs[] = $catTitleText;
106 # Extra message, when no category was found
107 if ( !count( $allMsgs ) ) {
108 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
112 * Show category description if it exists as a system message
113 * as category-name-desc
115 $descMsg = $this->msg( $catDesc );
116 if ( $descMsg->isBlank() ) {
117 $descMsg = $this->msg( 'trackingcategories-nodesc' );
120 $this->getOutput()->addHTML(
121 Html
::openElement( 'tr' ) .
122 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
123 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
124 Html
::closeElement( 'td' ) .
125 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
127 Html
::closeElement( 'td' ) .
128 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
130 Html
::closeElement( 'td' ) .
131 Html
::closeElement( 'tr' )
134 $this->getOutput()->addHTML( Html
::closeElement( 'table' ) );
138 * Read the global and extract title objects from the corresponding messages
139 * @return array Array( 'msg' => Title, 'cats' => Title[] )
141 private function prepareTrackingCategoriesData() {
142 $categories = array_merge(
143 self
::$coreTrackingCategories,
144 ExtensionRegistry
::getInstance()->getAttribute( 'TrackingCategories' ),
145 $this->getConfig()->get( 'TrackingCategories' ) // deprecated
147 $trackingCategories = [];
148 foreach ( $categories as $catMsg ) {
150 * Check if the tracking category varies by namespace
151 * Otherwise only pages in the current namespace will be displayed
152 * If it does vary, show pages considering all namespaces
154 $msgObj = $this->msg( $catMsg )->inContentLanguage();
156 $catMsgTitle = Title
::makeTitleSafe( NS_MEDIAWIKI
, $catMsg );
157 if ( !$catMsgTitle ) {
161 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
162 // False positives are ok, this is just an efficiency shortcut
163 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
164 $ns = MWNamespace
::getValidNamespaces();
165 foreach ( $ns as $namesp ) {
166 $tempTitle = Title
::makeTitleSafe( $namesp, $catMsg );
170 $catName = $msgObj->title( $tempTitle )->text();
171 # Allow tracking categories to be disabled by setting them to "-"
172 if ( $catName !== '-' ) {
173 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
175 $allCats[] = $catTitle;
180 $catName = $msgObj->text();
181 # Allow tracking categories to be disabled by setting them to "-"
182 if ( $catName !== '-' ) {
183 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
185 $allCats[] = $catTitle;
189 $trackingCategories[$catMsg] = [
191 'msg' => $catMsgTitle,
195 return $trackingCategories;
198 protected function getGroupName() {