MediaWiki master
SpecialTrackingCategories.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use MediaWiki\Cache\LinkBatchFactory;
13
25
26 private LinkBatchFactory $linkBatchFactory;
27 private TrackingCategories $trackingCategories;
28
29 public function __construct(
30 LinkBatchFactory $linkBatchFactory,
31 TrackingCategories $trackingCategories
32 ) {
33 parent::__construct( 'TrackingCategories' );
34 $this->linkBatchFactory = $linkBatchFactory;
35 $this->trackingCategories = $trackingCategories;
36 }
37
39 public function execute( $par ) {
40 $this->setHeaders();
41 $this->outputHeader();
42 $this->addHelpLink( 'Help:Tracking categories' );
43 $this->getOutput()->getMetadata()->setPreventClickjacking( false );
44 $this->getOutput()->addModuleStyles( [
45 'jquery.tablesorter.styles',
46 'mediawiki.pager.styles'
47 ] );
48 $this->getOutput()->addModules( 'jquery.tablesorter' );
49 $this->getOutput()->addHTML(
50 Html::openElement( 'table', [ 'class' => [ 'mw-datatable', 'sortable' ],
51 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
52 '<thead><tr>' .
53 Html::element( 'th', [], $this->msg( 'trackingcategories-msg' )->text() ) .
54 Html::element( 'th', [], $this->msg( 'trackingcategories-name' )->text() ) .
55 Html::element( 'th', [], $this->msg( 'trackingcategories-desc' )->text() ) .
56 '</tr></thead>'
57 );
58
59 $categoryList = $this->trackingCategories->getTrackingCategories();
60
61 $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
62 foreach ( $categoryList as $data ) {
63 $batch->addObj( $data['msg'] );
64 foreach ( $data['cats'] as $catTitle ) {
65 $batch->addObj( $catTitle );
66 }
67 }
68 $batch->execute();
69
70 $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
71
72 $linkRenderer = $this->getLinkRenderer();
73
74 foreach ( $categoryList as $catMsg => $data ) {
75 $allMsgs = [];
76 $catDesc = $catMsg . '-desc';
77
78 $catMsgTitleText = $linkRenderer->makeLink(
79 $data['msg'],
80 $catMsg
81 );
82
83 foreach ( $data['cats'] as $catTitle ) {
84 $html = Html::rawElement( 'bdi', [ 'dir' => $this->getContentLanguage()->getDir() ],
85 $linkRenderer->makeLink(
86 $catTitle,
87 $catTitle->getText()
88 ) );
89
90 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
91 $this, $catTitle, $html );
92
93 $allMsgs[] = $html;
94 }
95
96 # Extra message, when no category was found
97 if ( $allMsgs === [] ) {
98 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
99 }
100
101 /*
102 * Show category description if it exists as a system message
103 * as category-name-desc
104 */
105 $descMsg = $this->msg( $catDesc );
106 if ( $descMsg->isBlank() ) {
107 $descMsg = $this->msg( 'trackingcategories-nodesc' );
108 }
109
110 $this->getOutput()->addHTML(
111 Html::openElement( 'tr' ) .
112 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
113 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
114 Html::closeElement( 'td' ) .
115 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
116 $catMsgTitleText .
117 Html::closeElement( 'td' ) .
118 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
119 $descMsg->parse() .
120 Html::closeElement( 'td' ) .
121 Html::closeElement( 'tr' )
122 );
123 }
124 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
125 }
126
128 protected function getGroupName() {
129 return 'pages';
130 }
131}
132
137class_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:43
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.This must be overridden by subclasses; it will be made...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
element(SerializerNode $parent, SerializerNode $node, $contents)