Merge "docs: Fix typo"
[mediawiki.git] / includes / specials / SpecialTrackingCategories.php
blob819fe5bdbc99e2f2974abcaf19a45ebe1dd24103
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.
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.
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
18 * @file
21 namespace MediaWiki\Specials;
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\Category\TrackingCategories;
25 use MediaWiki\Html\Html;
26 use MediaWiki\SpecialPage\SpecialPage;
28 /**
29 * A special page that displays list of tracking categories.
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.
35 * @ingroup SpecialPage
36 * @since 1.23
38 class SpecialTrackingCategories extends SpecialPage {
40 private LinkBatchFactory $linkBatchFactory;
41 private TrackingCategories $trackingCategories;
43 public function __construct(
44 LinkBatchFactory $linkBatchFactory,
45 TrackingCategories $trackingCategories
46 ) {
47 parent::__construct( 'TrackingCategories' );
48 $this->linkBatchFactory = $linkBatchFactory;
49 $this->trackingCategories = $trackingCategories;
52 public function execute( $par ) {
53 $this->setHeaders();
54 $this->outputHeader();
55 $this->addHelpLink( 'Help:Tracking categories' );
56 $this->getOutput()->getMetadata()->setPreventClickjacking( false );
57 $this->getOutput()->addModuleStyles( [
58 'jquery.tablesorter.styles',
59 'mediawiki.pager.styles'
60 ] );
61 $this->getOutput()->addModules( 'jquery.tablesorter' );
62 $this->getOutput()->addHTML(
63 Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
64 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
65 '<thead><tr>' .
66 Html::element( 'th', [], $this->msg( 'trackingcategories-msg' )->text() ) .
67 Html::element( 'th', [], $this->msg( 'trackingcategories-name' )->text() ) .
68 Html::element( 'th', [], $this->msg( 'trackingcategories-desc' )->text() ) .
69 '</tr></thead>'
72 $categoryList = $this->trackingCategories->getTrackingCategories();
74 $batch = $this->linkBatchFactory->newLinkBatch();
75 foreach ( $categoryList as $data ) {
76 $batch->addObj( $data['msg'] );
77 foreach ( $data['cats'] as $catTitle ) {
78 $batch->addObj( $catTitle );
81 $batch->execute();
83 $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
85 $linkRenderer = $this->getLinkRenderer();
87 foreach ( $categoryList as $catMsg => $data ) {
88 $allMsgs = [];
89 $catDesc = $catMsg . '-desc';
91 $catMsgTitleText = $linkRenderer->makeLink(
92 $data['msg'],
93 $catMsg
96 foreach ( $data['cats'] as $catTitle ) {
97 $html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ],
98 $linkRenderer->makeLink(
99 $catTitle,
100 $catTitle->getText()
101 ) );
103 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
104 $this, $catTitle, $html );
106 $allMsgs[] = $html;
109 # Extra message, when no category was found
110 if ( $allMsgs === [] ) {
111 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
115 * Show category description if it exists as a system message
116 * as category-name-desc
118 $descMsg = $this->msg( $catDesc );
119 if ( $descMsg->isBlank() ) {
120 $descMsg = $this->msg( 'trackingcategories-nodesc' );
123 $this->getOutput()->addHTML(
124 Html::openElement( 'tr' ) .
125 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
126 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
127 Html::closeElement( 'td' ) .
128 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
129 $catMsgTitleText .
130 Html::closeElement( 'td' ) .
131 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
132 $descMsg->parse() .
133 Html::closeElement( 'td' ) .
134 Html::closeElement( 'tr' )
137 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
140 protected function getGroupName() {
141 return 'pages';
146 * Retain the old class name for backwards compatibility.
147 * @deprecated since 1.41
149 class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' );