MediaWiki master
SpecialTrackingCategories.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
30
42
43 private LinkBatchFactory $linkBatchFactory;
44 private TrackingCategories $trackingCategories;
45
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
161class_alias( SpecialTrackingCategories::class, 'SpecialTrackingCategories' );
This class performs some operations related to tracking categories, such as adding a tracking categor...
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that displays list of tracking categories Tracking categories allow pages with certain...
__construct(LinkBatchFactory $linkBatchFactory, TrackingCategories $trackingCategories)
execute( $par)
Default execute method Checks user permissions.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...