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',
56 'deprecated-self-close-category',
59 function execute( $par ) {
61 $this->outputHeader();
62 $this->getOutput()->allowClickjacking();
63 $this->getOutput()->addHTML(
64 Html
::openElement( 'table', [ 'class' => 'mw-datatable',
65 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
68 $this->msg( 'trackingcategories-msg' )->escaped() . "
71 $this->msg( 'trackingcategories-name' )->escaped() .
74 $this->msg( 'trackingcategories-desc' )->escaped() . "
79 $trackingCategories = $this->prepareTrackingCategoriesData();
81 $batch = new LinkBatch();
82 foreach ( $trackingCategories as $catMsg => $data ) {
83 $batch->addObj( $data['msg'] );
84 foreach ( $data['cats'] as $catTitle ) {
85 $batch->addObj( $catTitle );
90 Hooks
::run( 'SpecialTrackingCategories::preprocess', [ $this, $trackingCategories ] );
92 foreach ( $trackingCategories as $catMsg => $data ) {
94 $catDesc = $catMsg . '-desc';
96 $catMsgTitleText = Linker
::link(
98 htmlspecialchars( $catMsg )
101 foreach ( $data['cats'] as $catTitle ) {
102 $html = Linker
::link(
104 htmlspecialchars( $catTitle->getText() )
107 Hooks
::run( 'SpecialTrackingCategories::generateCatLink',
108 [ $this, $catTitle, &$html ] );
113 # Extra message, when no category was found
114 if ( !count( $allMsgs ) ) {
115 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
119 * Show category description if it exists as a system message
120 * as category-name-desc
122 $descMsg = $this->msg( $catDesc );
123 if ( $descMsg->isBlank() ) {
124 $descMsg = $this->msg( 'trackingcategories-nodesc' );
127 $this->getOutput()->addHTML(
128 Html
::openElement( 'tr' ) .
129 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
130 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
131 Html
::closeElement( 'td' ) .
132 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
134 Html
::closeElement( 'td' ) .
135 Html
::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
137 Html
::closeElement( 'td' ) .
138 Html
::closeElement( 'tr' )
141 $this->getOutput()->addHTML( Html
::closeElement( 'table' ) );
145 * Read the global and extract title objects from the corresponding messages
146 * @return array Array( 'msg' => Title, 'cats' => Title[] )
148 private function prepareTrackingCategoriesData() {
149 $categories = array_merge(
150 self
::$coreTrackingCategories,
151 ExtensionRegistry
::getInstance()->getAttribute( 'TrackingCategories' ),
152 $this->getConfig()->get( 'TrackingCategories' ) // deprecated
155 // Only show magic link tracking categories if they are enabled
156 $enableMagicLinks = $this->getConfig()->get( 'EnableMagicLinks' );
157 if ( $enableMagicLinks['ISBN'] ) {
158 $categories[] = 'magiclink-tracking-isbn';
160 if ( $enableMagicLinks['RFC'] ) {
161 $categories[] = 'magiclink-tracking-rfc';
163 if ( $enableMagicLinks['PMID'] ) {
164 $categories[] = 'magiclink-tracking-pmid';
167 $trackingCategories = [];
168 foreach ( $categories as $catMsg ) {
170 * Check if the tracking category varies by namespace
171 * Otherwise only pages in the current namespace will be displayed
172 * If it does vary, show pages considering all namespaces
174 $msgObj = $this->msg( $catMsg )->inContentLanguage();
176 $catMsgTitle = Title
::makeTitleSafe( NS_MEDIAWIKI
, $catMsg );
177 if ( !$catMsgTitle ) {
181 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
182 // False positives are ok, this is just an efficiency shortcut
183 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
184 $ns = MWNamespace
::getValidNamespaces();
185 foreach ( $ns as $namesp ) {
186 $tempTitle = Title
::makeTitleSafe( $namesp, $catMsg );
190 $catName = $msgObj->title( $tempTitle )->text();
191 # Allow tracking categories to be disabled by setting them to "-"
192 if ( $catName !== '-' ) {
193 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
195 $allCats[] = $catTitle;
200 $catName = $msgObj->text();
201 # Allow tracking categories to be disabled by setting them to "-"
202 if ( $catName !== '-' ) {
203 $catTitle = Title
::makeTitleSafe( NS_CATEGORY
, $catName );
205 $allCats[] = $catTitle;
209 $trackingCategories[$catMsg] = [
211 'msg' => $catMsgTitle,
215 return $trackingCategories;
218 protected function getGroupName() {