Fix an external link regression, and add server shell wrapper and setup docs

Change-Id: I9a4f7690e98313d003a2fec35324ed70556e6461
This commit is contained in:
Gabriel Wicke 2012-05-23 16:25:42 +02:00
parent b89f5071e5
commit a4c5d43ff7
4 changed files with 34 additions and 7 deletions

11
api/README.runserver.txt Normal file
View file

@ -0,0 +1,11 @@
== Installation on Ubuntu VM ==
apt-get update
apt-get install nodejs npm git build-essential
npm install -g express html5 lru-cache jquery pegjs async jshashes
adduser --system --home /var/lib/parsoid parsoid
cd /var/lib/parsoid
git clone
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/VisualEditor.git
cd VisualEditor/api
./runserver.sh

6
api/runserver.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
# redirect port 80 to unprivileged port 8000
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
# run the server as non-privileged user
nohup sudo -u nobody node server.js &

View file

@ -343,9 +343,13 @@ function ExternalLinkHandler( manager, isInclude ) {
// img_options production only.
ExternalLinkHandler.prototype.imageParser = new PegTokenizer();
}
this.onEnd();
this._reset();
}
ExternalLinkHandler.prototype._reset = function () {
this.linkCount = 1;
};
ExternalLinkHandler.prototype.rank = 1.15;
ExternalLinkHandler.prototype._imageExtensions = {
'jpg': true,
@ -403,6 +407,10 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
//console.warn('extlink href: ' + href );
//console.warn( 'content: ' + JSON.stringify( content, null, 2 ) );
// validate the href
if ( ! content.length ) {
content = ['[' + this.linkCount + ']'];
this.linkCount++;
}
if ( this.imageParser.tokenizeURL( href ) ) {
if ( content.length === 1 &&
content[0].constructor === String &&
@ -433,10 +441,6 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
].concat( content, [ new EndTagTk( 'a' )])
} );
} else {
if ( content === '' ) {
content = ['[' + this.linkCount + ']'];
this.linkCount++;
}
cb( {
tokens: ['[', href, ' ' ].concat( content, [']'] )
} );
@ -444,8 +448,8 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
};
ExternalLinkHandler.prototype.onEnd = function ( token, manager, cb ) {
this.linkCount = 1;
return { tokens: token };
this._reset();
cb( { tokens: [ token ] } );
};

View file

@ -435,6 +435,12 @@ AsyncTokenTransformManager.prototype.transformTokens = function ( tokens, parent
// maybeSyncReturn callback
if ( resTokens && resTokens.length ) {
if ( resTokens.length === 1 ) {
if ( resTokens[0] === undefined ) {
console.warn('transformer ' + transformer +
' returned undefined token!');
resTokens.shift();
break;
}
if ( token === resTokens[0] && ! resTokens.rank ) {
// token not modified, continue with
// transforms.