33use Psr\Log\LoggerInterface;
34use Wikimedia\Parsoid\Core\ContentMetadataCollector;
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',
92 'bad-language-code-category',
106 LoggerInterface $logger
109 $this->options = $options;
110 $this->namespaceInfo = $namespaceInfo;
111 $this->titleParser = $titleParser;
112 $this->logger = $logger;
115 $this->extensionRegistry = ExtensionRegistry::getInstance();
129 $categories = array_merge(
130 self::CORE_TRACKING_CATEGORIES,
137 if ( $enableMagicLinks[
'ISBN'] ) {
138 $categories[] =
'magiclink-tracking-isbn';
140 if ( $enableMagicLinks[
'RFC'] ) {
141 $categories[] =
'magiclink-tracking-rfc';
143 if ( $enableMagicLinks[
'PMID'] ) {
144 $categories[] =
'magiclink-tracking-pmid';
147 $trackingCategories = [];
148 foreach ( $categories as $catMsg ) {
156 $msgObj =
wfMessage( $catMsg )->inContentLanguage();
158 $catMsgTitle = $this->titleParser->makeTitleValueSafe(
NS_MEDIAWIKI, $catMsg );
159 if ( !$catMsgTitle ) {
165 if ( strpos( $msgObj->plain(),
'{{' ) !==
false ) {
166 $ns = $this->namespaceInfo->getValidNamespaces();
167 foreach ( $ns as $namesp ) {
168 $tempTitle = $this->titleParser->makeTitleValueSafe( $namesp, $catMsg );
174 $tempTitle = Title::newFromLinkTarget( $tempTitle );
175 $catName = $msgObj->page( $tempTitle )->text();
176 # Allow tracking categories to be disabled by setting them to "-"
177 if ( $catName !==
'-' ) {
178 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
180 $allCats[] = $catTitle;
185 $catName = $msgObj->text();
186 # Allow tracking categories to be disabled by setting them to "-"
187 if ( $catName !==
'-' ) {
188 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
190 $allCats[] = $catTitle;
194 $trackingCategories[$catMsg] = [
196 'msg' => $catMsgTitle,
200 return $trackingCategories;
212 if ( !$contextPage ) {
213 $this->logger->debug(
"Not adding tracking category $msg to missing page!" );
218 $this->logger->debug(
"Not adding tracking category $msg to special page!" );
225 ->page( $contextPage )
226 ->inContentLanguage()
229 # Allow tracking categories to be disabled by setting them to "-"
230 if ( $cat ===
'-' ) {
234 $containerCategory = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $cat );
235 if ( $containerCategory ===
null ) {
236 $this->logger->debug(
"[[MediaWiki:$msg]] is not a valid title!" );
239 return $containerCategory;
260 ContentMetadataCollector $parserOutput,
264 $categoryPage = $this->resolveTrackingCategory( $msg, $contextPage );
265 if ( $categoryPage ===
null ) {
268 $parserOutput->addCategory( $categoryPage );
274class_alias( TrackingCategories::class,
'TrackingCategories' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
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()