34use Psr\Log\LoggerInterface;
56 private $namespaceInfo;
62 private $extensionRegistry;
72 private const CORE_TRACKING_CATEGORIES = [
73 'broken-file-category',
74 'duplicate-args-category',
75 'expansion-depth-exceeded-category',
76 'expensive-parserfunction-category',
77 'hidden-category-category',
79 'node-count-exceeded-category',
81 'nonnumeric-formatnum',
82 'post-expand-template-argument-category',
83 'post-expand-template-inclusion-category',
84 'restricted-displaytitle-ignored',
85 # template-equals-category is unused in MW>=1.39, but the category
86 # can be left around for a major release or so for an easier
87 # transition for anyone who didn't do the cleanup. T91154
88 'template-equals-category',
89 'template-loop-category',
90 'unstrip-depth-category',
91 'unstrip-size-category',
104 LoggerInterface $logger
107 $this->options = $options;
108 $this->namespaceInfo = $namespaceInfo;
109 $this->titleParser = $titleParser;
110 $this->logger = $logger;
127 $categories = array_merge(
128 self::CORE_TRACKING_CATEGORIES,
135 if ( $enableMagicLinks[
'ISBN'] ) {
136 $categories[] =
'magiclink-tracking-isbn';
138 if ( $enableMagicLinks[
'RFC'] ) {
139 $categories[] =
'magiclink-tracking-rfc';
141 if ( $enableMagicLinks[
'PMID'] ) {
142 $categories[] =
'magiclink-tracking-pmid';
145 $trackingCategories = [];
146 foreach ( $categories as $catMsg ) {
154 $msgObj =
wfMessage( $catMsg )->inContentLanguage();
156 $catMsgTitle = $this->titleParser->makeTitleValueSafe(
NS_MEDIAWIKI, $catMsg );
157 if ( !$catMsgTitle ) {
163 if ( strpos( $msgObj->plain(),
'{{' ) !==
false ) {
164 $ns = $this->namespaceInfo->getValidNamespaces();
165 foreach ( $ns as $namesp ) {
166 $tempTitle = $this->titleParser->makeTitleValueSafe( $namesp, $catMsg );
172 $tempTitle = Title::newFromLinkTarget( $tempTitle );
173 $catName = $msgObj->page( $tempTitle )->text();
174 # Allow tracking categories to be disabled by setting them to "-"
175 if ( $catName !==
'-' ) {
176 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
178 $allCats[] = $catTitle;
183 $catName = $msgObj->text();
184 # Allow tracking categories to be disabled by setting them to "-"
185 if ( $catName !==
'-' ) {
186 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
188 $allCats[] = $catTitle;
192 $trackingCategories[$catMsg] = [
194 'msg' => $catMsgTitle,
198 return $trackingCategories;
210 if ( !$contextPage ) {
211 $this->logger->debug(
"Not adding tracking category $msg to missing page!" );
216 $this->logger->debug(
"Not adding tracking category $msg to special page!" );
223 ->page( $contextPage )
224 ->inContentLanguage()
227 # Allow tracking categories to be disabled by setting them to "-"
228 if ( $cat ===
'-' ) {
232 $containerCategory = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $cat );
233 if ( $containerCategory ===
null ) {
234 $this->logger->debug(
"[[MediaWiki:$msg]] is not a valid title!" );
237 return $containerCategory;
258 $categoryPage = $this->resolveTrackingCategory( $msg, $contextPage );
259 if ( $categoryPage ===
null ) {
262 $parserOutput->
addCategory( $categoryPage->getDBkey() );
268class_alias( TrackingCategories::class,
'TrackingCategories' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
Load JSON files, and uses a Processor to extract information.
A class containing constants representing the names of configuration variables.
const EnableMagicLinks
Name constant for the EnableMagicLinks setting, for use with Config::get()
const TrackingCategories
Name constant for the TrackingCategories setting, for use with Config::get()