32 use Psr\Log\LoggerInterface;
54 private $namespaceInfo;
60 private $extensionRegistry;
70 private const CORE_TRACKING_CATEGORIES = [
71 'broken-file-category',
72 'duplicate-args-category',
73 'expansion-depth-exceeded-category',
74 'expensive-parserfunction-category',
75 'hidden-category-category',
77 'node-count-exceeded-category',
79 'nonnumeric-formatnum',
80 'post-expand-template-argument-category',
81 'post-expand-template-inclusion-category',
82 'restricted-displaytitle-ignored',
83 # template-equals-category is unused in MW>=1.39, but the category
84 # can be left around for a major release or so for an easier
85 # transition for anyone who didn't do the cleanup. T91154
86 'template-equals-category',
87 'template-loop-category',
88 'unstrip-depth-category',
89 'unstrip-size-category',
102 LoggerInterface $logger
105 $this->options = $options;
106 $this->namespaceInfo = $namespaceInfo;
107 $this->titleParser = $titleParser;
108 $this->logger = $logger;
124 public function getTrackingCategories() {
125 $categories = array_merge(
126 self::CORE_TRACKING_CATEGORIES,
133 if ( $enableMagicLinks[
'ISBN'] ) {
134 $categories[] =
'magiclink-tracking-isbn';
136 if ( $enableMagicLinks[
'RFC'] ) {
137 $categories[] =
'magiclink-tracking-rfc';
139 if ( $enableMagicLinks[
'PMID'] ) {
140 $categories[] =
'magiclink-tracking-pmid';
143 $trackingCategories = [];
144 foreach ( $categories as $catMsg ) {
152 $msgObj =
wfMessage( $catMsg )->inContentLanguage();
154 $catMsgTitle = $this->titleParser->makeTitleValueSafe(
NS_MEDIAWIKI, $catMsg );
155 if ( !$catMsgTitle ) {
161 if ( strpos( $msgObj->plain(),
'{{' ) !==
false ) {
162 $ns = $this->namespaceInfo->getValidNamespaces();
163 foreach ( $ns as $namesp ) {
164 $tempTitle = $this->titleParser->makeTitleValueSafe( $namesp, $catMsg );
171 $catName = $msgObj->page( $tempTitle )->text();
172 # Allow tracking categories to be disabled by setting them to "-"
173 if ( $catName !==
'-' ) {
174 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
176 $allCats[] = $catTitle;
181 $catName = $msgObj->text();
182 # Allow tracking categories to be disabled by setting them to "-"
183 if ( $catName !==
'-' ) {
184 $catTitle = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $catName );
186 $allCats[] = $catTitle;
190 $trackingCategories[$catMsg] = [
192 'msg' => $catMsgTitle,
196 return $trackingCategories;
207 public function resolveTrackingCategory(
string $msg, ?PageReference $contextPage ): ?LinkTarget {
208 if ( !$contextPage ) {
209 $this->logger->debug(
"Not adding tracking category $msg to missing page!" );
213 if ( $contextPage->getNamespace() ===
NS_SPECIAL ) {
214 $this->logger->debug(
"Not adding tracking category $msg to special page!" );
221 ->page( $contextPage )
222 ->inContentLanguage()
225 # Allow tracking categories to be disabled by setting them to "-"
226 if ( $cat ===
'-' ) {
230 $containerCategory = $this->titleParser->makeTitleValueSafe(
NS_CATEGORY, $cat );
231 if ( $containerCategory ===
null ) {
232 $this->logger->debug(
"[[MediaWiki:$msg]] is not a valid title!" );
235 return $containerCategory;
246 public function addTrackingCategory(
ParserOutput $parserOutput,
string $msg, ?PageReference $contextPage ): bool {
247 $categoryPage = $this->resolveTrackingCategory( $msg, $contextPage );
248 if ( $categoryPage ===
null ) {
252 $categoryPage->getDBkey(),
259 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()
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.
A title parser service for MediaWiki.