MediaWiki REL1_39
SpecialTrackingCategories.php
Go to the documentation of this file.
1<?php
25
37
39 private $linkBatchFactory;
40
42 private $trackingCategories;
43
48 public function __construct(
49 LinkBatchFactory $linkBatchFactory,
50 TrackingCategories $trackingCategories
51 ) {
52 parent::__construct( 'TrackingCategories' );
53 $this->linkBatchFactory = $linkBatchFactory;
54 $this->trackingCategories = $trackingCategories;
55 }
56
57 public function execute( $par ) {
58 $this->setHeaders();
59 $this->outputHeader();
60 $this->addHelpLink( 'Help:Categories' );
61 $this->getOutput()->setPreventClickjacking( false );
62 $this->getOutput()->addModuleStyles( [
63 'jquery.tablesorter.styles',
64 'mediawiki.pager.styles'
65 ] );
66 $this->getOutput()->addModules( 'jquery.tablesorter' );
67 $this->getOutput()->addHTML(
68 Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
69 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
70 "<thead><tr>
71 <th>" .
72 $this->msg( 'trackingcategories-msg' )->escaped() . "
73 </th>
74 <th>" .
75 $this->msg( 'trackingcategories-name' )->escaped() .
76 "</th>
77 <th>" .
78 $this->msg( 'trackingcategories-desc' )->escaped() . "
79 </th>
80 </tr></thead>"
81 );
82
83 $categoryList = $this->trackingCategories->getTrackingCategories();
84
85 $batch = $this->linkBatchFactory->newLinkBatch();
86 foreach ( $categoryList as $catMsg => $data ) {
87 $batch->addObj( $data['msg'] );
88 foreach ( $data['cats'] as $catTitle ) {
89 $batch->addObj( $catTitle );
90 }
91 }
92 $batch->execute();
93
94 $this->getHookRunner()->onSpecialTrackingCategories__preprocess( $this, $categoryList );
95
96 $linkRenderer = $this->getLinkRenderer();
97
98 foreach ( $categoryList as $catMsg => $data ) {
99 $allMsgs = [];
100 $catDesc = $catMsg . '-desc';
101
102 $catMsgTitleText = $linkRenderer->makeLink(
103 $data['msg'],
104 $catMsg
105 );
106
107 foreach ( $data['cats'] as $catTitle ) {
108 $html = $linkRenderer->makeLink(
109 $catTitle,
110 $catTitle->getText()
111 );
112
113 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
114 $this, $catTitle, $html );
115
116 $allMsgs[] = $html;
117 }
118
119 # Extra message, when no category was found
120 if ( $allMsgs === [] ) {
121 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
122 }
123
124 /*
125 * Show category description if it exists as a system message
126 * as category-name-desc
127 */
128 $descMsg = $this->msg( $catDesc );
129 if ( $descMsg->isBlank() ) {
130 $descMsg = $this->msg( 'trackingcategories-nodesc' );
131 }
132
133 $this->getOutput()->addHTML(
134 Html::openElement( 'tr' ) .
135 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
136 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
137 Html::closeElement( 'td' ) .
138 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
139 $catMsgTitleText .
140 Html::closeElement( 'td' ) .
141 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
142 $descMsg->parse() .
143 Html::closeElement( 'td' ) .
144 Html::closeElement( 'tr' )
145 );
146 }
147 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
148 }
149
150 protected function getGroupName() {
151 return 'pages';
152 }
153}
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
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)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Default execute method Checks user permissions.
This class performs some operations related to tracking categories, such as creating a list of all su...