From 0ca156364425e959e8447ee00f9abd555c9904ae Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 3 Nov 2016 11:06:20 -0700 Subject: [PATCH] Add tracking categories when magic links are used This adds 3 tracking categories, one for each type of magic link (ISBN, RFC, PMID). This will allow wikis to gauge usage and identify pages that need migrating. These will only show up if the respective magic links are enabled via $wgEnableMagicLinks. Change-Id: Ic483f0c493112bf6373e1b37961e1241c20c3582 --- includes/parser/Parser.php | 4 ++++ includes/specials/SpecialTrackingCategories.php | 13 +++++++++++++ languages/i18n/en.json | 6 ++++++ languages/i18n/qqq.json | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 27c95358a0..eafccd936b 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1446,6 +1446,7 @@ class Parser { $keyword = 'RFC'; $urlmsg = 'rfcurl'; $cssClass = 'mw-magiclink-rfc'; + $trackingCat = 'magiclink-tracking-rfc'; $id = $m[5]; } elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) { if ( !$this->mOptions->getMagicPMIDLinks() ) { @@ -1454,12 +1455,14 @@ class Parser { $keyword = 'PMID'; $urlmsg = 'pubmedurl'; $cssClass = 'mw-magiclink-pmid'; + $trackingCat = 'magiclink-tracking-pmid'; $id = $m[5]; } else { throw new MWException( __METHOD__ . ': unrecognised match type "' . substr( $m[0], 0, 20 ) . '"' ); } $url = wfMessage( $urlmsg, $id )->inContentLanguage()->text(); + $this->addTrackingCategory( $trackingCat ); return Linker::makeExternalLink( $url, "{$keyword} {$id}", true, $cssClass, [], $this->mTitle ); } elseif ( isset( $m[6] ) && $m[6] !== '' && $this->mOptions->getMagicISBNLinks() @@ -1473,6 +1476,7 @@ class Parser { ' ' => '', 'x' => 'X', ] ); + $this->addTrackingCategory( 'magiclink-tracking-isbn' ); return $this->getLinkRenderer()->makeKnownLink( SpecialPage::getTitleFor( 'Booksources', $num ), "ISBN $isbn", diff --git a/includes/specials/SpecialTrackingCategories.php b/includes/specials/SpecialTrackingCategories.php index 4c892b29ee..3b502f8960 100644 --- a/includes/specials/SpecialTrackingCategories.php +++ b/includes/specials/SpecialTrackingCategories.php @@ -145,6 +145,19 @@ class SpecialTrackingCategories extends SpecialPage { ExtensionRegistry::getInstance()->getAttribute( 'TrackingCategories' ), $this->getConfig()->get( 'TrackingCategories' ) // deprecated ); + + // Only show magic link tracking categories if they are enabled + $enableMagicLinks = $this->getConfig()->get( 'EnableMagicLinks' ); + if ( $enableMagicLinks['ISBN'] ) { + $categories[] = 'magiclink-tracking-isbn'; + } + if ( $enableMagicLinks['RFC'] ) { + $categories[] = 'magiclink-tracking-rfc'; + } + if ( $enableMagicLinks['PMID'] ) { + $categories[] = 'magiclink-tracking-pmid'; + } + $trackingCategories = []; foreach ( $categories as $catMsg ) { /* diff --git a/languages/i18n/en.json b/languages/i18n/en.json index c7599845ab..767e1fac2e 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1935,6 +1935,12 @@ "booksources-search": "Search", "booksources-text": "Below is a list of links to other sites that sell new and used books, and may also have further information about books you are looking for:", "booksources-invalid-isbn": "The given ISBN does not appear to be valid; check for errors copying from the original source.", + "magiclink-tracking-rfc": "Pages using RFC magic links", + "magiclink-tracking-rfc-desc": "This page uses RFC magic links. See [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Magic_links mediawiki.org] on how to migrate.", + "magiclink-tracking-pmid": "Pages using PMID magic links", + "magiclink-tracking-pmid-desc": "This page uses PMID magic links. See [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Magic_links mediawiki.org] on how to migrate.", + "magiclink-tracking-isbn": "Pages using ISBN magic links", + "magiclink-tracking-isbn-desc": "This page uses ISBN magic links. See [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Magic_links mediawiki.org] on how to migrate.", "rfcurl": "//tools.ietf.org/html/rfc$1", "pubmedurl": "//www.ncbi.nlm.nih.gov/pubmed/$1?dopt=Abstract", "specialloguserlabel": "Performer:", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index fe44a2b13e..261cead92e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2119,6 +2119,12 @@ "booksources-search": "Search button in [[Special:BookSources]]\n\n{{Identical|Search}}", "booksources-text": "Used in [[Special:BookSources/1]].\n\nThis message is followed by a list of links to other sites.\n\nSee also:\n* {{msg-mw|Booksources|title}}\n* {{msg-mw|Booksources-text|text}}", "booksources-invalid-isbn": "This message is displayed after an invalid ISBN is entered on [[Special:Booksources]].", + "magiclink-tracking-rfc": "Name of the [[mw:Special:MyLanguage/Help:Tracking categories|tracking category]] where pages that use RFC magic links will be added.", + "magiclink-tracking-rfc-desc": "Description of the tracking category {{mw-msg|magiclink-tracking-rfc}}", + "magiclink-tracking-pmid": "Name of the [[mw:Special:MyLanguage/Help:Tracking categories|tracking category]] where pages that use PMID magic links will be added.", + "magiclink-tracking-pmid-desc": "Description of the tracking category {{mw-msg|magiclink-tracking-pmid}}", + "magiclink-tracking-isbn": "Name of the [[mw:Special:MyLanguage/Help:Tracking categories|tracking category]] where pages that use ISBN magic links will be added.", + "magiclink-tracking-isbn-desc": "Description of the tracking category {{mw-msg|magiclink-tracking-isbn}}", "rfcurl": "{{notranslate}}\nParameters:\n* $1 - RFC number\nSee also:\n* {{msg-mw|Pubmedurl}}", "pubmedurl": "{{notranslate}}\nParameters:\n* $1 - Pubmed number\nSee also:\n* {{msg-mw|Rfcurl}}", "specialloguserlabel": "Used in [[Special:Log]] as a label for an input field with which the log can be filtered for entries describing actions ''performed'' by the specified user. \"Carried out\" and \"done\" are possible alternatives for \"performed\".", -- 2.20.1