Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specials / SpecialTrackingCategories.php
blob810c53d1f1d11cfac374108caf4802324826795f
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 /**
44 * @param LinkBatchFactory $linkBatchFactory
45 * @param TrackingCategories $trackingCategories
47 public function __construct(
48 LinkBatchFactory $linkBatchFactory,
49 TrackingCategories $trackingCategories
50 ) {
51 parent::__construct( 'TrackingCategories' );
52 $this->linkBatchFactory = $linkBatchFactory;
53 $this->trackingCategories = $trackingCategories;
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>'
76 $categoryList = $this->trackingCategories->getTrackingCategories();
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 );
85 $batch->execute();
87 $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
89 $linkRenderer = $this->getLinkRenderer();
91 foreach ( $categoryList as $catMsg => $data ) {
92 $allMsgs = [];
93 $catDesc = $catMsg . '-desc';
95 $catMsgTitleText = $linkRenderer->makeLink(
96 $data['msg'],
97 $catMsg
100 foreach ( $data['cats'] as $catTitle ) {
101 $html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ],
102 $linkRenderer->makeLink(
103 $catTitle,
104 $catTitle->getText()
105 ) );
107 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
108 $this, $catTitle, $html );
110 $allMsgs[] = $html;
113 # Extra message, when no category was found
114 if ( $allMsgs === [] ) {
115 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
119 * Show category description if it exists as a system message
120 * as category-name-desc
122 $descMsg = $this->msg( $catDesc );
123 if ( $descMsg->isBlank() ) {
124 $descMsg = $this->msg( 'trackingcategories-nodesc' );
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' )
141 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
144 protected function getGroupName() {
145 return 'pages';
150 * Retain the old class name for backwards compatibility.
151 * @deprecated since 1.41
153 class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' );