33 use Psr\Log\LoggerInterface;
55 private $namespaceInfo;
61 private $extensionRegistry;
71 private const CORE_TRACKING_CATEGORIES = [
72 'broken-file-category',
73 'duplicate-args-category',
74 'expansion-depth-exceeded-category',
75 'expensive-parserfunction-category',
76 'hidden-category-category',
78 'node-count-exceeded-category',
80 'nonnumeric-formatnum',
81 'post-expand-template-argument-category',
82 'post-expand-template-inclusion-category',
83 'restricted-displaytitle-ignored',
84 # template-equals-category is unused in MW>=1.39, but the category
85 # can be left around for a major release or so for an easier
86 # transition for anyone who didn't do the cleanup. T91154
87 'template-equals-category',
88 'template-loop-category',
89 'unstrip-depth-category',
90 'unstrip-size-category',
103 LoggerInterface $logger
106 $this->options = $options;
107 $this->namespaceInfo = $namespaceInfo;
108 $this->titleParser = $titleParser;
109 $this->logger = $logger;
125 public function getTrackingCategories() {
126 $categories = array_merge(
127 self::CORE_TRACKING_CATEGORIES,
134 if ( $enableMagicLinks[
'ISBN'] ) {
135 $categories[] =
'magiclink-tracking-isbn';
137 if ( $enableMagicLinks[
'RFC'] ) {
138 $categories[] =
'magiclink-tracking-rfc';
140 if ( $enableMagicLinks[
'PMID'] ) {
141 $categories[] =
'magiclink-tracking-pmid';
144 $trackingCategories = [];
145 foreach ( $categories as $catMsg ) {
153 $msgObj =
wfMessage( $catMsg )->inContentLanguage();
155 $catMsgTitle = $this->titleParser->makeTitleValueSafe(
NS_MEDIAWIKI, $catMsg );
156 if ( !$catMsgTitle ) {
162 if ( strpos( $msgObj->plain(),
'{{' ) !==
false ) {
163 $ns = $this->namespaceInfo->getValidNamespaces();
164 foreach ( $ns as $namesp ) {
165 $tempTitle = $this->titleParser->makeTitleValueSafe( $namesp, $catMsg );
172 $catName = $msgObj->page( $tempTitle )->text();
173 # Allow tracking categories to be disabled by setting them to "-"
174 if ( $catName !==
'-' ) {
175 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
177 $allCats[] = $catTitle;
182 $catName = $msgObj->text();
183 # Allow tracking categories to be disabled by setting them to "-"
184 if ( $catName !==
'-' ) {
185 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
187 $allCats[] = $catTitle;
191 $trackingCategories[$catMsg] = [
193 'msg' => $catMsgTitle,
197 return $trackingCategories;
208 public function resolveTrackingCategory(
string $msg, ?PageReference $contextPage ): ?LinkTarget {
209 if ( !$contextPage ) {
210 $this->logger->debug(
"Not adding tracking category $msg to missing page!" );
214 if ( $contextPage->getNamespace() ===
NS_SPECIAL ) {
215 $this->logger->debug(
"Not adding tracking category $msg to special page!" );
222 ->page( $contextPage )
223 ->inContentLanguage()
226 # Allow tracking categories to be disabled by setting them to "-"
227 if ( $cat ===
'-' ) {
231 $containerCategory = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $cat );
232 if ( $containerCategory ===
null ) {
233 $this->logger->debug(
"[[MediaWiki:$msg]] is not a valid title!" );
236 return $containerCategory;
256 public function addTrackingCategory(
ParserOutput $parserOutput,
string $msg, ?PageReference $contextPage ): bool {
257 $categoryPage = $this->resolveTrackingCategory( $msg, $contextPage );
258 if ( $categoryPage ===
null ) {
262 $categoryPage->getDBkey(),
272 class_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()
getPageProperty(string $name)
Look up a page property.
addCategory( $c, $sort='')
Add a category.