Add tracking categories when magic links are used
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 3 Nov 2016 18:06:20 +0000 (11:06 -0700)
committerTTO <at.light@live.com.au>
Fri, 4 Nov 2016 02:20:05 +0000 (02:20 +0000)
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
includes/specials/SpecialTrackingCategories.php
languages/i18n/en.json
languages/i18n/qqq.json

index 27c9535..eafccd9 100644 (file)
@@ -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",
index 4c892b2..3b502f8 100644 (file)
@@ -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 ) {
                        /*
index c759984..767e1fa 100644 (file)
        "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:",
index fe44a2b..261cead 100644 (file)
        "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\".",