Subramanya Sastry has uploaded a new change for review.

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

Change subject: Remove support for constructing titles with explicit namespaces
......................................................................

Remove support for constructing titles with explicit namespaces

* Rely on mediawiki-title to construct a title with the right
  namespace as parsed from the title (while using a default
  namespace where one isn't available in the title).

* This fixes a bad parse of a link like [[Category:Project:Foo]]
  where both the colon separated prefixes are valid namespace ids.

* Added a parser test to verify this expectation.

Change-Id: I34211598d98decc87be7f1759b10138f02309f69
---
M lib/config/MWParserEnvironment.js
M lib/wt2html/tt/LinkHandler.js
M tests/parserTests.txt
3 files changed, 19 insertions(+), 11 deletions(-)


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

diff --git a/lib/config/MWParserEnvironment.js 
b/lib/config/MWParserEnvironment.js
index 74b7c7e..2de16aa 100644
--- a/lib/config/MWParserEnvironment.js
+++ b/lib/config/MWParserEnvironment.js
@@ -497,13 +497,13 @@
 };
 
 /* urlDecodedText will be in url-decoded form */
-MWParserEnvironment.prototype._makeTitle = function(urlDecodedText, ns, 
noExceptions) {
+MWParserEnvironment.prototype._makeTitle = function(urlDecodedText, defaultNS, 
noExceptions) {
        try {
                if (this.page && /^(\#|\/|\.\.\/)/.test(urlDecodedText)) {
-                       ns = this.page.ns;
+                       defaultNS = this.page.ns;
                }
                urlDecodedText = this.resolveTitle(urlDecodedText);
-               return Title.newFromText(urlDecodedText, 
this.conf.wiki.siteInfo, ns);
+               return Title.newFromText(urlDecodedText, 
this.conf.wiki.siteInfo, defaultNS);
        } catch (e) {
                if (noExceptions) {
                        return null;
@@ -515,13 +515,13 @@
 
 /* text might have url-encoded entities that need url-decoding */
 /* See: Title::newFromText in mediawiki. */
-MWParserEnvironment.prototype.makeTitleFromText = function(str, ns, 
noExceptions) {
-       return this._makeTitle(Util.decodeURI(str), ns, noExceptions);
+MWParserEnvironment.prototype.makeTitleFromText = function(str, defaultNS, 
noExceptions) {
+       return this._makeTitle(Util.decodeURI(str), defaultNS, noExceptions);
 };
 
 /* See: Title::newFromURL in mediawiki. */
-MWParserEnvironment.prototype.makeTitleFromURLDecodedStr = function(str, ns, 
noExceptions) {
-       return this._makeTitle(str, ns, noExceptions);
+MWParserEnvironment.prototype.makeTitleFromURLDecodedStr = function(str, 
defaultNS, noExceptions) {
+       return this._makeTitle(str, defaultNS, noExceptions);
 };
 
 MWParserEnvironment.prototype.makeLink = function(title) {
diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js
index c230eee..e70dcd7 100644
--- a/lib/wt2html/tt/LinkHandler.js
+++ b/lib/wt2html/tt/LinkHandler.js
@@ -100,11 +100,11 @@
                var ns = env.conf.wiki.namespaceIds.hasOwnProperty(nnn) ? 
env.conf.wiki.namespaceIds[nnn] : undefined;
                // also check for url to protect against [[constructor:foo]]
                if (ns !== undefined) {
-                       info.title = 
env.makeTitleFromURLDecodedStr(title.replace(/^[^:]+:/, ''), ns);
+                       info.title = env.makeTitleFromURLDecodedStr(title);
                } else if (interwikiInfo && interwikiInfo.localinterwiki !== 
undefined) {
                        if (hrefBits[2] === '') {
                                // Empty title => main page (T66167)
-                               info.title = 
env.makeTitleFromURLDecodedStr(env.conf.wiki.mainpage, 0);
+                               info.title = 
env.makeTitleFromURLDecodedStr(env.conf.wiki.mainpage);
                        } else {
                                info.href = hrefBits[2];
                                // Recurse!
@@ -129,10 +129,10 @@
                                info.language = interwikiInfo;
                        }
                } else {
-                       info.title = env.makeTitleFromURLDecodedStr(title, 0);
+                       info.title = env.makeTitleFromURLDecodedStr(title);
                }
        } else {
-               info.title = env.makeTitleFromURLDecodedStr(title, 0);
+               info.title = env.makeTitleFromURLDecodedStr(title);
        }
 
        return info;
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index f8f22bb..0cabaaf 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -14945,6 +14945,14 @@
 !! end
 
 !! test
+Category links with multiple namespaces
+!! wikitext
+[[Category:Project:Foo]]
+!! html/parsoid
+<link rel="mw:PageProp/Category" href="./Category:Project:Foo" />
+!! end
+
+!! test
 Parsoid: Serialize link to category page with colon escape
 !! options
 parsoid

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

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

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

Reply via email to