MediaWiki  master
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  'restricted-displaytitle-ignored',
56  'deprecated-self-close-category',
57  ];
58 
59  function execute( $par ) {
60  $this->setHeaders();
61  $this->outputHeader();
62  $this->getOutput()->allowClickjacking();
63  $this->getOutput()->addHTML(
64  Html::openElement( 'table', [ 'class' => 'mw-datatable',
65  'id' => 'mw-trackingcategories-table' ] ) . "\n" .
66  "<thead><tr>
67  <th>" .
68  $this->msg( 'trackingcategories-msg' )->escaped() . "
69  </th>
70  <th>" .
71  $this->msg( 'trackingcategories-name' )->escaped() .
72  "</th>
73  <th>" .
74  $this->msg( 'trackingcategories-desc' )->escaped() . "
75  </th>
76  </tr></thead>"
77  );
78 
79  $trackingCategories = $this->prepareTrackingCategoriesData();
80 
81  $batch = new LinkBatch();
82  foreach ( $trackingCategories as $catMsg => $data ) {
83  $batch->addObj( $data['msg'] );
84  foreach ( $data['cats'] as $catTitle ) {
85  $batch->addObj( $catTitle );
86  }
87  }
88  $batch->execute();
89 
90  foreach ( $trackingCategories as $catMsg => $data ) {
91  $allMsgs = [];
92  $catDesc = $catMsg . '-desc';
93 
94  $catMsgTitleText = Linker::link(
95  $data['msg'],
96  htmlspecialchars( $catMsg )
97  );
98 
99  foreach ( $data['cats'] as $catTitle ) {
100  $catTitleText = Linker::link(
101  $catTitle,
102  htmlspecialchars( $catTitle->getText() )
103  );
104  $allMsgs[] = $catTitleText;
105  }
106 
107  # Extra message, when no category was found
108  if ( !count( $allMsgs ) ) {
109  $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
110  }
111 
112  /*
113  * Show category description if it exists as a system message
114  * as category-name-desc
115  */
116  $descMsg = $this->msg( $catDesc );
117  if ( $descMsg->isBlank() ) {
118  $descMsg = $this->msg( 'trackingcategories-nodesc' );
119  }
120 
121  $this->getOutput()->addHTML(
122  Html::openElement( 'tr' ) .
123  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
124  $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
125  Html::closeElement( 'td' ) .
126  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
127  $catMsgTitleText .
128  Html::closeElement( 'td' ) .
129  Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
130  $descMsg->parse() .
131  Html::closeElement( 'td' ) .
132  Html::closeElement( 'tr' )
133  );
134  }
135  $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
136  }
137 
142  private function prepareTrackingCategoriesData() {
143  $categories = array_merge(
144  self::$coreTrackingCategories,
145  ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
146  $this->getConfig()->get( 'TrackingCategories' ) // deprecated
147  );
148  $trackingCategories = [];
149  foreach ( $categories as $catMsg ) {
150  /*
151  * Check if the tracking category varies by namespace
152  * Otherwise only pages in the current namespace will be displayed
153  * If it does vary, show pages considering all namespaces
154  */
155  $msgObj = $this->msg( $catMsg )->inContentLanguage();
156  $allCats = [];
157  $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
158  if ( !$catMsgTitle ) {
159  continue;
160  }
161 
162  // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
163  // False positives are ok, this is just an efficiency shortcut
164  if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
166  foreach ( $ns as $namesp ) {
167  $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
168  if ( !$tempTitle ) {
169  continue;
170  }
171  $catName = $msgObj->title( $tempTitle )->text();
172  # Allow tracking categories to be disabled by setting them to "-"
173  if ( $catName !== '-' ) {
174  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
175  if ( $catTitle ) {
176  $allCats[] = $catTitle;
177  }
178  }
179  }
180  } else {
181  $catName = $msgObj->text();
182  # Allow tracking categories to be disabled by setting them to "-"
183  if ( $catName !== '-' ) {
184  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
185  if ( $catTitle ) {
186  $allCats[] = $catTitle;
187  }
188  }
189  }
190  $trackingCategories[$catMsg] = [
191  'cats' => $allCats,
192  'msg' => $catMsgTitle,
193  ];
194  }
195 
196  return $trackingCategories;
197  }
198 
199  protected function getGroupName() {
200  return 'pages';
201  }
202 }
static array $coreTrackingCategories
Tracking categories that exist in core.
static closeElement($element)
Returns "</$element>".
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:32
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:527
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:203
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.