Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233655

Change subject: WTS support for localized ISBN magic links
......................................................................

WTS support for localized ISBN magic links

"Be generous in what you accept."

Bug: T110037
Change-Id: I5d000d8b63dafdfe0a2753069d3f0ac5b03b8829
---
M lib/mediawiki.ApiRequest.js
M lib/mediawiki.WikiConfig.js
2 files changed, 46 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/55/233655/1

diff --git a/lib/mediawiki.ApiRequest.js b/lib/mediawiki.ApiRequest.js
index aefb44f..ddeb0d7 100644
--- a/lib/mediawiki.ApiRequest.js
+++ b/lib/mediawiki.ApiRequest.js
@@ -865,6 +865,7 @@
                'interwikimap',
                'languages',
                'protocols',
+               'specialpagealiases',
        ];
        var apiargs = {
                format: 'json',
diff --git a/lib/mediawiki.WikiConfig.js b/lib/mediawiki.WikiConfig.js
index 983f3ab..e3d5f03 100644
--- a/lib/mediawiki.WikiConfig.js
+++ b/lib/mediawiki.WikiConfig.js
@@ -101,6 +101,7 @@
        };
 
        this._categoryRegexpSource = "Category";
+       this._specialAliases = ['Special'];
 
        // Namespace IDs that have subpages enabled.
        this.namespacesWithSubpages = {};
@@ -108,6 +109,9 @@
                nsid = nkeys[nx];
                name = names[nsid];
                this.namespaceNames[nsid] = name['*'];
+               if (nsid === '-1' && name['*'] !== 'Special') {
+                       this._specialAliases.push(name['*']);
+               }
                if (nsid === "14" && name['*'] !== "Category") {
                        this._categoryRegexpSource += "|" + name['*'];
                }
@@ -131,6 +135,9 @@
        var aliases = resultConf.namespacealiases;
        for (var ax = 0; ax < aliases.length; ax++) {
                
this.namespaceIds[Util.normalizeNamespaceName(aliases[ax]['*'])] = 
aliases[ax].id;
+               if (aliases[ax].id === -1) {
+                       this._specialAliases.push(aliases[ax]['*']);
+               }
        }
 
        // The interwikiMap maps prefixes to the corresponding information
@@ -280,17 +287,44 @@
        );
 
        // Special page names on this wiki, indexed by aliases.
-       this.specialPages = {};
-       // This path isn't necessary because we don't need special page aliases.
-       // Before you uncomment this, make sure you actually need it, and be 
sure to
-       // also add 'specialpagealiases' back into the API request for the 
config.
-       //  var specials = resultConf.specialpagealiases;
-       //  for ( var sx = 0; sx < specials.length; sx++ ) {
-       //      aliases = specials[sx].aliases;
-       //      for ( var sax = 0; sax < aliases.length; sax++ ) {
-       //              this.specialPages[aliases[sax]] = specials[sx].realname;
-       //      }
-       //  }
+       // We need these to recognize localized ISBN magic links.
+       var specialPages = this.specialPages = new Map();
+       (resultConf.specialpagealiases || []).forEach(function(special) {
+               specialPages.set(
+                       special.realname,
+                       new RegExp(
+                               special.aliases.map(function(a) {
+                                       return a.split(/[ 
_]/g).map(Util.escapeRegExp).join('[ _]');
+                               }).join('|')
+                       )
+               );
+       });
+
+       // Special case for localized ISBN ExtResourceMatcher
+       var isbnRegExp = new RegExp(
+               '^(?:(?:[.][.]?/)*)' +
+               '(?:' + this._specialAliases.map(function(a) {
+                       return a.split(/[ _]/g).map(Util.escapeRegExp).join('[ 
_]');
+               }).join('|') + '):(?:' +
+               (this.specialPages.get('Booksources') || /Booksources/).source +
+               ')/(\\d+[Xx]?)$',
+               // Strictly speaking, only the namespace is case insensitive.
+               // But we're feeling generous.
+               'i'
+       );
+       var superMatch = 
WikiConfig.prototype.ExtResourceURLPatternMatcher.match;
+       this.ExtResourceURLPatternMatcher = {
+               match: function(s) {
+                       var r = superMatch(s);
+                       if (!r) {
+                               var m = s.match(isbnRegExp);
+                               if (m) {
+                                       return [ 'ISBN', m[1] ];
+                               }
+                       }
+                       return r;
+               },
+       };
 
        // Regex for stripping useless stuff out of the regex messages
        var stripRegex = /^\/\^(.*)\$\//;

-- 
To view, visit https://gerrit.wikimedia.org/r/233655
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d000d8b63dafdfe0a2753069d3f0ac5b03b8829
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to