Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/204007
Change subject: Fix rtselser in roundtrip-test.js
......................................................................
Fix rtselser in roundtrip-test.js
* Remove fetchWT from parsoidConfig; it just isn't being used.
* Force clients to supply the original html when using selser in the v2
api. v1 uses the convoluted fallback mechanism in the
SelectiveSerializer to fetch and parse source as necessary.
* However, keep the hack RESTBase is using to fetch the source.
* Going forward, we should decide on and document the behaviour we want
to support. There are some tests around this area but it all seems
very brittle.
Change-Id: Ic89a269d3617d10d2a060d52d4ce0171f11e260b
---
M api/routes.js
M lib/mediawiki.ParsoidConfig.js
M tests/roundtrip-test.js
M tests/rttest.localsettings.js
4 files changed, 47 insertions(+), 50 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/07/204007/1
diff --git a/api/routes.js b/api/routes.js
index 3f3db08..612c91a 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -252,25 +252,22 @@
env.conf.parsoid.allowCORS );
}
- var p = new Promise(function( resolve, reject ) {
- if ( v2 && v2.original && v2.original.wikitext ) {
- env.setPageSrcInfo( v2.original.wikitext.body );
- return resolve();
- } else if ( !(v2 && v2.original && v2.original.html)
- && !env.conf.parsoid.fetchWT ) {
- return resolve();
- }
- var target = env.resolveTitle(
env.normalizeTitle(env.page.name), '' );
- var tpr = new TemplateRequest( env, target, env.page.id );
- tpr.once('src', function( err, src_and_metadata ) {
- if ( err ) {
- env.log("error", "There was an error fetching "
+
+ var p = Promise.resolve().then(function() {
+ if (v2 && v2.original && v2.original.wikitext &&
+ v2.original.wikitext.body !== undefined
+ ) {
+ env.setPageSrcInfo(v2.original.wikitext.body);
+ } else if (v2 && v2.original && v2.original.html) {
+ // Original html was supplied w/o wikitext. Fetch it as
a courtesy
+ // for RestBASE.
+ var target =
env.resolveTitle(env.normalizeTitle(env.page.name), '');
+ return TemplateRequest
+ .setPageSrcInfo(env, target, env.page.id)
+ .catch(function(err) {
+ env.log("error", "There was an error
fetching " +
"the original wikitext for ",
target, err);
- } else {
- env.setPageSrcInfo( src_and_metadata );
- }
- resolve();
- });
+ });
+ }
}).then(function() {
html = html.replace(/\r/g, '');
@@ -291,18 +288,29 @@
Date.now() - startTimers.get( 'html2wt.init' ));
}
- var Serializer = parsoidConfig.useSelser ? SelectiveSerializer
: WikitextSerializer,
- serializer = new Serializer({ env: env, oldid: env.page.id });
+ var Serializer = parsoidConfig.useSelser ?
+ SelectiveSerializer : WikitextSerializer;
- if ( v2 && v2.original && v2.original["data-parsoid"] ) {
- DU.applyDataParsoid( doc,
v2.original["data-parsoid"].body );
- }
- if ( v2 && v2.original && v2.original.html ) {
- env.page.dom = DU.parseHTML( v2.original.html.body
).body;
- if ( v2.original["data-parsoid"] ) {
- DU.applyDataParsoid(
env.page.dom.ownerDocument, v2.original["data-parsoid"].body );
+ if (v2) {
+ if (v2.original && v2.original["data-parsoid"]) {
+ DU.applyDataParsoid(doc,
v2.original["data-parsoid"].body);
+ }
+ if (v2.original && v2.original.html) {
+ env.page.dom =
DU.parseHTML(v2.original.html.body).body;
+ if (v2.original["data-parsoid"]) {
+
DU.applyDataParsoid(env.page.dom.ownerDocument,
+
v2.original["data-parsoid"].body);
+ }
+ } else {
+ // Original html wasn't supplied; don't use
selser. The
+ // SelectiveSerializer tries to be nice about
fetching and
+ // parsing original source, but we'd prefer not
to rely on
+ // these underspecified fallback mechanisms.
+ Serializer = WikitextSerializer;
}
}
+
+ var serializer = new Serializer({ env: env, oldid: env.page.id
});
return Promise.promisify( serializer.serializeDOM, false,
serializer )(
doc.body, false
);
diff --git a/lib/mediawiki.ParsoidConfig.js b/lib/mediawiki.ParsoidConfig.js
index 561db50..958ed72 100644
--- a/lib/mediawiki.ParsoidConfig.js
+++ b/lib/mediawiki.ParsoidConfig.js
@@ -178,13 +178,6 @@
ParsoidConfig.prototype.storeDataParsoid = false;
/**
- * @property {boolean} fetchWT
- * When transforming from html to wt, fetch the original wikitext before.
- * Intended for use in round-trip testing.
- */
- ParsoidConfig.prototype.fetchWT = false;
-
-/**
* @property {boolean} addHTMLTemplateParameters
* When processing template parameters, parse them to HTML and add it to the
* template parameters data.
diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index 0507d90..13b2583 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -580,7 +580,10 @@
oldid: env.page.meta.revision.revid,
data: {
html: data.oldHTML,
- original: { 'data-parsoid': data.oldDp },
+ original: {
+ 'data-parsoid': data.oldDp,
+ wikitext: { body: data.oldWt },
+ },
},
}, parsoidOptions);
return parsoidPost(env, options);
@@ -601,33 +604,29 @@
oldid: env.page.meta.revision.revid,
data: {
html: newDocument.outerHTML,
- original: { 'data-parsoid': data.oldDp },
+ original: {
+ 'data-parsoid': data.oldDp,
+ html: data.oldHTML,
+ wikitext: { body: data.oldWt },
+ },
},
profilePrefix: 'selser',
}, parsoidOptions);
return parsoidPost(env, options);
}).then(function(body) {
- var out = body.wikitext.body;
-
// Finish the total time now
// FIXME: Is the right place to end it?
if (env.profile && env.profile.time) {
env.profile.time.total = Date.now() -
env.profile.time.start;
}
- // FIXME: I guess so? This needs a comment. First we're diff'ing
- // the old and new wt's. Now we're diff'ing the new and
supposedly
- // selser'd wt's. Meanwhile, the serializer never seems to be
invoked
- // in selserMode.
- data.oldWt = data.newWt;
-
// Remove the selser trigger comment
- out = out.replace(/<!--rtSelserEditTestComment-->\n*$/, '');
- data.newWt = out;
+ data.newWt =
body.wikitext.body.replace(/<!--rtSelserEditTestComment-->\n*$/, '');
// FIXME: not sure about this stuff?
data.oldWt = data.oldWt.replace(/\n(?=\n)/g, '\n ');
data.newWt = data.newWt.replace(/\n(?=\n)/g, '\n ');
+
return roundTripDiff(env, parsoidOptions, data);
}).then(function(selserDiffs) {
selserDiffs.forEach(function(diff) {
diff --git a/tests/rttest.localsettings.js b/tests/rttest.localsettings.js
index 422ce2b..7a20cfa 100644
--- a/tests/rttest.localsettings.js
+++ b/tests/rttest.localsettings.js
@@ -32,7 +32,7 @@
// parsoidConfig.usePHPPreProcessor = false;
// Use selective serialization (default false)
- // parsoidConfig.useSelser = true;
+ parsoidConfig.useSelser = true;
// Allow cross-domain requests to the API (default '*')
// Sets Access-Control-Allow-Origin header
@@ -60,9 +60,6 @@
// Set rtTestMode to true for round-trip testing
parsoidConfig.rtTestMode = true;
-
- // Fetch the wikitext for a page before doing html2wt
- parsoidConfig.fetchWT = true;
// Set to true to enable Performance timing
parsoidConfig.useDefaultPerformanceTimer = false;
--
To view, visit https://gerrit.wikimedia.org/r/204007
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic89a269d3617d10d2a060d52d4ce0171f11e260b
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