Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | wgScriptPath: argv.wgScriptPath, |
52 | 52 | wgScriptExtension: argv.wgScriptExtension, |
53 | 53 | // XXX: add options for this! |
54 | | - wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb', |
| 54 | + wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons', |
55 | 55 | fetchTemplates: argv.fetchTemplates, |
56 | 56 | // enable/disable debug output using this switch |
57 | 57 | debug: argv.debug, |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js |
— | — | @@ -39,9 +39,7 @@ |
40 | 40 | var kv; |
41 | 41 | for ( var i = 0, l = kvs.length; i < l; i++ ) { |
42 | 42 | kv = kvs[i]; |
43 | | - // XXX: tokensToString actually strips too much here! Anything |
44 | | - // non-stringish should not match at all. |
45 | | - if ( this.manager.env.tokensToString( kv.v ) === key ) { |
| 43 | + if ( this.manager.env.tokensToString( kv.v, true ) === key ) { |
46 | 44 | // found. now look for the next entry with a non-empty key. |
47 | 45 | for ( var j = i; j < l; j++) { |
48 | 46 | kv = kvs[j]; |
— | — | @@ -61,7 +59,7 @@ |
62 | 60 | // TODO: Implement |
63 | 61 | // http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#Grouping_results |
64 | 62 | ParserFunctions.prototype['pf_#switch'] = function ( target, argList, argDict, unnamedArgs ) { |
65 | | - this.manager.env.dp( 'switch enter: ' + target.trim() + |
| 63 | + this.manager.env.dp( 'switch enter', target.trim(), |
66 | 64 | ' looking in ', argDict ); |
67 | 65 | target = target.trim(); |
68 | 66 | if ( argDict[target] !== undefined ) { |
— | — | @@ -396,7 +394,7 @@ |
397 | 395 | return [ target ]; |
398 | 396 | }; |
399 | 397 | ParserFunctions.prototype['pf_pagenamee'] = function ( target, argList, argDict ) { |
400 | | - return [ target ]; |
| 398 | + return [ target.split(':', 2)[1] || '' ]; |
401 | 399 | }; |
402 | 400 | ParserFunctions.prototype['pf_fullpagename'] = function ( target, argList, argDict ) { |
403 | 401 | return target && [target] || ["http://example.com/fixme/"]; |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js |
— | — | @@ -57,6 +57,46 @@ |
58 | 58 | return null; |
59 | 59 | }; |
60 | 60 | |
| 61 | +/** |
| 62 | + * Trim space and newlines from leading and trailing text tokens. |
| 63 | + */ |
| 64 | +MWParserEnvironment.prototype.tokenTrim = function ( tokens ) { |
| 65 | + var l = tokens.length, |
| 66 | + i, token; |
| 67 | + // strip leading space |
| 68 | + for ( i = 0; i < l; i++ ) { |
| 69 | + token = tokens[i]; |
| 70 | + if ( token.constructor === String ) { |
| 71 | + token = token.replace( /^\s+/, '' ); |
| 72 | + tokens[i] = token; |
| 73 | + if ( token !== '' ) { |
| 74 | + break; |
| 75 | + } |
| 76 | + } else { |
| 77 | + break; |
| 78 | + } |
| 79 | + } |
| 80 | + // strip trailing space |
| 81 | + for ( i = l - 1; i >= 0; i-- ) { |
| 82 | + token = tokens[i]; |
| 83 | + if ( token.constructor === String ) { |
| 84 | + token = token.replace( /\s+$/, '' ); |
| 85 | + tokens[i] = token; |
| 86 | + if ( token !== '' ) { |
| 87 | + break; |
| 88 | + } |
| 89 | + } else { |
| 90 | + break; |
| 91 | + } |
| 92 | + } |
| 93 | + return tokens; |
| 94 | +}; |
| 95 | + |
| 96 | + |
| 97 | +/** |
| 98 | + * Convert an array of key-value pairs into a hash of keys to values. For |
| 99 | + * duplicate keys, the last entry wins. |
| 100 | + */ |
61 | 101 | MWParserEnvironment.prototype.KVtoHash = function ( kvs ) { |
62 | 102 | if ( ! kvs ) { |
63 | 103 | console.warn( "Invalid kvs!: " + JSON.stringify( kvs, null, 2 ) ); |
— | — | @@ -66,9 +106,9 @@ |
67 | 107 | for ( var i = 0, l = kvs.length; i < l; i++ ) { |
68 | 108 | var kv = kvs[i], |
69 | 109 | key = this.tokensToString( kv.k ).trim(); |
70 | | - if( res[key] === undefined ) { |
71 | | - res[key] = kv.v; |
72 | | - } |
| 110 | + //if( res[key] === undefined ) { |
| 111 | + res[key] = this.tokenTrim( kv.v ); |
| 112 | + //} |
73 | 113 | } |
74 | 114 | //console.warn( 'KVtoHash: ' + JSON.stringify( res )); |
75 | 115 | return res; |
— | — | @@ -203,7 +243,8 @@ |
204 | 244 | var tstring = JSON.stringify( token ); |
205 | 245 | this.dp ( 'MWParserEnvironment.tokensToString, non-text token: ' + |
206 | 246 | tstring + JSON.stringify( tokens, null, 2 ) ); |
207 | | - //out.push( tstring ); |
| 247 | + //console.trace(); |
| 248 | + out.push( tstring ); |
208 | 249 | } |
209 | 250 | } |
210 | 251 | //console.warn( 'MWParserEnvironment.tokensToString result: ' + out.join('') ); |