https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113162
Revision: 113162
Author: gwicke
Date: 2012-03-06 18:02:35 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------
Improve generic attribute expansion before external link processing, and make
wgUploadPath configurable. Also change the hard-coded fall-back image sizes to
sensible defaults. This breaks three parser tests until image size retrieval
from the wiki is implemented.
Modified Paths:
--------------
trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
trunk/extensions/VisualEditor/modules/parser/parse.js
trunk/extensions/VisualEditor/tests/parser/parserTests.js
Modified:
trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
2012-03-06 17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -42,7 +42,11 @@
* processes the template.
*/
AttributeExpander.prototype.onToken = function ( token, frame, cb ) {
- if ( token.constructor === TagTk && token.attribs &&
token.attribs.length ) {
+ this.manager.env.dp( 'AttributeExpander.onToken', token );
+ if ( token.constructor === TagTk ||
+ token.constructor === SelfclosingTagTk &&
+ token.attribs &&
+ token.attribs.length ) {
var expandData = {
token: token,
cb: cb
Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
2012-03-06 17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -112,8 +112,8 @@
var MD5 = new jshashes.MD5(),
hash = MD5.hex( title.key ),
// TODO: Hackhack.. Move to proper test harness setup!
- path = 'http://example.com/images/' +
- [ hash[0], hash.substr(0, 2) ].join('/') + '/' +
title.key;
+ path = [ this.manager.env.wgUploadPath, hash[0],
+ hash.substr(0, 2), title.key
].join('/');
@@ -153,8 +153,8 @@
var img = new SelfclosingTagTk( 'img',
[
// FIXME!
- new KV( 'height', options.height || '220' ),
- new KV( 'width', options.width || '1941' ),
+ new KV( 'height', options.height || '120' ),
+ new KV( 'width', options.width || '120' ),
new KV( 'src', path ),
new KV( 'alt', options.alt || title.key )
] );
@@ -217,8 +217,9 @@
};
ExternalLinkHandler.prototype.onUrlLink = function ( token, manager, cb ) {
- var href = this.manager.env.sanitizeURI(
- this.manager.env.lookupKV( token.attribs, 'href' ).v
+ var env = this.manager.env,
+ href = env.sanitizeURI(
+ env.tokensToString( env.lookupKV(
token.attribs, 'href' ).v )
);
if ( this._isImageLink( href ) ) {
return { token: new SelfclosingTagTk( 'img',
@@ -241,9 +242,10 @@
// Bracketed external link
ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
- var href = this.manager.env.lookupKV( token.attribs, 'href' ).v,
- content= this.manager.env.lookupKV( token.attribs, 'content'
).v;
- href = this.manager.env.sanitizeURI( href );
+ var env = this.manager.env,
+ href = env.tokensToString( env.lookupKV( token.attribs, 'href'
).v ),
+ content= env.lookupKV( token.attribs, 'content' ).v;
+ href = env.sanitizeURI( href );
//console.warn('extlink href: ' + href );
//console.warn( 'content: ' + JSON.stringify( content, null, 2 ) );
// validate the href
Modified:
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-03-06 17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -399,15 +399,15 @@
return [ target ];
};
ParserFunctions.prototype['pf_fullpagename'] = function ( target, argList,
argDict ) {
- return [target];
+ return target && [target] || ["http://example.com/fixme/"];
};
ParserFunctions.prototype['pf_fullpagenamee'] = function ( target, argList,
argDict ) {
- return [target];
+ return target && [target] || ["http://example.com/fixme/"];
};
// This should be doable with the information in the envirionment
// (this.manager.env) already.
ParserFunctions.prototype['pf_fullurl'] = function ( target, argList, argDict
) {
- return [target];
+ return target && [target] || ["http://example.com/fixme/"];
};
ParserFunctions.prototype['pf_urlencode'] = function ( target, argList,
argDict ) {
this.manager.env.tp( 'urlencode: ' + target );
Modified: trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
2012-03-06 17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -10,9 +10,10 @@
Title.prototype.makeLink = function () {
// XXX: links always point to the canonical namespace name.
if ( false && this.nskey ) {
- return this.env.sanitizeURI( this.env.wgScriptPath + this.nskey
+ ':' + this.key );
+ return this.env.sanitizeURI( this.env.wgScriptPath + '/' +
+ this.nskey + ':' + this.key );
} else {
- var l = this.env.wgScriptPath,
+ var l = this.env.wgScriptPath + '/',
ns = this.ns.getDefaultName();
if ( ns ) {
Modified:
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
===================================================================
---
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
2012-03-06 17:53:05 UTC (rev 113161)
+++
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -91,6 +91,7 @@
transArr.push(transformer);
// sort ascending by rank
transArr.sort( this._cmpTransformations );
+ this.env.dp( 'transforms: ', this.transformers );
};
/**
@@ -191,7 +192,7 @@
* processed tokens.
* @returns {Object} Token(s) and async indication.
*/
-TokenTransformManager.prototype._transformTagToken = function ( token,
phaseEndRank, cbOrPrevToken ) {
+TokenTransformManager.prototype._transformTagToken = function ( token,
cbOrPrevToken ) {
// prepend 'any' transformers
var ts = this.transformers.any,
res = { token: token },
@@ -205,6 +206,7 @@
// could cache this per tag type to avoid re-sorting each time
ts = ts.concat(tagts);
ts.sort( this._cmpTransformations );
+ this.env.dp( 'ts: ', ts );
}
//console.warn(JSON.stringify(ts, null, 2));
if ( ts ) {
@@ -243,7 +245,7 @@
if ( res.token.rank === undefined &&
res.token.constructor === String ) {
res.token = new String ( res.token );
}
- res.token.rank = phaseEndRank;
+ res.token.rank = this.phaseEndRank;
}
}
return res;
@@ -261,7 +263,7 @@
* @param {Array} ts List of token transformers for this token type.
* @returns {Object} Token(s) and async indication.
*/
-TokenTransformManager.prototype._transformToken = function ( token,
phaseEndRank, ts, cbOrPrevToken ) {
+TokenTransformManager.prototype._transformToken = function ( token, ts,
cbOrPrevToken ) {
// prepend 'any' transformers
//this.env.dp('_transformToken', token);
var anyTrans = this.transformers.any;
@@ -303,7 +305,7 @@
if ( res.token.rank === undefined &&
res.token.constructor === String ) {
res.token = new String ( res.token );
}
- res.token.rank = phaseEndRank; // need phase passed in!
+ res.token.rank = this.phaseEndRank; // need phase
passed in!
}
//else {
// this.env.dp( '_transformToken aborted', res );
@@ -333,7 +335,7 @@
* @param {Object} args, the argument map for templates
* @param {Object} env, the environment.
*/
-function AsyncTokenTransformManager ( childFactories, args, env, inputType ) {
+function AsyncTokenTransformManager ( childFactories, args, env, inputType,
phaseEndRank ) {
// Factory function for new AsyncTokenTransformManager creation with
// default transforms enabled
// Also sets up a tokenizer and phase-1-transform depending on the
input format
@@ -342,6 +344,7 @@
this.childFactories = childFactories;
this._construct();
this._reset( args, env );
+ this.phaseEndRank = phaseEndRank;
// FIXME: pass actual title?
this.loopAndDepthCheck = new LoopAndDepthCheck( null );
}
@@ -473,7 +476,6 @@
//console.warn('AsyncTokenTransformManager.transformTokens: ' +
JSON.stringify(tokens) );
var res,
- phaseEndRank = 2, // XXX: parametrize!
// Prepare a new accumulator, to be used by async children (if
any)
localAccum = [],
accum = new TokenAccumulator( this, parentCB ),
@@ -489,26 +491,26 @@
switch ( token.constructor ) {
case String:
- res = this._transformToken( token,
phaseEndRank, ts.text, cb );
+ res = this._transformToken( token, ts.text, cb
);
break;
case NlTk:
- res = this._transformToken( token,
phaseEndRank, ts.newline, cb );
+ res = this._transformToken( token, ts.newline,
cb );
break;
case TagTk:
case EndTagTk:
case SelfclosingTagTk:
- res = this._transformTagToken( token,
phaseEndRank, cb );
+ res = this._transformTagToken( token, cb );
break;
default:
switch( token.type ) {
case 'COMMENT':
- res = this._transformToken(
token, phaseEndRank, ts.comment, cb );
+ res = this._transformToken(
token, ts.comment, cb );
break;
case 'END':
- res = this._transformToken(
token, phaseEndRank, ts.end, cb );
+ res = this._transformToken(
token, ts.end, cb );
break;
default:
- res = this._transformToken(
token, phaseEndRank, ts.martian, cb );
+ res = this._transformToken(
token, ts.martian, cb );
break;
}
break;
@@ -626,7 +628,7 @@
* @constructor
* @param {Object} environment.
*/
-function SyncTokenTransformManager ( env, phaseEndRank, inputType ) {
+function SyncTokenTransformManager ( env, inputType, phaseEndRank ) {
// both inherited
this._construct();
this.phaseEndRank = phaseEndRank;
@@ -672,27 +674,26 @@
switch( token.constructor ) {
case String:
- res = this._transformToken( token,
this.phaseEndRank,
- ts.text, this.prevToken
);
+ res = this._transformToken( token, ts.text,
this.prevToken );
break;
case NlTk:
- res = this._transformToken( token,
this.phaseEndRank, ts.newline, this.prevToken );
+ res = this._transformToken( token, ts.newline,
this.prevToken );
break;
case TagTk:
case EndTagTk:
case SelfclosingTagTk:
- res = this._transformTagToken( token,
this.phaseEndRank, this.prevToken );
+ res = this._transformTagToken( token,
this.prevToken );
break;
default:
switch( token.type ) {
case 'COMMENT':
- res = this._transformToken(
token, this.phaseEndRank, ts.comment, this.prevToken );
+ res = this._transformToken(
token, ts.comment, this.prevToken );
break;
case 'END':
- res = this._transformToken(
token, this.phaseEndRank, ts.end, this.prevToken );
+ res = this._transformToken(
token, ts.end, this.prevToken );
break;
default:
- res = this._transformToken(
token, this.phaseEndRank, ts.martian, this.prevToken );
+ res = this._transformToken(
token, ts.martian, this.prevToken );
break;
}
}
Modified:
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
===================================================================
---
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
2012-03-06 17:53:05 UTC (rev 113161)
+++
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -9,7 +9,9 @@
pageCache: {}, // @fixme use something with managed space
debug: false,
trace: false,
- wgScriptPath: "http://en.wikipedia.org/w",
+ wgScriptPath: "/wiki",
+ wgScript: "/wiki/index.php",
+ wgUploadPath: "/wiki/images",
wgScriptExtension: ".php",
fetchTemplates: false,
maxDepth: 40
Modified: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
2012-03-06 17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
2012-03-06 18:02:35 UTC (rev 113162)
@@ -76,7 +76,7 @@
this.tokenPostProcessor = new TokenTransformManager
- .SyncTokenTransformManager ( env,
inputType );
+ .SyncTokenTransformManager ( env,
inputType, 3.0 );
this.tokenPostProcessor.listenForTokensFrom ( this.inputPipeline );
@@ -239,7 +239,7 @@
*
https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
*/
var tokenPreProcessor = new
TokenTransformManager
-
.SyncTokenTransformManager ( this.env );
+
.SyncTokenTransformManager ( this.env, 'text/wiki', 1 );
tokenPreProcessor.listenForTokensFrom (
wikiTokenizer );
this._addTransformers( 'text/wiki', 'sync01',
@@ -251,7 +251,7 @@
'input':
this.makeInputPipeline.bind( this ),
'attributes':
this.makeAttributePipeline.bind( this )
},
- args, this.env,
inputType
+ args, this.env,
inputType, 2.0
);
// Register template expansion extension
@@ -295,10 +295,10 @@
* See
https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
*/
var tokenPreProcessor = new TokenTransformManager
- .SyncTokenTransformManager ( this.env,
inputType );
+ .SyncTokenTransformManager ( this.env,
inputType, 1 );
// XXX: set include flag properly!
- //this._addTransformers( inputType, 'sync01',
tokenPreProcessor, false );
+ this._addTransformers( inputType, 'sync01', tokenPreProcessor,
false );
new NoInclude( tokenPreProcessor );
@@ -307,7 +307,7 @@
'input': this.makeInputPipeline.bind(
this ),
'attributes':
this.makeAttributePipeline.bind( this )
},
- args, this.env, inputType
+ args, this.env, inputType, 2
);
// Register template expansion extension
this._addTransformers( 'text/wiki', 'async12',
Modified: trunk/extensions/VisualEditor/modules/parser/parse.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/parse.js 2012-03-06
17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/modules/parser/parse.js 2012-03-06
18:02:35 UTC (rev 113162)
@@ -49,6 +49,8 @@
// fetch templates from enwiki
by default..
wgScriptPath: argv.wgScriptPath,
wgScriptExtension:
argv.wgScriptExtension,
+ // XXX: add options for this!
+ wgUploadPath:
'http://upload.wikimedia.org/wikipedia/commons/thumb/',
fetchTemplates:
argv.fetchTemplates,
// enable/disable debug output
using this switch
debug: argv.debug,
Modified: trunk/extensions/VisualEditor/tests/parser/parserTests.js
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/parserTests.js 2012-03-06
17:53:05 UTC (rev 113161)
+++ trunk/extensions/VisualEditor/tests/parser/parserTests.js 2012-03-06
18:02:35 UTC (rev 113162)
@@ -202,7 +202,7 @@
fetchTemplates: false,
debug: this.argv.debug,
trace: this.argv.trace,
- wgScriptPath: '/wiki/'
+ wgUploadPath: 'http://example.com/images'
});
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs