mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 04:06:51 +00:00
Add round-trip form and split out rt diffing
Change-Id: I3bc8ad7f273937ce6c767b8d7bbccdc86cbd93b4
This commit is contained in:
parent
99c98d6c56
commit
0eabd2c67e
|
@ -42,11 +42,13 @@ app.get('/', function(req, res){
|
||||||
res.write( '<p>Usage: <ul><li>GET /title for the DOM. ' +
|
res.write( '<p>Usage: <ul><li>GET /title for the DOM. ' +
|
||||||
'Example: <strong><a href="/Main_Page">Main Page</a></strong>');
|
'Example: <strong><a href="/Main_Page">Main Page</a></strong>');
|
||||||
res.write('<li>POST a DOM as parameter "content" to /title for the wikitext</ul>');
|
res.write('<li>POST a DOM as parameter "content" to /title for the wikitext</ul>');
|
||||||
res.write('<p>There are also some tools for experiments:' +
|
res.write('<p>There are also some tools for experiments:<ul>');
|
||||||
'<ul><li><strong><a href="/_wikitext/">WikiText -> HTML DOM form</a></strong></li>' +
|
res.write('<li>Round-trip test pages from the English Wikipedia: ' +
|
||||||
|
'<strong><a href="/_rt/Help:Magic">/_rt/Help:Magic</a></strong></li>');
|
||||||
|
res.write('<li><strong><a href="/_rtform/">WikiText -> HTML DOM -> WikiText round-trip form</a></strong></li>');
|
||||||
|
res.write('<li><strong><a href="/_wikitext/">WikiText -> HTML DOM form</a></strong></li>' +
|
||||||
'<li><strong><a href="/_html/">HTML DOM -> WikiText form</a></strong></li>');
|
'<li><strong><a href="/_html/">HTML DOM -> WikiText form</a></strong></li>');
|
||||||
res.end('<li>Round-trip testing arbitrary pages: ' +
|
res.end('</ul>');
|
||||||
'<strong><a href="/_roundtrip/Help:Magic">/_roundtrip/Help:Magic</a></strong></li></ul>');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var htmlSpecialChars = function ( s ) {
|
var htmlSpecialChars = function ( s ) {
|
||||||
|
@ -163,25 +165,7 @@ var refineDiff = function( diff ) {
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
var roundTripDiff = function ( res, src, document ) {
|
||||||
* Round-trip article testing
|
|
||||||
*/
|
|
||||||
app.get(/\/_roundtrip\/(.*)/, function(req, res){
|
|
||||||
env.pageName = req.params[0];
|
|
||||||
env.wgScriptPath = '/_roundtrip';
|
|
||||||
|
|
||||||
if ( env.pageName === 'favicon.ico' ) {
|
|
||||||
res.end( 'no favicon yet..' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = env.resolveTitle( env.normalizeTitle( env.pageName ), '' );
|
|
||||||
|
|
||||||
console.log('retrieving ' + req.params[0]);
|
|
||||||
var tpr = new TemplateRequest( env, target );
|
|
||||||
tpr.once('src', function ( src ) {
|
|
||||||
var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' );
|
|
||||||
parser.on('document', function ( document ) {
|
|
||||||
res.write('<html><head><style>del { background: #ff9191; text-decoration: none; } ins { background: #99ff7e; text-decoration: none }; </style></head><body>');
|
res.write('<html><head><style>del { background: #ff9191; text-decoration: none; } ins { background: #99ff7e; text-decoration: none }; </style></head><body>');
|
||||||
res.write( '<h2>Wikitext parsed to HTML DOM</h2><hr>' );
|
res.write( '<h2>Wikitext parsed to HTML DOM</h2><hr>' );
|
||||||
res.write(document.body.innerHTML + '<hr>');
|
res.write(document.body.innerHTML + '<hr>');
|
||||||
|
@ -199,17 +183,57 @@ app.get(/\/_roundtrip\/(.*)/, function(req, res){
|
||||||
patch = jsDiff.convertChangesToXML( refineDiff( jsDiff.diffLines( out, src ) ) );
|
patch = jsDiff.convertChangesToXML( refineDiff( jsDiff.diffLines( out, src ) ) );
|
||||||
}
|
}
|
||||||
res.end( '<pre>' + patch);
|
res.end( '<pre>' + patch);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
var parse = function ( res, cb, src ) {
|
||||||
|
var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' );
|
||||||
|
parser.on('document', cb.bind( null, res, src ) );
|
||||||
try {
|
try {
|
||||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
console.log('starting parsing of ' + req.params[0]);
|
//console.log('starting parsing of ' + req.params[0]);
|
||||||
// FIXME: This does not handle includes or templates correctly
|
// FIXME: This does not handle includes or templates correctly
|
||||||
parser.process( src );
|
parser.process( src );
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log( e );
|
console.log( e );
|
||||||
res.end( e );
|
res.end( e );
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round-trip article testing
|
||||||
|
*/
|
||||||
|
app.get(/\/_rt\/(.*)/, function(req, res){
|
||||||
|
env.pageName = req.params[0];
|
||||||
|
env.wgScriptPath = '/_rt';
|
||||||
|
|
||||||
|
if ( env.pageName === 'favicon.ico' ) {
|
||||||
|
res.end( 'no favicon yet..' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = env.resolveTitle( env.normalizeTitle( env.pageName ), '' );
|
||||||
|
|
||||||
|
console.log('retrieving ' + req.params[0]);
|
||||||
|
var tpr = new TemplateRequest( env, target );
|
||||||
|
tpr.once('src', parse.bind( null, res, roundTripDiff ));
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form-based round-tripping for manual testing
|
||||||
|
*/
|
||||||
|
app.get(/\/_rtform\/(.*)/, function(req, res){
|
||||||
|
env.pageName = req.params[0];
|
||||||
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
res.write( "Your wikitext:" );
|
||||||
|
textarea( res );
|
||||||
|
res.end('');
|
||||||
|
});
|
||||||
|
app.post(/\/_rtform\/(.*)/, function(req, res){
|
||||||
|
env.pageName = req.params[0];
|
||||||
|
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||||
|
var parser = parserPipelineFactory.makePipeline( 'text/x-mediawiki/full' );
|
||||||
|
|
||||||
|
parse( res, roundTripDiff, req.body.content);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue