Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 67
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 / 66
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 / 62
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 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Specials;
22
23use MediaWiki\Cache\LinkBatchFactory;
24use MediaWiki\Category\TrackingCategories;
25use MediaWiki\Html\Html;
26use MediaWiki\SpecialPage\SpecialPage;
27
28/**
29 * A special page that displays list of tracking categories.
30 *
31 * Tracking categories allow pages with certain characteristics to be tracked.
32 * It works by adding any such page to a category automatically.
33 * Category is specified by the tracking category's system message.
34 *
35 * @ingroup SpecialPage
36 * @since 1.23
37 */
38class SpecialTrackingCategories extends SpecialPage {
39
40    private LinkBatchFactory $linkBatchFactory;
41    private TrackingCategories $trackingCategories;
42
43    /**
44     * @param LinkBatchFactory $linkBatchFactory
45     * @param TrackingCategories $trackingCategories
46     */
47    public function __construct(
48        LinkBatchFactory $linkBatchFactory,
49        TrackingCategories $trackingCategories
50    ) {
51        parent::__construct( 'TrackingCategories' );
52        $this->linkBatchFactory = $linkBatchFactory;
53        $this->trackingCategories = $trackingCategories;
54    }
55
56    public function execute( $par ) {
57        $this->setHeaders();
58        $this->outputHeader();
59        $this->addHelpLink( 'Help:Tracking categories' );
60        $this->getOutput()->getMetadata()->setPreventClickjacking( false );
61        $this->getOutput()->addModuleStyles( [
62            'jquery.tablesorter.styles',
63            'mediawiki.pager.styles'
64        ] );
65        $this->getOutput()->addModules( 'jquery.tablesorter' );
66        $this->getOutput()->addHTML(
67            Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
68                'id' => 'mw-trackingcategories-table' ] ) . "\n" .
69            '<thead><tr>' .
70            Html::element( 'th', [], $this->msg( 'trackingcategories-msg' )->text() ) .
71            Html::element( 'th', [], $this->msg( 'trackingcategories-name' )->text() ) .
72            Html::element( 'th', [], $this->msg( 'trackingcategories-desc' )->text() ) .
73            '</tr></thead>'
74        );
75
76        $categoryList = $this->trackingCategories->getTrackingCategories();
77
78        $batch = $this->linkBatchFactory->newLinkBatch();
79        foreach ( $categoryList as $data ) {
80            $batch->addObj( $data['msg'] );
81            foreach ( $data['cats'] as $catTitle ) {
82                $batch->addObj( $catTitle );
83            }
84        }
85        $batch->execute();
86
87        $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
88
89        $linkRenderer = $this->getLinkRenderer();
90
91        foreach ( $categoryList as $catMsg => $data ) {
92            $allMsgs = [];
93            $catDesc = $catMsg . '-desc';
94
95            $catMsgTitleText = $linkRenderer->makeLink(
96                $data['msg'],
97                $catMsg
98            );
99
100            foreach ( $data['cats'] as $catTitle ) {
101                $html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ],
102                    $linkRenderer->makeLink(
103                        $catTitle,
104                        $catTitle->getText()
105                    ) );
106
107                $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
108                    $this, $catTitle, $html );
109
110                $allMsgs[] = $html;
111            }
112
113            # Extra message, when no category was found
114            if ( $allMsgs === [] ) {
115                $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
116            }
117
118            /*
119             * Show category description if it exists as a system message
120             * as category-name-desc
121             */
122            $descMsg = $this->msg( $catDesc );
123            if ( $descMsg->isBlank() ) {
124                $descMsg = $this->msg( 'trackingcategories-nodesc' );
125            }
126
127            $this->getOutput()->addHTML(
128                Html::openElement( 'tr' ) .
129                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
130                    $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
131                Html::closeElement( 'td' ) .
132                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
133                    $catMsgTitleText .
134                Html::closeElement( 'td' ) .
135                Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
136                    $descMsg->parse() .
137                Html::closeElement( 'td' ) .
138                Html::closeElement( 'tr' )
139            );
140        }
141        $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
142    }
143
144    protected function getGroupName() {
145        return 'pages';
146    }
147}
148
149/**
150 * Retain the old class name for backwards compatibility.
151 * @deprecated since 1.41
152 */
153class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' );