MediaWiki REL1_37
SpecialTrackingCategories.php
Go to the documentation of this file.
1<?php
25
37
40
44 public function __construct( LinkBatchFactory $linkBatchFactory ) {
45 parent::__construct( 'TrackingCategories' );
46 $this->linkBatchFactory = $linkBatchFactory;
47 }
48
49 public function execute( $par ) {
50 $this->setHeaders();
51 $this->outputHeader();
52 $this->addHelpLink( 'Help:Categories' );
53 $this->getOutput()->allowClickjacking();
54 $this->getOutput()->addModuleStyles( [
55 'jquery.tablesorter.styles',
56 'mediawiki.pager.tablePager'
57 ] );
58 $this->getOutput()->addModules( 'jquery.tablesorter' );
59 $this->getOutput()->addHTML(
60 Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
61 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
62 "<thead><tr>
63 <th>" .
64 $this->msg( 'trackingcategories-msg' )->escaped() . "
65 </th>
66 <th>" .
67 $this->msg( 'trackingcategories-name' )->escaped() .
68 "</th>
69 <th>" .
70 $this->msg( 'trackingcategories-desc' )->escaped() . "
71 </th>
72 </tr></thead>"
73 );
74
75 $trackingCategories = new TrackingCategories( $this->getConfig() );
76 $categoryList = $trackingCategories->getTrackingCategories();
77
78 $batch = $this->linkBatchFactory->newLinkBatch();
79 foreach ( $categoryList as $catMsg => $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
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 = $linkRenderer->makeLink(
102 $catTitle,
103 $catTitle->getText()
104 );
105
106 $this->getHookRunner()->onSpecialTrackingCategories__generateCatLink(
107 $this, $catTitle, $html );
108
109 $allMsgs[] = $html;
110 }
111
112 # Extra message, when no category was found
113 if ( $allMsgs === [] ) {
114 $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
115 }
116
117 /*
118 * Show category description if it exists as a system message
119 * as category-name-desc
120 */
121 $descMsg = $this->msg( $catDesc );
122 if ( $descMsg->isBlank() ) {
123 $descMsg = $this->msg( 'trackingcategories-nodesc' );
124 }
125
126 $this->getOutput()->addHTML(
127 Html::openElement( 'tr' ) .
128 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
129 $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
130 Html::closeElement( 'td' ) .
131 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
132 $catMsgTitleText .
133 Html::closeElement( 'td' ) .
134 Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
135 $descMsg->parse() .
136 Html::closeElement( 'td' ) .
137 Html::closeElement( 'tr' )
138 );
139 }
140 $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
141 }
142
143 protected function getGroupName() {
144 return 'pages';
145 }
146}
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
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.
LinkRenderer null $linkRenderer
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
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...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(LinkBatchFactory $linkBatchFactory)
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...