Merge "Make the global objects documentation consistent in Setup.php"
[lhc/web/wiklou.git] / includes / specials / SpecialTrackingCategories.php
1 <?php
2 /**
3 * Implements Special:TrackingCategories
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
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.
29 *
30 * @ingroup SpecialPage
31 * @since 1.23
32 */
33
34 class SpecialTrackingCategories extends SpecialPage {
35 function __construct() {
36 parent::__construct( 'TrackingCategories' );
37 }
38
39 function execute( $par ) {
40 // Global array containing names of tracking categories
41 global $wgTrackingCategories;
42
43 $this->setHeaders();
44 $this->outputHeader();
45 $this->getOutput()->allowClickjacking();
46 $this->getOutput()->addHTML(
47 Html::openElement( 'table', array( 'class' => 'mw-datatable TablePager',
48 'id' => 'mw-trackingcategories-table' ) ) . "\n" .
49 "<thead><tr>
50 <th>" .
51 $this->msg( 'trackingcategories-msg' )->escaped() . "
52 </th>
53 <th>" .
54 $this->msg( 'trackingcategories-name' )->escaped() .
55 "</th>
56 <th>" .
57 $this->msg( 'trackingcategories-desc' )->escaped() . "
58 </th>
59 </tr></thead>"
60 );
61
62 foreach( $wgTrackingCategories as $catMsg ) {
63 /*
64 * Check if the tracking category varies by namespace
65 * Otherwise only pages in the current namespace will be displayed
66 * If it does vary, show pages considering all namespaces
67 */
68 $msgObj = $this->msg( $catMsg )->inContentLanguage();
69 $allMsgs = array();
70 $catDesc = $catMsg . '-desc';
71 $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
72 if ( !$catMsgTitle ) {
73 continue;
74 }
75 $catMsgTitleText = Linker::link(
76 $catMsgTitle,
77 htmlspecialchars( $catMsg )
78 );
79
80 // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
81 // False positives are ok, this is just an efficiency shortcut
82 if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
83 $ns = MWNamespace::getValidNamespaces();
84 foreach ( $ns as $namesp ) {
85 $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
86 if ( !$tempTitle ) {
87 continue;
88 }
89 $catName = $msgObj->title( $tempTitle )->text();
90 # Allow tracking categories to be disabled by setting them to "-"
91 if ( $catName !== '-' ) {
92 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
93 if ( $catTitle ) {
94 $catTitleText = Linker::link(
95 $catTitle,
96 htmlspecialchars( $catName )
97 );
98 $allMsgs[] = $catTitleText;
99 }
100 }
101 }
102 } else {
103 $catName = $msgObj->text();
104 # Allow tracking categories to be disabled by setting them to "-"
105 if ( $catName !== '-' ) {
106 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
107 if ( $catTitle ) {
108 $catTitleText = Linker::link(
109 $catTitle,
110 htmlspecialchars( $catName )
111 );
112 $allMsgs[] = $catTitleText;
113 }
114 }
115 }
116
117 # Extra message, when no category was found
118 if ( !count( $allMsgs ) ) {
119 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
120 }
121
122 /*
123 * Show category description if it exists as a system message
124 * as category-name-desc
125 */
126 $descMsg = $this->msg( $catDesc );
127 if ( $descMsg->isBlank() ) {
128 $descMsg = $this->msg( 'trackingcategories-nodesc' );
129 }
130
131 $this->getOutput()->addHTML(
132 Html::openElement( 'tr' ) .
133 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-name' ) ) .
134 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
135 Html::closeElement( 'td' ) .
136 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-msg' ) ) .
137 $catMsgTitleText .
138 Html::closeElement( 'td' ) .
139 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-desc' ) ) .
140 $descMsg->parse() .
141 Html::closeElement( 'td' ) .
142 Html::closeElement( 'tr' )
143 );
144 }
145 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
146 }
147
148 protected function getGroupName() {
149 return 'pages';
150 }
151 }