MediaWiki  master
TrackingCategories.php
Go to the documentation of this file.
1 <?php
23 
31  private $config;
32 
38  private static $coreTrackingCategories = [
39  'index-category',
40  'noindex-category',
41  'duplicate-args-category',
42  'expensive-parserfunction-category',
43  'post-expand-template-argument-category',
44  'post-expand-template-inclusion-category',
45  'hidden-category-category',
46  'broken-file-category',
47  'node-count-exceeded-category',
48  'expansion-depth-exceeded-category',
49  'restricted-displaytitle-ignored',
50  'deprecated-self-close-category',
51  'template-loop-category',
52  ];
53 
57  public function __construct( Config $config ) {
58  $this->config = $config;
59  }
60 
65  public function getTrackingCategories() {
66  $categories = array_merge(
67  self::$coreTrackingCategories,
68  ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ),
69  $this->config->get( 'TrackingCategories' ) // deprecated
70  );
71 
72  // Only show magic link tracking categories if they are enabled
73  $enableMagicLinks = $this->config->get( 'EnableMagicLinks' );
74  if ( $enableMagicLinks['ISBN'] ) {
75  $categories[] = 'magiclink-tracking-isbn';
76  }
77  if ( $enableMagicLinks['RFC'] ) {
78  $categories[] = 'magiclink-tracking-rfc';
79  }
80  if ( $enableMagicLinks['PMID'] ) {
81  $categories[] = 'magiclink-tracking-pmid';
82  }
83 
84  $trackingCategories = [];
85  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
86  foreach ( $categories as $catMsg ) {
87  /*
88  * Check if the tracking category varies by namespace
89  * Otherwise only pages in the current namespace will be displayed
90  * If it does vary, show pages considering all namespaces
91  */
92  $msgObj = wfMessage( $catMsg )->inContentLanguage();
93  $allCats = [];
94  $catMsgTitle = Title::makeTitleSafe( NS_MEDIAWIKI, $catMsg );
95  if ( !$catMsgTitle ) {
96  continue;
97  }
98 
99  // Match things like {{NAMESPACE}} and {{NAMESPACENUMBER}}.
100  // False positives are ok, this is just an efficiency shortcut
101  if ( strpos( $msgObj->plain(), '{{' ) !== false ) {
102  $ns = $nsInfo->getValidNamespaces();
103  foreach ( $ns as $namesp ) {
104  $tempTitle = Title::makeTitleSafe( $namesp, $catMsg );
105  if ( !$tempTitle ) {
106  continue;
107  }
108  $catName = $msgObj->title( $tempTitle )->text();
109  # Allow tracking categories to be disabled by setting them to "-"
110  if ( $catName !== '-' ) {
111  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
112  if ( $catTitle ) {
113  $allCats[] = $catTitle;
114  }
115  }
116  }
117  } else {
118  $catName = $msgObj->text();
119  # Allow tracking categories to be disabled by setting them to "-"
120  if ( $catName !== '-' ) {
121  $catTitle = Title::makeTitleSafe( NS_CATEGORY, $catName );
122  if ( $catTitle ) {
123  $allCats[] = $catTitle;
124  }
125  }
126  }
127  $trackingCategories[$catMsg] = [
128  'cats' => $allCats,
129  'msg' => $catMsgTitle,
130  ];
131  }
132 
133  return $trackingCategories;
134  }
135 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 MediaWikiServices
Definition: injection.txt:23
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 use $formDescriptor instead 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
Interface for configuration instances.
Definition: Config.php:28
const NS_CATEGORY
Definition: Defines.php:74
static array $coreTrackingCategories
Tracking categories that exist in core.
__construct(Config $config)
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:68
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
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
getTrackingCategories()
Read the global and extract title objects from the corresponding messages.
This class performs some operations related to tracking categories, such as creating a list of all su...