Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[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 $this->setHeaders();
41 $this->outputHeader();
42 $this->getOutput()->allowClickjacking();
43 $this->getOutput()->addModuleStyles( 'jquery.tablesorter.styles' );
44 $this->getOutput()->addModules( 'jquery.tablesorter' );
45 $this->getOutput()->addHTML(
46 Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
47 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
48 "<thead><tr>
49 <th>" .
50 $this->msg( 'trackingcategories-msg' )->escaped() . "
51 </th>
52 <th>" .
53 $this->msg( 'trackingcategories-name' )->escaped() .
54 "</th>
55 <th>" .
56 $this->msg( 'trackingcategories-desc' )->escaped() . "
57 </th>
58 </tr></thead>"
59 );
60
61 $trackingCategories = new TrackingCategories( $this->getConfig() );
62 $categoryList = $trackingCategories->getTrackingCategories();
63
64 $batch = new LinkBatch();
65 foreach ( $categoryList as $catMsg => $data ) {
66 $batch->addObj( $data['msg'] );
67 foreach ( $data['cats'] as $catTitle ) {
68 $batch->addObj( $catTitle );
69 }
70 }
71 $batch->execute();
72
73 Hooks::run( 'SpecialTrackingCategories::preprocess', [ $this, $categoryList ] );
74
75 $linkRenderer = $this->getLinkRenderer();
76
77 foreach ( $categoryList as $catMsg => $data ) {
78 $allMsgs = [];
79 $catDesc = $catMsg . '-desc';
80
81 $catMsgTitleText = $linkRenderer->makeLink(
82 $data['msg'],
83 $catMsg
84 );
85
86 foreach ( $data['cats'] as $catTitle ) {
87 $html = $linkRenderer->makeLink(
88 $catTitle,
89 $catTitle->getText()
90 );
91
92 Hooks::run( 'SpecialTrackingCategories::generateCatLink',
93 [ $this, $catTitle, &$html ] );
94
95 $allMsgs[] = $html;
96 }
97
98 # Extra message, when no category was found
99 if ( $allMsgs === [] ) {
100 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
101 }
102
103 /*
104 * Show category description if it exists as a system message
105 * as category-name-desc
106 */
107 $descMsg = $this->msg( $catDesc );
108 if ( $descMsg->isBlank() ) {
109 $descMsg = $this->msg( 'trackingcategories-nodesc' );
110 }
111
112 $this->getOutput()->addHTML(
113 Html::openElement( 'tr' ) .
114 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
115 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
116 Html::closeElement( 'td' ) .
117 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
118 $catMsgTitleText .
119 Html::closeElement( 'td' ) .
120 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
121 $descMsg->parse() .
122 Html::closeElement( 'td' ) .
123 Html::closeElement( 'tr' )
124 );
125 }
126 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
127 }
128
129 protected function getGroupName() {
130 return 'pages';
131 }
132 }