Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 70
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialTrackingCategories
0.00% covered (danger)
0.00%
0 / 69
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 65
0.00% covered (danger)
0.00%
0 / 1
56
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
24namespace MediaWiki\Specials;
25
26use MediaWiki\Cache\LinkBatchFactory;
27use MediaWiki\Category\TrackingCategories;
28use MediaWiki\Html\Html;
29use MediaWiki\SpecialPage\SpecialPage;
30
31/**
32 * A special page that displays list of tracking categories
33 * Tracking categories allow pages with certain characteristics to be tracked.
34 * It works by adding any such page to a category automatically.
35 * Category is specified by the tracking category's system message.
36 *
37 * @ingroup SpecialPage
38 * @since 1.23
39 */
40
41class SpecialTrackingCategories extends SpecialPage {
42
43    private LinkBatchFactory $linkBatchFactory;
44    private TrackingCategories $trackingCategories;
45
46    /**
47     * @param LinkBatchFactory $linkBatchFactory
48     * @param TrackingCategories $trackingCategories
49     */
50    public function __construct(
51        LinkBatchFactory $linkBatchFactory,
52        TrackingCategories $trackingCategories
53    ) {
54        parent::__construct( 'TrackingCategories' );
55        $this->linkBatchFactory = $linkBatchFactory;
56        $this->trackingCategories = $trackingCategories;
57    }
58
59    public function execute( $par ) {
60        $this->setHeaders();
61        $this->outputHeader();
62        $this->addHelpLink( 'Help:Tracking categories' );
63        $this->getOutput()->setPreventClickjacking( false );
64        $this->getOutput()->addModuleStyles( [
65            'jquery.tablesorter.styles',
66            'mediawiki.pager.styles'
67        ] );
68        $this->getOutput()->addModules( 'jquery.tablesorter' );
69        $this->getOutput()->addHTML(
70            Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
71                'id' => 'mw-trackingcategories-table' ] ) . "\n" .
72            "<thead><tr>
73            <th>" .
74                $this->msg( 'trackingcategories-msg' )->escaped() . "
75            </th>
76            <th>" .
77                $this->msg( 'trackingcategories-name' )->escaped() .
78            "</th>
79            <th>" .
80                $this->msg( 'trackingcategories-desc' )->escaped() . "
81            </th>
82            </tr></thead>"
83        );
84
85        $categoryList = $this->trackingCategories->getTrackingCategories();
86
87        $batch = $this->linkBatchFactory->newLinkBatch();
88        foreach ( $categoryList as $data ) {
89            $batch->addObj( $data['msg'] );
90            foreach ( $data['cats'] as $catTitle ) {
91                $batch->addObj( $catTitle );
92            }
93        }
94        $batch->execute();
95
96        $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
97
98        $linkRenderer = $this->getLinkRenderer();
99
100        foreach ( $categoryList as $catMsg => $data ) {
101            $allMsgs = [];
102            $catDesc = $catMsg . '-desc';
103
104            $catMsgTitleText = $linkRenderer->makeLink(
105                $data['msg'],
106                $catMsg
107            );
108
109            foreach ( $data['cats'] as $catTitle ) {
110                $html = $linkRenderer->makeLink(
111                    $catTitle,
112                    $catTitle->getText()
113                );
114
115                $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
116                    $this, $catTitle, $html );
117
118                $allMsgs[] = $html;
119            }
120
121            # Extra message, when no category was found
122            if ( $allMsgs === [] ) {
123                $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
124            }
125
126            /*
127             * Show category description if it exists as a system message
128             * as category-name-desc
129             */
130            $descMsg = $this->msg( $catDesc );
131            if ( $descMsg->isBlank() ) {
132                $descMsg = $this->msg( 'trackingcategories-nodesc' );
133            }
134
135            $this->getOutput()->addHTML(
136                Html::openElement( 'tr' ) .
137                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
138                    $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
139                Html::closeElement( 'td' ) .
140                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
141                    $catMsgTitleText .
142                Html::closeElement( 'td' ) .
143                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
144                    $descMsg->parse() .
145                Html::closeElement( 'td' ) .
146                Html::closeElement( 'tr' )
147            );
148        }
149        $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
150    }
151
152    protected function getGroupName() {
153        return 'pages';
154    }
155}
156
157/**
158 * Retain the old class name for backwards compatibility.
159 * @deprecated since 1.41
160 */
161class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' );