MediaWiki  1.34.0
SpecialTrackingCategories.php
Go to the documentation of this file.
1 <?php
35  function __construct() {
36  parent::__construct( 'TrackingCategories' );
37  }
38 
39  function execute( $par ) {
40  $this->setHeaders();
41  $this->outputHeader();
42  $this->addHelpLink( 'Help:Categories' );
43  $this->getOutput()->allowClickjacking();
44  $this->getOutput()->addModuleStyles( 'jquery.tablesorter.styles' );
45  $this->getOutput()->addModules( 'jquery.tablesorter' );
46  $this->getOutput()->addHTML(
47  Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
48  'id' => 'mw-trackingcategories-table' ] ) . "\n" .
49  "<thead><tr>
50  <th>" .
51  $this->msg( 'trackingcategories-msg' )->escaped() . "
52  </th>
53  <th>" .
54  $this->msg( 'trackingcategories-name' )->escaped() .
55  "</th>
56  <th>" .
57  $this->msg( 'trackingcategories-desc' )->escaped() . "
58  </th>
59  </tr></thead>"
60  );
61 
62  $trackingCategories = new TrackingCategories( $this->getConfig() );
63  $categoryList = $trackingCategories->getTrackingCategories();
64 
65  $batch = new LinkBatch();
66  foreach ( $categoryList as $catMsg => $data ) {
67  $batch->addObj( $data['msg'] );
68  foreach ( $data['cats'] as $catTitle ) {
69  $batch->addObj( $catTitle );
70  }
71  }
72  $batch->execute();
73 
74  Hooks::run( 'SpecialTrackingCategories::preprocess', [ $this, $categoryList ] );
75 
76  $linkRenderer = $this->getLinkRenderer();
77 
78  foreach ( $categoryList as $catMsg => $data ) {
79  $allMsgs = [];
80  $catDesc = $catMsg . '-desc';
81 
82  $catMsgTitleText = $linkRenderer->makeLink(
83  $data['msg'],
84  $catMsg
85  );
86 
87  foreach ( $data['cats'] as $catTitle ) {
88  $html = $linkRenderer->makeLink(
89  $catTitle,
90  $catTitle->getText()
91  );
92 
93  Hooks::run( 'SpecialTrackingCategories::generateCatLink',
94  [ $this, $catTitle, &$html ] );
95 
96  $allMsgs[] = $html;
97  }
98 
99  # Extra message, when no category was found
100  if ( $allMsgs === [] ) {
101  $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
102  }
103 
104  /*
105  * Show category description if it exists as a system message
106  * as category-name-desc
107  */
108  $descMsg = $this->msg( $catDesc );
109  if ( $descMsg->isBlank() ) {
110  $descMsg = $this->msg( 'trackingcategories-nodesc' );
111  }
112 
113  $this->getOutput()->addHTML(
114  Html::openElement( 'tr' ) .
115  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
116  $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
117  Html::closeElement( 'td' ) .
118  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
119  $catMsgTitleText .
120  Html::closeElement( 'td' ) .
121  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
122  $descMsg->parse() .
123  Html::closeElement( 'td' ) .
124  Html::closeElement( 'tr' )
125  );
126  }
127  $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
128  }
129 
130  protected function getGroupName() {
131  return 'pages';
132  }
133 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:792
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:719
SpecialTrackingCategories\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialTrackingCategories.php:130
SpecialTrackingCategories\__construct
__construct()
Definition: SpecialTrackingCategories.php:35
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:749
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:828
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:758
SpecialTrackingCategories
A special page that displays list of tracking categories Tracking categories allow pages with certain...
Definition: SpecialTrackingCategories.php:34
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:537
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:37
SpecialTrackingCategories\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialTrackingCategories.php:39
TrackingCategories
This class performs some operations related to tracking categories, such as creating a list of all su...
Definition: TrackingCategories.php:29
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:639