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()->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
153class_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.
getContentLanguage()
Shortcut to get content language.
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...
element(SerializerNode $parent, SerializerNode $node, $contents)