Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js |
— | — | @@ -202,7 +202,7 @@ |
203 | 203 | fetchTemplates: false, |
204 | 204 | debug: this.argv.debug, |
205 | 205 | trace: this.argv.trace, |
206 | | - wgScriptPath: '/wiki/' |
| 206 | + wgUploadPath: 'http://example.com/images' |
207 | 207 | }); |
208 | 208 | } |
209 | 209 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | transArr.push(transformer); |
93 | 93 | // sort ascending by rank |
94 | 94 | transArr.sort( this._cmpTransformations ); |
| 95 | + this.env.dp( 'transforms: ', this.transformers ); |
95 | 96 | }; |
96 | 97 | |
97 | 98 | /** |
— | — | @@ -191,7 +192,7 @@ |
192 | 193 | * processed tokens. |
193 | 194 | * @returns {Object} Token(s) and async indication. |
194 | 195 | */ |
195 | | -TokenTransformManager.prototype._transformTagToken = function ( token, phaseEndRank, cbOrPrevToken ) { |
| 196 | +TokenTransformManager.prototype._transformTagToken = function ( token, cbOrPrevToken ) { |
196 | 197 | // prepend 'any' transformers |
197 | 198 | var ts = this.transformers.any, |
198 | 199 | res = { token: token }, |
— | — | @@ -205,6 +206,7 @@ |
206 | 207 | // could cache this per tag type to avoid re-sorting each time |
207 | 208 | ts = ts.concat(tagts); |
208 | 209 | ts.sort( this._cmpTransformations ); |
| 210 | + this.env.dp( 'ts: ', ts ); |
209 | 211 | } |
210 | 212 | //console.warn(JSON.stringify(ts, null, 2)); |
211 | 213 | if ( ts ) { |
— | — | @@ -243,7 +245,7 @@ |
244 | 246 | if ( res.token.rank === undefined && res.token.constructor === String ) { |
245 | 247 | res.token = new String ( res.token ); |
246 | 248 | } |
247 | | - res.token.rank = phaseEndRank; |
| 249 | + res.token.rank = this.phaseEndRank; |
248 | 250 | } |
249 | 251 | } |
250 | 252 | return res; |
— | — | @@ -261,7 +263,7 @@ |
262 | 264 | * @param {Array} ts List of token transformers for this token type. |
263 | 265 | * @returns {Object} Token(s) and async indication. |
264 | 266 | */ |
265 | | -TokenTransformManager.prototype._transformToken = function ( token, phaseEndRank, ts, cbOrPrevToken ) { |
| 267 | +TokenTransformManager.prototype._transformToken = function ( token, ts, cbOrPrevToken ) { |
266 | 268 | // prepend 'any' transformers |
267 | 269 | //this.env.dp('_transformToken', token); |
268 | 270 | var anyTrans = this.transformers.any; |
— | — | @@ -303,7 +305,7 @@ |
304 | 306 | if ( res.token.rank === undefined && res.token.constructor === String ) { |
305 | 307 | res.token = new String ( res.token ); |
306 | 308 | } |
307 | | - res.token.rank = phaseEndRank; // need phase passed in! |
| 309 | + res.token.rank = this.phaseEndRank; // need phase passed in! |
308 | 310 | } |
309 | 311 | //else { |
310 | 312 | // this.env.dp( '_transformToken aborted', res ); |
— | — | @@ -333,7 +335,7 @@ |
334 | 336 | * @param {Object} args, the argument map for templates |
335 | 337 | * @param {Object} env, the environment. |
336 | 338 | */ |
337 | | -function AsyncTokenTransformManager ( childFactories, args, env, inputType ) { |
| 339 | +function AsyncTokenTransformManager ( childFactories, args, env, inputType, phaseEndRank ) { |
338 | 340 | // Factory function for new AsyncTokenTransformManager creation with |
339 | 341 | // default transforms enabled |
340 | 342 | // Also sets up a tokenizer and phase-1-transform depending on the input format |
— | — | @@ -342,6 +344,7 @@ |
343 | 345 | this.childFactories = childFactories; |
344 | 346 | this._construct(); |
345 | 347 | this._reset( args, env ); |
| 348 | + this.phaseEndRank = phaseEndRank; |
346 | 349 | // FIXME: pass actual title? |
347 | 350 | this.loopAndDepthCheck = new LoopAndDepthCheck( null ); |
348 | 351 | } |
— | — | @@ -473,7 +476,6 @@ |
474 | 477 | //console.warn('AsyncTokenTransformManager.transformTokens: ' + JSON.stringify(tokens) ); |
475 | 478 | |
476 | 479 | var res, |
477 | | - phaseEndRank = 2, // XXX: parametrize! |
478 | 480 | // Prepare a new accumulator, to be used by async children (if any) |
479 | 481 | localAccum = [], |
480 | 482 | accum = new TokenAccumulator( this, parentCB ), |
— | — | @@ -489,26 +491,26 @@ |
490 | 492 | |
491 | 493 | switch ( token.constructor ) { |
492 | 494 | case String: |
493 | | - res = this._transformToken( token, phaseEndRank, ts.text, cb ); |
| 495 | + res = this._transformToken( token, ts.text, cb ); |
494 | 496 | break; |
495 | 497 | case NlTk: |
496 | | - res = this._transformToken( token, phaseEndRank, ts.newline, cb ); |
| 498 | + res = this._transformToken( token, ts.newline, cb ); |
497 | 499 | break; |
498 | 500 | case TagTk: |
499 | 501 | case EndTagTk: |
500 | 502 | case SelfclosingTagTk: |
501 | | - res = this._transformTagToken( token, phaseEndRank, cb ); |
| 503 | + res = this._transformTagToken( token, cb ); |
502 | 504 | break; |
503 | 505 | default: |
504 | 506 | switch( token.type ) { |
505 | 507 | case 'COMMENT': |
506 | | - res = this._transformToken( token, phaseEndRank, ts.comment, cb ); |
| 508 | + res = this._transformToken( token, ts.comment, cb ); |
507 | 509 | break; |
508 | 510 | case 'END': |
509 | | - res = this._transformToken( token, phaseEndRank, ts.end, cb ); |
| 511 | + res = this._transformToken( token, ts.end, cb ); |
510 | 512 | break; |
511 | 513 | default: |
512 | | - res = this._transformToken( token, phaseEndRank, ts.martian, cb ); |
| 514 | + res = this._transformToken( token, ts.martian, cb ); |
513 | 515 | break; |
514 | 516 | } |
515 | 517 | break; |
— | — | @@ -626,7 +628,7 @@ |
627 | 629 | * @constructor |
628 | 630 | * @param {Object} environment. |
629 | 631 | */ |
630 | | -function SyncTokenTransformManager ( env, phaseEndRank, inputType ) { |
| 632 | +function SyncTokenTransformManager ( env, inputType, phaseEndRank ) { |
631 | 633 | // both inherited |
632 | 634 | this._construct(); |
633 | 635 | this.phaseEndRank = phaseEndRank; |
— | — | @@ -672,27 +674,26 @@ |
673 | 675 | |
674 | 676 | switch( token.constructor ) { |
675 | 677 | case String: |
676 | | - res = this._transformToken( token, this.phaseEndRank, |
677 | | - ts.text, this.prevToken ); |
| 678 | + res = this._transformToken( token, ts.text, this.prevToken ); |
678 | 679 | break; |
679 | 680 | case NlTk: |
680 | | - res = this._transformToken( token, this.phaseEndRank, ts.newline, this.prevToken ); |
| 681 | + res = this._transformToken( token, ts.newline, this.prevToken ); |
681 | 682 | break; |
682 | 683 | case TagTk: |
683 | 684 | case EndTagTk: |
684 | 685 | case SelfclosingTagTk: |
685 | | - res = this._transformTagToken( token, this.phaseEndRank, this.prevToken ); |
| 686 | + res = this._transformTagToken( token, this.prevToken ); |
686 | 687 | break; |
687 | 688 | default: |
688 | 689 | switch( token.type ) { |
689 | 690 | case 'COMMENT': |
690 | | - res = this._transformToken( token, this.phaseEndRank, ts.comment, this.prevToken ); |
| 691 | + res = this._transformToken( token, ts.comment, this.prevToken ); |
691 | 692 | break; |
692 | 693 | case 'END': |
693 | | - res = this._transformToken( token, this.phaseEndRank, ts.end, this.prevToken ); |
| 694 | + res = this._transformToken( token, ts.end, this.prevToken ); |
694 | 695 | break; |
695 | 696 | default: |
696 | | - res = this._transformToken( token, this.phaseEndRank, ts.martian, this.prevToken ); |
| 697 | + res = this._transformToken( token, ts.martian, this.prevToken ); |
697 | 698 | break; |
698 | 699 | } |
699 | 700 | } |
Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -49,6 +49,8 @@ |
50 | 50 | // fetch templates from enwiki by default.. |
51 | 51 | wgScriptPath: argv.wgScriptPath, |
52 | 52 | wgScriptExtension: argv.wgScriptExtension, |
| 53 | + // XXX: add options for this! |
| 54 | + wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb/', |
53 | 55 | fetchTemplates: argv.fetchTemplates, |
54 | 56 | // enable/disable debug output using this switch |
55 | 57 | debug: argv.debug, |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js |
— | — | @@ -399,15 +399,15 @@ |
400 | 400 | return [ target ]; |
401 | 401 | }; |
402 | 402 | ParserFunctions.prototype['pf_fullpagename'] = function ( target, argList, argDict ) { |
403 | | - return [target]; |
| 403 | + return target && [target] || ["http://example.com/fixme/"]; |
404 | 404 | }; |
405 | 405 | ParserFunctions.prototype['pf_fullpagenamee'] = function ( target, argList, argDict ) { |
406 | | - return [target]; |
| 406 | + return target && [target] || ["http://example.com/fixme/"]; |
407 | 407 | }; |
408 | 408 | // This should be doable with the information in the envirionment |
409 | 409 | // (this.manager.env) already. |
410 | 410 | ParserFunctions.prototype['pf_fullurl'] = function ( target, argList, argDict ) { |
411 | | - return [target]; |
| 411 | + return target && [target] || ["http://example.com/fixme/"]; |
412 | 412 | }; |
413 | 413 | ParserFunctions.prototype['pf_urlencode'] = function ( target, argList, argDict ) { |
414 | 414 | this.manager.env.tp( 'urlencode: ' + target ); |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js |
— | — | @@ -42,7 +42,11 @@ |
43 | 43 | * processes the template. |
44 | 44 | */ |
45 | 45 | AttributeExpander.prototype.onToken = function ( token, frame, cb ) { |
46 | | - if ( token.constructor === TagTk && token.attribs && token.attribs.length ) { |
| 46 | + this.manager.env.dp( 'AttributeExpander.onToken', token ); |
| 47 | + if ( token.constructor === TagTk || |
| 48 | + token.constructor === SelfclosingTagTk && |
| 49 | + token.attribs && |
| 50 | + token.attribs.length ) { |
47 | 51 | var expandData = { |
48 | 52 | token: token, |
49 | 53 | cb: cb |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js |
— | — | @@ -112,8 +112,8 @@ |
113 | 113 | var MD5 = new jshashes.MD5(), |
114 | 114 | hash = MD5.hex( title.key ), |
115 | 115 | // TODO: Hackhack.. Move to proper test harness setup! |
116 | | - path = 'http://example.com/images/' + |
117 | | - [ hash[0], hash.substr(0, 2) ].join('/') + '/' + title.key; |
| 116 | + path = [ this.manager.env.wgUploadPath, hash[0], |
| 117 | + hash.substr(0, 2), title.key ].join('/'); |
118 | 118 | |
119 | 119 | |
120 | 120 | |
— | — | @@ -153,8 +153,8 @@ |
154 | 154 | var img = new SelfclosingTagTk( 'img', |
155 | 155 | [ |
156 | 156 | // FIXME! |
157 | | - new KV( 'height', options.height || '220' ), |
158 | | - new KV( 'width', options.width || '1941' ), |
| 157 | + new KV( 'height', options.height || '120' ), |
| 158 | + new KV( 'width', options.width || '120' ), |
159 | 159 | new KV( 'src', path ), |
160 | 160 | new KV( 'alt', options.alt || title.key ) |
161 | 161 | ] ); |
— | — | @@ -217,8 +217,9 @@ |
218 | 218 | }; |
219 | 219 | |
220 | 220 | ExternalLinkHandler.prototype.onUrlLink = function ( token, manager, cb ) { |
221 | | - var href = this.manager.env.sanitizeURI( |
222 | | - this.manager.env.lookupKV( token.attribs, 'href' ).v |
| 221 | + var env = this.manager.env, |
| 222 | + href = env.sanitizeURI( |
| 223 | + env.tokensToString( env.lookupKV( token.attribs, 'href' ).v ) |
223 | 224 | ); |
224 | 225 | if ( this._isImageLink( href ) ) { |
225 | 226 | return { token: new SelfclosingTagTk( 'img', |
— | — | @@ -241,9 +242,10 @@ |
242 | 243 | |
243 | 244 | // Bracketed external link |
244 | 245 | ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) { |
245 | | - var href = this.manager.env.lookupKV( token.attribs, 'href' ).v, |
246 | | - content= this.manager.env.lookupKV( token.attribs, 'content' ).v; |
247 | | - href = this.manager.env.sanitizeURI( href ); |
| 246 | + var env = this.manager.env, |
| 247 | + href = env.tokensToString( env.lookupKV( token.attribs, 'href' ).v ), |
| 248 | + content= env.lookupKV( token.attribs, 'content' ).v; |
| 249 | + href = env.sanitizeURI( href ); |
248 | 250 | //console.warn('extlink href: ' + href ); |
249 | 251 | //console.warn( 'content: ' + JSON.stringify( content, null, 2 ) ); |
250 | 252 | // validate the href |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.Title.js |
— | — | @@ -10,9 +10,10 @@ |
11 | 11 | Title.prototype.makeLink = function () { |
12 | 12 | // XXX: links always point to the canonical namespace name. |
13 | 13 | if ( false && this.nskey ) { |
14 | | - return this.env.sanitizeURI( this.env.wgScriptPath + this.nskey + ':' + this.key ); |
| 14 | + return this.env.sanitizeURI( this.env.wgScriptPath + '/' + |
| 15 | + this.nskey + ':' + this.key ); |
15 | 16 | } else { |
16 | | - var l = this.env.wgScriptPath, |
| 17 | + var l = this.env.wgScriptPath + '/', |
17 | 18 | ns = this.ns.getDefaultName(); |
18 | 19 | |
19 | 20 | if ( ns ) { |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | |
78 | 78 | |
79 | 79 | this.tokenPostProcessor = new TokenTransformManager |
80 | | - .SyncTokenTransformManager ( env, inputType ); |
| 80 | + .SyncTokenTransformManager ( env, inputType, 3.0 ); |
81 | 81 | this.tokenPostProcessor.listenForTokensFrom ( this.inputPipeline ); |
82 | 82 | |
83 | 83 | |
— | — | @@ -239,7 +239,7 @@ |
240 | 240 | * https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
241 | 241 | */ |
242 | 242 | var tokenPreProcessor = new TokenTransformManager |
243 | | - .SyncTokenTransformManager ( this.env ); |
| 243 | + .SyncTokenTransformManager ( this.env, 'text/wiki', 1 ); |
244 | 244 | tokenPreProcessor.listenForTokensFrom ( wikiTokenizer ); |
245 | 245 | |
246 | 246 | this._addTransformers( 'text/wiki', 'sync01', |
— | — | @@ -251,7 +251,7 @@ |
252 | 252 | 'input': this.makeInputPipeline.bind( this ), |
253 | 253 | 'attributes': this.makeAttributePipeline.bind( this ) |
254 | 254 | }, |
255 | | - args, this.env, inputType |
| 255 | + args, this.env, inputType, 2.0 |
256 | 256 | ); |
257 | 257 | |
258 | 258 | // Register template expansion extension |
— | — | @@ -295,10 +295,10 @@ |
296 | 296 | * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
297 | 297 | */ |
298 | 298 | var tokenPreProcessor = new TokenTransformManager |
299 | | - .SyncTokenTransformManager ( this.env, inputType ); |
| 299 | + .SyncTokenTransformManager ( this.env, inputType, 1 ); |
300 | 300 | |
301 | 301 | // XXX: set include flag properly! |
302 | | - //this._addTransformers( inputType, 'sync01', tokenPreProcessor, false ); |
| 302 | + this._addTransformers( inputType, 'sync01', tokenPreProcessor, false ); |
303 | 303 | |
304 | 304 | new NoInclude( tokenPreProcessor ); |
305 | 305 | |
— | — | @@ -307,7 +307,7 @@ |
308 | 308 | 'input': this.makeInputPipeline.bind( this ), |
309 | 309 | 'attributes': this.makeAttributePipeline.bind( this ) |
310 | 310 | }, |
311 | | - args, this.env, inputType |
| 311 | + args, this.env, inputType, 2 |
312 | 312 | ); |
313 | 313 | // Register template expansion extension |
314 | 314 | this._addTransformers( 'text/wiki', 'async12', |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js |
— | — | @@ -9,7 +9,9 @@ |
10 | 10 | pageCache: {}, // @fixme use something with managed space |
11 | 11 | debug: false, |
12 | 12 | trace: false, |
13 | | - wgScriptPath: "http://en.wikipedia.org/w", |
| 13 | + wgScriptPath: "/wiki", |
| 14 | + wgScript: "/wiki/index.php", |
| 15 | + wgUploadPath: "/wiki/images", |
14 | 16 | wgScriptExtension: ".php", |
15 | 17 | fetchTemplates: false, |
16 | 18 | maxDepth: 40 |