8a32ba98da52841da270cc51b5382ad7c61183ee
[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 $catMsgTitleText = Linker::link(
73 $catMsgTitle,
74 htmlspecialchars( $catMsg )
75 );
76
77 if ( strpos( $msgObj->plain(), '{{NAMESPACE}}' ) !== false ) {
78 $ns = MWNamespace::getValidNamespaces();
79 foreach ( $ns as $namesp ) {
80 $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
81 $catName = $msgObj->title( $tempTitle )->text();
82 if ( !$msgObj->isDisabled() ) {
83 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
84 $catTitleText = Linker::link(
85 $catTitle,
86 htmlspecialchars( $catName )
87 );
88 $allMsgs[] = $catTitleText;
89 }
90 }
91 } else {
92 $catName = $msgObj->text();
93 if ( !$msgObj->isDisabled() ) {
94 $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
95 $catTitleText = Linker::link(
96 $catTitle,
97 htmlspecialchars( $catName )
98 );
99 } else {
100 $catTitleText = $this->msg( 'trackingcategories-disabled' )->parse();
101 }
102 $allMsgs[] = $catTitleText;
103 }
104
105 /*
106 * Show category description if it exists as a system message
107 * as category-name-desc
108 */
109 $descMsg = $this->msg( $catDesc );
110 if ( $descMsg->isBlank() ) {
111 $descMsg = $this->msg( 'trackingcategories-nodesc' );
112 }
113
114 $this->getOutput()->addHTML(
115 Html::openElement( 'tr' ) .
116 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-name' ) ) .
117 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
118 Html::closeElement( 'td' ) .
119 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-msg' ) ) .
120 $catMsgTitleText .
121 Html::closeElement( 'td' ) .
122 Html::openElement( 'td', array( 'class' => 'mw-trackingcategories-desc' ) ) .
123 $descMsg->parse() .
124 Html::closeElement( 'td' ) .
125 Html::closeElement( 'tr' )
126 );
127 }
128 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
129 }
130
131 protected function getGroupName() {
132 return 'pages';
133 }
134 }