https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113360
Revision: 113360
Author: gwicke
Date: 2012-03-08 11:44:37 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
A few fixes to parser functions and template expansion. Trim whitespace off
template arguments, let the last duplicate key win and fake pagenamee slightly
better.
Modified Paths:
--------------
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
trunk/extensions/VisualEditor/modules/parser/parse.js
Modified:
trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-03-08 11:35:34 UTC (rev 113359)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
2012-03-08 11:44:37 UTC (rev 113360)
@@ -39,9 +39,7 @@
var kv;
for ( var i = 0, l = kvs.length; i < l; i++ ) {
kv = kvs[i];
- // XXX: tokensToString actually strips too much here! Anything
- // non-stringish should not match at all.
- if ( this.manager.env.tokensToString( kv.v ) === key ) {
+ if ( this.manager.env.tokensToString( kv.v, true ) === key ) {
// found. now look for the next entry with a non-empty
key.
for ( var j = i; j < l; j++) {
kv = kvs[j];
@@ -61,7 +59,7 @@
// TODO: Implement
//
http://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#Grouping_results
ParserFunctions.prototype['pf_#switch'] = function ( target, argList, argDict,
unnamedArgs ) {
- this.manager.env.dp( 'switch enter: ' + target.trim() +
+ this.manager.env.dp( 'switch enter', target.trim(),
' looking in ', argDict );
target = target.trim();
if ( argDict[target] !== undefined ) {
@@ -396,7 +394,7 @@
return [ target ];
};
ParserFunctions.prototype['pf_pagenamee'] = function ( target, argList,
argDict ) {
- return [ target ];
+ return [ target.split(':', 2)[1] || '' ];
};
ParserFunctions.prototype['pf_fullpagename'] = function ( target, argList,
argDict ) {
return target && [target] || ["http://example.com/fixme/"];
Modified:
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
===================================================================
---
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
2012-03-08 11:35:34 UTC (rev 113359)
+++
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
2012-03-08 11:44:37 UTC (rev 113360)
@@ -57,6 +57,46 @@
return null;
};
+/**
+ * Trim space and newlines from leading and trailing text tokens.
+ */
+MWParserEnvironment.prototype.tokenTrim = function ( tokens ) {
+ var l = tokens.length,
+ i, token;
+ // strip leading space
+ for ( i = 0; i < l; i++ ) {
+ token = tokens[i];
+ if ( token.constructor === String ) {
+ token = token.replace( /^\s+/, '' );
+ tokens[i] = token;
+ if ( token !== '' ) {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ // strip trailing space
+ for ( i = l - 1; i >= 0; i-- ) {
+ token = tokens[i];
+ if ( token.constructor === String ) {
+ token = token.replace( /\s+$/, '' );
+ tokens[i] = token;
+ if ( token !== '' ) {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ return tokens;
+};
+
+
+/**
+ * Convert an array of key-value pairs into a hash of keys to values. For
+ * duplicate keys, the last entry wins.
+ */
MWParserEnvironment.prototype.KVtoHash = function ( kvs ) {
if ( ! kvs ) {
console.warn( "Invalid kvs!: " + JSON.stringify( kvs, null, 2 )
);
@@ -66,9 +106,9 @@
for ( var i = 0, l = kvs.length; i < l; i++ ) {
var kv = kvs[i],
key = this.tokensToString( kv.k ).trim();
- if( res[key] === undefined ) {
- res[key] = kv.v;
- }
+ //if( res[key] === undefined ) {
+ res[key] = this.tokenTrim( kv.v );
+ //}
}
//console.warn( 'KVtoHash: ' + JSON.stringify( res ));
return res;
@@ -203,7 +243,8 @@
var tstring = JSON.stringify( token );
this.dp ( 'MWParserEnvironment.tokensToString, non-text
token: ' +
tstring + JSON.stringify( tokens, null,
2 ) );
- //out.push( tstring );
+ //console.trace();
+ out.push( tstring );
}
}
//console.warn( 'MWParserEnvironment.tokensToString result: ' +
out.join('') );
Modified: trunk/extensions/VisualEditor/modules/parser/parse.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/parse.js 2012-03-08
11:35:34 UTC (rev 113359)
+++ trunk/extensions/VisualEditor/modules/parser/parse.js 2012-03-08
11:44:37 UTC (rev 113360)
@@ -50,7 +50,7 @@
wgScriptPath: argv.wgScriptPath,
wgScriptExtension:
argv.wgScriptExtension,
// XXX: add options for this!
- wgUploadPath:
'http://upload.wikimedia.org/wikipedia/commons/thumb',
+ wgUploadPath:
'http://upload.wikimedia.org/wikipedia/commons',
fetchTemplates:
argv.fetchTemplates,
// enable/disable debug output
using this switch
debug: argv.debug,
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs