jenkins-bot has submitted this change and it was merged.
Change subject: Round-trip relative and pipe-tricky links
......................................................................
Round-trip relative and pipe-tricky links
* Add a title and ns member to env.page
* Use that to check whether a page is in a namespace that has subpages
enabled
* Add a test for links of the form [[../../foo]] and [[../../foo/]]
* Round-trip relative links like this
Change-Id: I04acb2e87fd6ae7354da451a7d36a3bc65e876c8
---
M js/lib/ext.core.LinkHandler.js
M js/lib/mediawiki.WikitextSerializer.js
M js/lib/mediawiki.parser.environment.js
M js/tests/parserTests.txt
4 files changed, 39 insertions(+), 7 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index d30005c..d79360c 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -306,7 +306,8 @@
morecontent = morecontent.replace(/^:/, '');
// Try to match labeling in core
- if ( env.page.meta.ns === undefined ||
env.conf.wiki.namespacesWithSubpages[ env.page.meta.ns ] ) {
+ if ( env.page.ns !== undefined &&
+ env.conf.wiki.namespacesWithSubpages[
env.page.ns ] ) {
var match = morecontent.match( /^\/(.*)\/$/ );
if ( match ) {
morecontent = match[1];
@@ -314,11 +315,11 @@
// If a there's a trailing slash, don't resolve
title
// making sure the second to last character
isn't a
// forward slash, for cases like: ../../////
- match = morecontent.match( /^(\.\.\/)+(.*[^/])\/$/ );
+ match = morecontent.match( /^(\.\.\/)+(.*?)\/$/
);
if ( match ) {
morecontent = match[2];
- } else if ( env.page.meta.ns !== undefined ) {
- morecontent = env.resolveTitle(
morecontent, env.page.meta.ns );
+ } else {
+ morecontent = env.resolveTitle(
morecontent, env.page.ns );
}
}
}
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index d9048b2..6f93ed6 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -1587,6 +1587,15 @@
// any colon escape
env.normalizeTitle(
contentString, true ) ===
Util.decodeURI(
strippedTargetValue ) ||
+ // Relative link
+ (
env.conf.wiki.namespacesWithSubpages[ env.page.ns ] &&
+ (
/^\.\.\/.*[^\/]$/.test(strippedTargetValue) &&
+
env.resolveTitle(strippedTargetValue, env.page.ns) ===
+ contentString ) ||
+ (
/^\.\.\/.*?\/$/.test(strippedTargetValue) &&
+
strippedTargetValue.replace(/^(?:\.\.\/)+(.*?)\/$/, '$1') ===
+ contentString )
+ ) ||
// normalize with underscores
for comparison with href
env.normalizeTitle(
contentString ) ===
Util.decodeURI( linkData.href )
@@ -1625,7 +1634,6 @@
// Get <nowiki/> escapes to protect against unwanted
prefix / tail
var escapes = this.getLinkPrefixTailEscapes(node, env),
linkTarget;
-
if ( canUseSimple ) {
diff --git a/js/lib/mediawiki.parser.environment.js
b/js/lib/mediawiki.parser.environment.js
index eec830f..3416e10 100644
--- a/js/lib/mediawiki.parser.environment.js
+++ b/js/lib/mediawiki.parser.environment.js
@@ -3,7 +3,8 @@
var WikiConfig = require( './mediawiki.WikiConfig.js' ).WikiConfig,
ParsoidConfig = require( './mediawiki.ParsoidConfig.js' ).ParsoidConfig,
ConfigRequest = require( './mediawiki.ApiRequest.js' ).ConfigRequest,
- $ = require( './fakejquery' );
+ $ = require( './fakejquery' ),
+ Title = require('./mediawiki.Title.js').Title;
function Tracer(env) {
this.env = env;
@@ -69,7 +70,9 @@
relativeLinkPrefix: '',
id: null,
src: null,
- dom: null
+ dom: null,
+ ns: null,
+ title: null // a full Title object
};
// Configuration
@@ -206,6 +209,11 @@
* @param {string} pageName
*/
MWParserEnvironment.prototype.setPageName = function ( pageName ) {
+ // Create a title from the pageName
+ var title = Title.fromPrefixedText(this, pageName);
+ this.page.ns = title.ns.id;
+ this.page.title = title;
+
this.page.name = pageName;
// Construct a relative link prefix depending on the number of slashes
in
// pageName
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index a583457..4ef0ec0 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -8439,6 +8439,21 @@
</p>
!! end
+# TODO: make this PHP-parser compatible!
+!! test
+Relative subpage noslash link
+!! options
+parsoid=wt2wt,wt2html,html2html
+subpage title=[[Subpage test/1/2/3/4]]
+!!input
+[[../../subpage/]]
+
+[[../../subpage]]
+!! result
+<p><a rel="mw:WikiLink" href="Subpage_test/1/2/subpage/">subpage</a></p>
+<p><a rel="mw:WikiLink"
href="Subpage_test/1/2/subpage">Subpage_test/1/2/subpage</a></p>
+!! end
+
!! test
Disabled subpages
!! input
--
To view, visit https://gerrit.wikimedia.org/r/71754
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I04acb2e87fd6ae7354da451a7d36a3bc65e876c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits