wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / specials / SpecialTrackingCategories.php
blobd219c99d0361b0921ac51de338c96f0c9131fc74
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
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
31 * @since 1.23
34 class SpecialTrackingCategories extends SpecialPage {
35 function __construct() {
36 parent::__construct( 'TrackingCategories' );
39 /**
40 * Tracking categories that exist in core
42 * @var array
44 private static $coreTrackingCategories = array(
45 'index-category',
46 'noindex-category',
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',
57 function execute( $par ) {
58 $this->setHeaders();
59 $this->outputHeader();
60 $this->getOutput()->allowClickjacking();
61 $this->getOutput()->addHTML(
62 Html::openElement( 'table', array( 'class' => 'mw-datatable',
63 'id' => 'mw-trackingcategories-table' ) ) . "\n" .
64 "<thead><tr>
65 <th>" .
66 $this->msg( 'trackingcategories-msg' )->escaped() . "
67 </th>
68 <th>" .
69 $this->msg( 'trackingcategories-name' )->escaped() .
70 "</th>
71 <th>" .
72 $this->msg( 'trackingcategories-desc' )->escaped() . "
73 </th>
74 </tr></thead>"
77 $trackingCategories = $this->prepareTrackingCategoriesData();
79 $batch = new LinkBatch();
80 foreach ( $trackingCategories as $catMsg => $data ) {
81 $batch->addObj( $data['msg'] );
82 foreach ( $data['cats'] as $catTitle ) {
83 $batch->addObj( $catTitle );
86 $batch->execute();
88 foreach ( $trackingCategories as $catMsg => $data ) {
89 $allMsgs = array();
90 $catDesc = $catMsg . '-desc';
92 $catMsgTitleText = Linker::link(
93 $data['msg'],
94 htmlspecialchars( $catMsg )
97 foreach ( $data['cats'] as $catTitle ) {
98 $catTitleText = Linker::link(
99 $catTitle,
100 htmlspecialchars( $catTitle->getText() )
102 $allMsgs[] = $catTitleText;
105 # Extra message, when no category was found
106 if ( !count( $allMsgs ) ) {
107 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
111 * Show category description if it exists as a system message
112 * as category-name-desc
114 $descMsg = $this->msg( $catDesc );
115 if ( $descMsg->isBlank() ) {
116 $descMsg = $this->msg( 'trackingcategories-nodesc' );
119 $this->getOutput()->addHTML(
120 Html::openElement( 'tr' ) .
121 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-name' ) ) .
122 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
123 Html::closeElement( 'td' ) .
124 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-msg' ) ) .
125 $catMsgTitleText .
126 Html::closeElement( 'td' ) .
127 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-desc' ) ) .
128 $descMsg->parse() .
129 Html::closeElement( 'td' ) .
130 Html::closeElement( 'tr' )
133 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
137 * Read the global and extract title objects from the corresponding messages
138 * @return array Array( 'msg' => Title, 'cats' => Title[] )
140 private function prepareTrackingCategoriesData() {
141 $categories = array_merge(
142 self::$coreTrackingCategories,
143 ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
144 $this->getConfig()->get( 'TrackingCategories' ) // deprecated
146 $trackingCategories = array();
147 foreach ( $categories as $catMsg ) {
149 * Check if the tracking category varies by namespace
150 * Otherwise only pages in the current namespace will be displayed
151 * If it does vary, show pages considering all namespaces
153 $msgObj = $this->msg( $catMsg )->inContentLanguage();
154 $allCats = array();
155 $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
156 if ( !$catMsgTitle ) {
157 continue;
160 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
161 // False positives are ok, this is just an efficiency shortcut
162 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
163 $ns = MWNamespace::getValidNamespaces();
164 foreach ( $ns as $namesp ) {
165 $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
166 if ( !$tempTitle ) {
167 continue;
169 $catName = $msgObj->title( $tempTitle )->text();
170 # Allow tracking categories to be disabled by setting them to "-"
171 if ( $catName !== '-' ) {
172 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
173 if ( $catTitle ) {
174 $allCats[] = $catTitle;
178 } else {
179 $catName = $msgObj->text();
180 # Allow tracking categories to be disabled by setting them to "-"
181 if ( $catName !== '-' ) {
182 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
183 if ( $catTitle ) {
184 $allCats[] = $catTitle;
188 $trackingCategories[$catMsg] = array(
189 'cats' => $allCats,
190 'msg' => $catMsgTitle,
194 return $trackingCategories;
197 protected function getGroupName() {
198 return 'pages';