Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189590
Change subject: WIP: Fix serializing categories without indent-pre protection
......................................................................
WIP: Fix serializing categories without indent-pre protection
* Account for variations in namespace names.
* Redirects shouldn't have any non-whitespace chars preceding them on
the page (T88081), so stripping seems necessary. Confirmed that the
php parser rejects,
<nowiki> </nowiki>#REDIRECT [[Test]]
* Still need to look into language links
Change-Id: Ib5dcd0fdddd616109d845aa80360049bf6610a34
---
M lib/mediawiki.WikiConfig.js
M lib/mediawiki.WikitextSerializer.js
M tests/parserTests.txt
3 files changed, 28 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/90/189590/1
diff --git a/lib/mediawiki.WikiConfig.js b/lib/mediawiki.WikiConfig.js
index 95c44f5..6411b68 100644
--- a/lib/mediawiki.WikiConfig.js
+++ b/lib/mediawiki.WikiConfig.js
@@ -91,12 +91,17 @@
'14': 'Category'
};
+ this._categoryRegexp = "Category";
+
// Namespace IDs that have subpages enabled.
this.namespacesWithSubpages = {};
for ( var nx = 0; nx < nkeys.length; nx++ ) {
nsid = nkeys[nx];
name = names[nsid];
this.namespaceNames[nsid] = name['*'];
+ if ( nsid === "14" && name['*'] !== "Category" ) {
+ this._categoryRegexp += "|" + name['*'];
+ }
this.namespaceIds[Util.normalizeNamespaceName(name['*'])] =
Number( nsid );
if ( name.canonical ) {
// XXX: is this b/c?
@@ -402,6 +407,17 @@
// Function hooks on this wiki, indexed by their normalized form
this.functionHooks = new Set(resultConf.functionhooks || []);
+ // Match a line containing just sol transparent link wikitext.
+ // Redirects should not contain any preceding non-whitespace chars.
+ this.solTransparentLinkLineRegexp = JSUtils.rejoin(
+ "^\\s*(?:(?:",
+ this._mwRegexps.redirect.source.slice(2, -2),
+ ")\\s+\\[\\[[^\\]]*?\\]\\]",
+ ")?(?:\\[\\[(?:",
+ this._categoryRegexp,
+ ")\\:[^\\]]*?\\]\\]|\\s)*$",
+ { flags: "i" }
+ );
}
/**
diff --git a/lib/mediawiki.WikitextSerializer.js
b/lib/mediawiki.WikitextSerializer.js
index a4f6049..9193ad1 100644
--- a/lib/mediawiki.WikitextSerializer.js
+++ b/lib/mediawiki.WikitextSerializer.js
@@ -1071,7 +1071,7 @@
return nextNode;
};
-function stripUnnecessaryIndentPreNowikis(wt) {
+function stripUnnecessaryIndentPreNowikis( env, wt ) {
var pieces =
wt.split(/^((?:<!--(?:[^\-]|-(?!->))*-->)*)(<nowiki>\s+<\/nowiki>)([^\n]*(?:\n|$))/m);
var out = pieces[0];
for (var i = 1; i < pieces.length; i += 4) {
@@ -1097,10 +1097,8 @@
}
}
- // Just spaces and categories, huh
- if ( reqd && /^(\[\[Category\:[^\]]*?\]\]|\s)*$/.test( rest ) )
{
- reqd = false;
- }
+ // Not required if just spaces and sol transparent links on the
line.
+ reqd = reqd &&
!env.conf.wiki.solTransparentLinkLineRegexp.test( rest );
if (!reqd) {
nowiki = nowiki.replace(/^<nowiki>(\s+)<\/nowiki>/,
'$1');
@@ -1275,7 +1273,7 @@
// rather than do one post-pass on the entire document.
//
// Strip excess/useless nowikis
- out = stripUnnecessaryIndentPreNowikis(out);
+ out = stripUnnecessaryIndentPreNowikis( this.env, out );
}
if (state.hasQuoteNowikis) {
// FIXME: Perhaps this can be done on a per-line basis
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index cbd569f..4a7cb7b 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -22404,13 +22404,18 @@
!! end
!! test
-New category doesn't need indent-pre nowiki protection
+New sol transparent links don't need indent-pre nowiki protection
!! options
parsoid=html2wt
+language=de
!! html
-<!-- this is great --> <link rel="mw:PageProp/Category"
href="./Category:Good" />
+ <link rel="mw:PageProp/redirect" href="./Main_Page">
+<!-- this is good --> <link rel="mw:PageProp/Category"
href="./Category:Good" />
+<!-- this is great --> <link rel="mw:PageProp/Category"
href="./Kategorie:Great" />
!! wikitext
-<!-- this is great --> [[Category:Good]]
+ #WEITERLEITUNG [[Main Page]]
+<!-- this is good --> [[Category:Good]]
+<!-- this is great --> [[Kategorie:Great]]
!! end
!! test
--
To view, visit https://gerrit.wikimedia.org/r/189590
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5dcd0fdddd616109d845aa80360049bf6610a34
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits