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