26use Psr\Log\LoggerInterface;
39 MainConfigNames::TrackingCategories,
40 MainConfigNames::EnableMagicLinks,
47 private $namespaceInfo;
53 private $extensionRegistry;
63 private const CORE_TRACKING_CATEGORIES = [
64 'broken-file-category',
65 'duplicate-args-category',
66 'expansion-depth-exceeded-category',
67 'expensive-parserfunction-category',
68 'hidden-category-category',
70 'node-count-exceeded-category',
72 'nonnumeric-formatnum',
73 'post-expand-template-argument-category',
74 'post-expand-template-inclusion-category',
75 'restricted-displaytitle-ignored',
76 # template-equals-category is unused in MW>=1.39, but the category
77 # can be left around for a major release or so for an easier
78 # transition for anyone who didn't do the cleanup. T91154
79 'template-equals-category',
80 'template-loop-category',
81 'unstrip-depth-category',
82 'unstrip-size-category',
95 LoggerInterface $logger
98 $this->options = $options;
99 $this->namespaceInfo = $namespaceInfo;
100 $this->titleParser = $titleParser;
101 $this->logger = $logger;
104 $this->extensionRegistry = ExtensionRegistry::getInstance();
118 $categories = array_merge(
119 self::CORE_TRACKING_CATEGORIES,
120 $this->extensionRegistry->getAttribute( MainConfigNames::TrackingCategories ),
121 $this->options->get( MainConfigNames::TrackingCategories )
125 $enableMagicLinks = $this->options->get( MainConfigNames::EnableMagicLinks );
126 if ( $enableMagicLinks[
'ISBN'] ) {
127 $categories[] =
'magiclink-tracking-isbn';
129 if ( $enableMagicLinks[
'RFC'] ) {
130 $categories[] =
'magiclink-tracking-rfc';
132 if ( $enableMagicLinks[
'PMID'] ) {
133 $categories[] =
'magiclink-tracking-pmid';
136 $trackingCategories = [];
137 foreach ( $categories as $catMsg ) {
145 $msgObj =
wfMessage( $catMsg )->inContentLanguage();
147 $catMsgTitle = $this->titleParser->makeTitleValueSafe(
NS_MEDIAWIKI, $catMsg );
148 if ( !$catMsgTitle ) {
154 if ( strpos( $msgObj->plain(),
'{{' ) !==
false ) {
155 $ns = $this->namespaceInfo->getValidNamespaces();
156 foreach ( $ns as $namesp ) {
157 $tempTitle = $this->titleParser->makeTitleValueSafe( $namesp, $catMsg );
163 $tempTitle = Title::newFromLinkTarget( $tempTitle );
164 $catName = $msgObj->page( $tempTitle )->text();
165 # Allow tracking categories to be disabled by setting them to "-"
166 if ( $catName !==
'-' ) {
167 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
169 $allCats[] = $catTitle;
174 $catName = $msgObj->text();
175 # Allow tracking categories to be disabled by setting them to "-"
176 if ( $catName !==
'-' ) {
177 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
179 $allCats[] = $catTitle;
183 $trackingCategories[$catMsg] = [
185 'msg' => $catMsgTitle,
189 return $trackingCategories;
201 if ( !$contextPage ) {
202 $this->logger->debug(
"Not adding tracking category $msg to missing page!" );
207 $this->logger->debug(
"Not adding tracking category $msg to special page!" );
214 ->page( $contextPage )
215 ->inContentLanguage()
218 # Allow tracking categories to be disabled by setting them to "-"
219 if ( $cat ===
'-' ) {
223 $containerCategory = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $cat );
224 if ( $containerCategory ===
null ) {
225 $this->logger->debug(
"[[MediaWiki:$msg]] is not a valid title!" );
228 return $containerCategory;
240 $categoryPage = $this->resolveTrackingCategory( $msg, $contextPage );
241 if ( $categoryPage ===
null ) {
245 $categoryPage->getDBkey(),
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
The Registry loads JSON files, and uses a Processor to extract information from them.
A class containing constants representing the names of configuration variables.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
getPageProperty(string $name)
Look up a page property.
addCategory( $c, $sort='')
Add a category.
This class performs some operations related to tracking categories, such as creating a list of all su...
addTrackingCategory(ParserOutput $parserOutput, string $msg, ?PageReference $contextPage)
Add a tracking category to a ParserOutput.
__construct(ServiceOptions $options, NamespaceInfo $namespaceInfo, TitleParser $titleParser, LoggerInterface $logger)
getTrackingCategories()
Read the global and extract title objects from the corresponding messages.
const CONSTRUCTOR_OPTIONS
resolveTrackingCategory(string $msg, ?PageReference $contextPage)
Resolve a tracking category.
A title parser service for MediaWiki.