MediaWiki  1.29.2
TrackingCategories.php
Go to the documentation of this file.
1 <?php
28  private $config;
29 
35  private static $coreTrackingCategories = [
36  'index-category',
37  'noindex-category',
38  'duplicate-args-category',
39  'expensive-parserfunction-category',
40  'post-expand-template-argument-category',
41  'post-expand-template-inclusion-category',
42  'hidden-category-category',
43  'broken-file-category',
44  'node-count-exceeded-category',
45  'expansion-depth-exceeded-category',
46  'restricted-displaytitle-ignored',
47  'deprecated-self-close-category',
48  'template-loop-category',
49  ];
50 
54  public function __construct( Config $config ) {
55  $this->config = $config;
56  }
57 
62  public function getTrackingCategories() {
63  $categories = array_merge(
64  self::$coreTrackingCategories,
65  ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
66  $this->config->get( 'TrackingCategories' ) // deprecated
67  );
68 
69  // Only show magic link tracking categories if they are enabled
70  $enableMagicLinks = $this->config->get( 'EnableMagicLinks' );
71  if ( $enableMagicLinks['ISBN'] ) {
72  $categories[] = 'magiclink-tracking-isbn';
73  }
74  if ( $enableMagicLinks['RFC'] ) {
75  $categories[] = 'magiclink-tracking-rfc';
76  }
77  if ( $enableMagicLinks['PMID'] ) {
78  $categories[] = 'magiclink-tracking-pmid';
79  }
80 
81  $trackingCategories = [];
82  foreach ( $categories as $catMsg ) {
83  /*
84  * Check if the tracking category varies by namespace
85  * Otherwise only pages in the current namespace will be displayed
86  * If it does vary, show pages considering all namespaces
87  */
88  $msgObj = wfMessage( $catMsg )->inContentLanguage();
89  $allCats = [];
90  $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
91  if ( !$catMsgTitle ) {
92  continue;
93  }
94 
95  // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
96  // False positives are ok, this is just an efficiency shortcut
97  if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
99  foreach ( $ns as $namesp ) {
100  $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
101  if ( !$tempTitle ) {
102  continue;
103  }
104  $catName = $msgObj->title( $tempTitle )->text();
105  # Allow tracking categories to be disabled by setting them to "-"
106  if ( $catName !== '-' ) {
107  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
108  if ( $catTitle ) {
109  $allCats[] = $catTitle;
110  }
111  }
112  }
113  } else {
114  $catName = $msgObj->text();
115  # Allow tracking categories to be disabled by setting them to "-"
116  if ( $catName !== '-' ) {
117  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
118  if ( $catTitle ) {
119  $allCats[] = $catTitle;
120  }
121  }
122  }
123  $trackingCategories[$catMsg] = [
124  'cats' => $allCats,
125  'msg' => $catMsgTitle,
126  ];
127  }
128 
129  return $trackingCategories;
130  }
131 }
TrackingCategories\$coreTrackingCategories
static array $coreTrackingCategories
Tracking categories that exist in core.
Definition: TrackingCategories.php:35
MWNamespace\getValidNamespaces
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
Definition: MWNamespace.php:264
TrackingCategories\getTrackingCategories
getTrackingCategories()
Read the global and extract title objects from the corresponding messages.
Definition: TrackingCategories.php:62
TrackingCategories\$config
Config $config
Definition: TrackingCategories.php:28
php
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
ExtensionRegistry\getInstance
static getInstance()
Definition: ExtensionRegistry.php:80
Config
Interface for configuration instances.
Definition: Config.php:28
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:76
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
TrackingCategories
This class performs some operations related to tracking categories, such as creating a list of all su...
Definition: TrackingCategories.php:26
as
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
TrackingCategories\__construct
__construct(Config $config)
Definition: TrackingCategories.php:54
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:70
array
the array() calling protocol came about after MediaWiki 1.4rc1.