jenkins-bot has submitted this change and it was merged.

Change subject: Bug 54339: Add _rtselser endpoint in web API
......................................................................


Bug 54339: Add _rtselser endpoint in web API

Added an argument to roundTripDiff to set which serializer to use.
Also, resolve titles correctly in the _rtve endpoint.

Change-Id: I733151662bca5f8ea477107fb8486e5afe68f2e9
---
M js/api/ParserService.js
1 file changed, 43 insertions(+), 11 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/api/ParserService.js b/js/api/ParserService.js
index d3d3ea8..91096cc 100644
--- a/js/api/ParserService.js
+++ b/js/api/ParserService.js
@@ -206,7 +206,7 @@
        return out;
 };
 
-var roundTripDiff = function ( req, res, env, document ) {
+var roundTripDiff = function ( selser, req, res, env, document ) {
        var patch;
        var out = [];
 
@@ -261,12 +261,17 @@
        // Re-parse the HTML to uncover foster-parenting issues
        document = domino.createDocument(document.outerHTML);
 
-       // Always use the regular serializer for round-trip diff tests
-       // since these will never have any edits for selser to do any work.
-       new WikitextSerializer({env: env}).serializeDOM( document.body,
-                               function ( chunk ) {
-                                       out.push(chunk);
-                               }, finalCB );
+       if ( selser ) {
+               new SelectiveSerializer( {env: env}).serializeDOM( 
document.body,
+                       function ( chunk ) {
+                               out.push(chunk);
+                       }, finalCB );
+       } else {
+               new WikitextSerializer({env: env}).serializeDOM( document.body,
+                       function ( chunk ) {
+                               out.push(chunk);
+                       }, finalCB );
+       }
 };
 
 function handleCacheRequest (env, req, cb, err, src, cacheErr, cacheSrc) {
@@ -527,7 +532,7 @@
                        oldid = req.query.oldid;
                }
                var tpr = new TemplateRequest( env, target, oldid );
-               tpr.once('src', parse.bind( tpr, env, req, res, roundTripDiff 
));
+               tpr.once('src', parse.bind( tpr, env, req, res, 
roundTripDiff.bind( null, false ) ));
        };
 
        getParserServiceEnv( res, req.params[0], req.params[1], cb );
@@ -542,7 +547,7 @@
                        return;
                }
 
-               var target = env.page.title;
+               var target = env.resolveTitle( env.normalizeTitle( 
env.page.name ), '' );
 
                console.log('starting parsing of ' + target);
                var oldid = null;
@@ -554,13 +559,40 @@
                                // strip newlines from the html
                                var html = 
document.innerHTML.replace(/[\r\n]/g, ''),
                                        newDocument = Util.parseHTML(html);
-                               roundTripDiff( req, res, src, newDocument );
+                               roundTripDiff( false, req, res, src, 
newDocument );
                        };
 
                tpr.once('src', parse.bind( tpr, env, req, res, cb ));
        };
 
        getParserServiceEnv( res, req.params[0], req.params[1], cb );
+});
+
+// Round-trip article testing with selser over re-parsed HTML.
+app.get( new RegExp('/_rtselser/(' + getInterwikiRE() + ')/(.*)') , function 
(req, res) {
+       var envCb = function ( env ) {
+               if ( env.page.name === 'favicon.ico' ) {
+                       res.send( 'no favicon yet..', 404 );
+                       return;
+               }
+
+               var target = env.resolveTitle( env.normalizeTitle( 
env.page.name ), '' );
+
+               console.log( 'starting parsing of ' + target );
+               var oldid = null;
+               if ( req.query.oldid ) {
+                       oldid = req.query.oldid;
+               }
+               var tpr = new TemplateRequest( env, target, oldid ),
+                       tprCb = function ( req, res, src, document ) {
+                               var newDocument = Util.parseHTML( 
document.innerHTML );
+                               roundTripDiff( true, req, res, src, newDocument 
);
+                       };
+
+               tpr.once( 'src', parse.bind( tpr, env, req, res, tprCb ) );
+       };
+
+       getParserServiceEnv( res, req.params[0], req.params[1], envCb );
 });
 
 // Form-based round-tripping for manual testing
@@ -579,7 +611,7 @@
        var cb = function ( env ) {
                res.setHeader('Content-Type', 'text/html; charset=UTF-8');
                // we don't care about \r, and normalize everything to \n
-               parse( env, req, res, roundTripDiff, null, {
+               parse( env, req, res, roundTripDiff.bind( null, false ), null, {
                        revision: { '*': req.body.content.replace(/\r/g, '') }
                });
        };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I733151662bca5f8ea477107fb8486e5afe68f2e9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to