Do not insert page titles into querycache.qc_value
[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->addHelpLink( 'Help:Categories' );
43 $this->getOutput()->allowClickjacking();
44 $this->getOutput()->addModuleStyles( 'jquery.tablesorter.styles' );
45 $this->getOutput()->addModules( 'jquery.tablesorter' );
46 $this->getOutput()->addHTML(
47 Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
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 $trackingCategories = new TrackingCategories( $this->getConfig() );
63 $categoryList = $trackingCategories->getTrackingCategories();
64
65 $batch = new LinkBatch();
66 foreach ( $categoryList as $catMsg => $data ) {
67 $batch->addObj( $data['msg'] );
68 foreach ( $data['cats'] as $catTitle ) {
69 $batch->addObj( $catTitle );
70 }
71 }
72 $batch->execute();
73
74 Hooks::run( 'SpecialTrackingCategories::preprocess', [ $this, $categoryList ] );
75
76 $linkRenderer = $this->getLinkRenderer();
77
78 foreach ( $categoryList as $catMsg => $data ) {
79 $allMsgs = [];
80 $catDesc = $catMsg . '-desc';
81
82 $catMsgTitleText = $linkRenderer->makeLink(
83 $data['msg'],
84 $catMsg
85 );
86
87 foreach ( $data['cats'] as $catTitle ) {
88 $html = $linkRenderer->makeLink(
89 $catTitle,
90 $catTitle->getText()
91 );
92
93 Hooks::run( 'SpecialTrackingCategories::generateCatLink',
94 [ $this, $catTitle, &$html ] );
95
96 $allMsgs[] = $html;
97 }
98
99 # Extra message, when no category was found
100 if ( $allMsgs === [] ) {
101 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
102 }
103
104 /*
105 * Show category description if it exists as a system message
106 * as category-name-desc
107 */
108 $descMsg = $this->msg( $catDesc );
109 if ( $descMsg->isBlank() ) {
110 $descMsg = $this->msg( 'trackingcategories-nodesc' );
111 }
112
113 $this->getOutput()->addHTML(
114 Html::openElement( 'tr' ) .
115 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
116 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
117 Html::closeElement( 'td' ) .
118 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
119 $catMsgTitleText .
120 Html::closeElement( 'td' ) .
121 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
122 $descMsg->parse() .
123 Html::closeElement( 'td' ) .
124 Html::closeElement( 'tr' )
125 );
126 }
127 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
128 }
129
130 protected function getGroupName() {
131 return 'pages';
132 }
133 }