MediaWiki  1.27.2
SpecialTrackingCategories.php
Go to the documentation of this file.
1 <?php
35  function __construct() {
36  parent::__construct( 'TrackingCategories' );
37  }
38 
44  private static $coreTrackingCategories = [
45  'index-category',
46  'noindex-category',
47  'duplicate-args-category',
48  'expensive-parserfunction-category',
49  'post-expand-template-argument-category',
50  'post-expand-template-inclusion-category',
51  'hidden-category-category',
52  'broken-file-category',
53  'node-count-exceeded-category',
54  'expansion-depth-exceeded-category',
55  ];
56 
57  function execute( $par ) {
58  $this->setHeaders();
59  $this->outputHeader();
60  $this->getOutput()->allowClickjacking();
61  $this->getOutput()->addHTML(
62  Html::openElement( 'table', [ 'class' => 'mw-datatable',
63  'id' => 'mw-trackingcategories-table' ] ) . "\n" .
64  "<thead><tr>
65  <th>" .
66  $this->msg( 'trackingcategories-msg' )->escaped() . "
67  </th>
68  <th>" .
69  $this->msg( 'trackingcategories-name' )->escaped() .
70  "</th>
71  <th>" .
72  $this->msg( 'trackingcategories-desc' )->escaped() . "
73  </th>
74  </tr></thead>"
75  );
76 
77  $trackingCategories = $this->prepareTrackingCategoriesData();
78 
79  $batch = new LinkBatch();
80  foreach ( $trackingCategories as $catMsg => $data ) {
81  $batch->addObj( $data['msg'] );
82  foreach ( $data['cats'] as $catTitle ) {
83  $batch->addObj( $catTitle );
84  }
85  }
86  $batch->execute();
87 
88  foreach ( $trackingCategories as $catMsg => $data ) {
89  $allMsgs = [];
90  $catDesc = $catMsg . '-desc';
91 
92  $catMsgTitleText = Linker::link(
93  $data['msg'],
94  htmlspecialchars( $catMsg )
95  );
96 
97  foreach ( $data['cats'] as $catTitle ) {
98  $catTitleText = Linker::link(
99  $catTitle,
100  htmlspecialchars( $catTitle->getText() )
101  );
102  $allMsgs[] = $catTitleText;
103  }
104 
105  # Extra message, when no category was found
106  if ( !count( $allMsgs ) ) {
107  $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
108  }
109 
110  /*
111  * Show category description if it exists as a system message
112  * as category-name-desc
113  */
114  $descMsg = $this->msg( $catDesc );
115  if ( $descMsg->isBlank() ) {
116  $descMsg = $this->msg( 'trackingcategories-nodesc' );
117  }
118 
119  $this->getOutput()->addHTML(
120  Html::openElement( 'tr' ) .
121  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
122  $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
123  Html::closeElement( 'td' ) .
124  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
125  $catMsgTitleText .
126  Html::closeElement( 'td' ) .
127  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
128  $descMsg->parse() .
129  Html::closeElement( 'td' ) .
130  Html::closeElement( 'tr' )
131  );
132  }
133  $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
134  }
135 
140  private function prepareTrackingCategoriesData() {
141  $categories = array_merge(
142  self::$coreTrackingCategories,
143  ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
144  $this->getConfig()->get( 'TrackingCategories' ) // deprecated
145  );
146  $trackingCategories = [];
147  foreach ( $categories as $catMsg ) {
148  /*
149  * Check if the tracking category varies by namespace
150  * Otherwise only pages in the current namespace will be displayed
151  * If it does vary, show pages considering all namespaces
152  */
153  $msgObj = $this->msg( $catMsg )->inContentLanguage();
154  $allCats = [];
155  $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
156  if ( !$catMsgTitle ) {
157  continue;
158  }
159 
160  // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
161  // False positives are ok, this is just an efficiency shortcut
162  if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
164  foreach ( $ns as $namesp ) {
165  $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
166  if ( !$tempTitle ) {
167  continue;
168  }
169  $catName = $msgObj->title( $tempTitle )->text();
170  # Allow tracking categories to be disabled by setting them to "-"
171  if ( $catName !== '-' ) {
172  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
173  if ( $catTitle ) {
174  $allCats[] = $catTitle;
175  }
176  }
177  }
178  } else {
179  $catName = $msgObj->text();
180  # Allow tracking categories to be disabled by setting them to "-"
181  if ( $catName !== '-' ) {
182  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
183  if ( $catTitle ) {
184  $allCats[] = $catTitle;
185  }
186  }
187  }
188  $trackingCategories[$catMsg] = [
189  'cats' => $allCats,
190  'msg' => $catMsgTitle,
191  ];
192  }
193 
194  return $trackingCategories;
195  }
196 
197  protected function getGroupName() {
198  return 'pages';
199  }
200 }
static array $coreTrackingCategories
Tracking categories that exist in core.
static closeElement($element)
Returns "".
Definition: Html.php:306
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
$batch
Definition: linkcache.txt:23
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:31
Parent class for all special pages.
Definition: SpecialPage.php:36
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
const NS_CATEGORY
Definition: Defines.php:83
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
const NS_MEDIAWIKI
Definition: Defines.php:77
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:195
A special page that displays list of tracking categories Tracking categories allow pages with certain...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
prepareTrackingCategoriesData()
Read the global and extract title objects from the corresponding messages.