MediaWiki master
SpecialTrackingCategories.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
27
39
40 private LinkBatchFactory $linkBatchFactory;
41 private TrackingCategories $trackingCategories;
42
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()->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 <th>" .
71 $this->msg( 'trackingcategories-msg' )->escaped() . "
72 </th>
73 <th>" .
74 $this->msg( 'trackingcategories-name' )->escaped() .
75 "</th>
76 <th>" .
77 $this->msg( 'trackingcategories-desc' )->escaped() . "
78 </th>
79 </tr></thead>"
80 );
81
82 $categoryList = $this->trackingCategories->getTrackingCategories();
83
84 $batch = $this->linkBatchFactory->newLinkBatch();
85 foreach ( $categoryList as $data ) {
86 $batch->addObj( $data['msg'] );
87 foreach ( $data['cats'] as $catTitle ) {
88 $batch->addObj( $catTitle );
89 }
90 }
91 $batch->execute();
92
93 $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
94
95 $linkRenderer = $this->getLinkRenderer();
96
97 foreach ( $categoryList as $catMsg => $data ) {
98 $allMsgs = [];
99 $catDesc = $catMsg . '-desc';
100
101 $catMsgTitleText = $linkRenderer->makeLink(
102 $data['msg'],
103 $catMsg
104 );
105
106 foreach ( $data['cats'] as $catTitle ) {
107 $html = $linkRenderer->makeLink(
108 $catTitle,
109 $catTitle->getText()
110 );
111
112 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
113 $this, $catTitle, $html );
114
115 $allMsgs[] = $html;
116 }
117
118 # Extra message, when no category was found
119 if ( $allMsgs === [] ) {
120 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
121 }
122
123 /*
124 * Show category description if it exists as a system message
125 * as category-name-desc
126 */
127 $descMsg = $this->msg( $catDesc );
128 if ( $descMsg->isBlank() ) {
129 $descMsg = $this->msg( 'trackingcategories-nodesc' );
130 }
131
132 $this->getOutput()->addHTML(
133 Html::openElement( 'tr' ) .
134 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
135 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
136 Html::closeElement( 'td' ) .
137 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
138 $catMsgTitleText .
139 Html::closeElement( 'td' ) .
140 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
141 $descMsg->parse() .
142 Html::closeElement( 'td' ) .
143 Html::closeElement( 'tr' )
144 );
145 }
146 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
147 }
148
149 protected function getGroupName() {
150 return 'pages';
151 }
152}
153
158class_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 By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that displays list of tracking categories.
__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...