2011-11-02 21:07:51 +00:00
|
|
|
var MWParserEnvironment = function(opts) {
|
|
|
|
var options = {
|
|
|
|
tagHooks: {},
|
|
|
|
parserFunctions: {},
|
|
|
|
pageCache: {}, // @fixme use something with managed space
|
|
|
|
domCache: {}
|
|
|
|
};
|
|
|
|
$.extend(options, opts);
|
|
|
|
this.debug = false;
|
|
|
|
this.tagHooks = options.tagHooks;
|
|
|
|
this.parserFunctions = options.parserFunctions;
|
|
|
|
this.pageCache = options.pageCache;
|
|
|
|
this.domCache = options.domCache;
|
|
|
|
};
|
|
|
|
|
2012-01-10 01:09:50 +00:00
|
|
|
MWParserEnvironment.prototype.lookupKV = function ( kvs, key ) {
|
|
|
|
var kv;
|
|
|
|
for ( var i = 0, l = kvs.length; i < l; i++ ) {
|
|
|
|
kv = kvs[i];
|
|
|
|
if ( kv[0] === key ) {
|
|
|
|
// found, return it.
|
|
|
|
return kv[1];
|
2011-11-02 21:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-10 01:09:50 +00:00
|
|
|
// nothing found!
|
|
|
|
return null;
|
|
|
|
};
|
2011-11-02 21:07:51 +00:00
|
|
|
|
|
|
|
|
2012-01-10 01:09:50 +00:00
|
|
|
// Does this need separate UI/content inputs?
|
|
|
|
MWParserEnvironment.prototype.formatNum = function( num ) {
|
|
|
|
return num + '';
|
|
|
|
};
|
2011-11-02 21:07:51 +00:00
|
|
|
|
2012-01-10 01:09:50 +00:00
|
|
|
MWParserEnvironment.prototype.getVariable = function( varname, options ) {
|
2011-11-02 21:07:51 +00:00
|
|
|
//
|
2012-01-10 01:09:50 +00:00
|
|
|
};
|
2011-11-02 21:07:51 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-10 01:09:50 +00:00
|
|
|
* @return MWParserFunction
|
2011-11-02 21:07:51 +00:00
|
|
|
*/
|
2012-01-10 01:09:50 +00:00
|
|
|
MWParserEnvironment.prototype.getParserFunction = function( name ) {
|
|
|
|
if (name in this.parserFunctions) {
|
|
|
|
return new this.parserFunctions[name]( this );
|
|
|
|
} else {
|
|
|
|
return null;
|
2011-11-02 21:07:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-01-10 01:09:50 +00:00
|
|
|
* @return MWParserTagHook
|
2011-11-02 21:07:51 +00:00
|
|
|
*/
|
2012-01-10 01:09:50 +00:00
|
|
|
MWParserEnvironment.prototype.getTagHook = function( name ) {
|
|
|
|
if (name in this.tagHooks) {
|
|
|
|
return new this.tagHooks[name](this);
|
|
|
|
} else {
|
|
|
|
return null;
|
2011-11-02 21:07:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-01-10 01:09:50 +00:00
|
|
|
* @fixme do this for real eh
|
2011-11-02 21:07:51 +00:00
|
|
|
*/
|
2012-01-10 01:09:50 +00:00
|
|
|
MWParserEnvironment.prototype.resolveTitle = function( name, namespace ) {
|
|
|
|
// hack!
|
|
|
|
if (name.indexOf(':') == -1 && typeof namespace ) {
|
|
|
|
// hack hack hack
|
|
|
|
name = namespace + ':' + name;
|
|
|
|
}
|
|
|
|
return name;
|
2011-11-02 21:07:51 +00:00
|
|
|
};
|
|
|
|
|
2012-01-11 19:48:49 +00:00
|
|
|
MWParserEnvironment.prototype.tokensToString = function ( tokens ) {
|
|
|
|
var out = [];
|
|
|
|
// XXX: quick hack, track down non-array sources later!
|
|
|
|
if ( ! $.isArray( tokens ) ) {
|
|
|
|
tokens = [ tokens ];
|
|
|
|
}
|
|
|
|
for ( var i = 0, l = tokens.length; i < l; i++ ) {
|
|
|
|
console.log( 'MWParserEnvironment.tokensToString: ' + token );
|
|
|
|
var token = tokens[i];
|
|
|
|
if ( token.type === 'TEXT' ) {
|
|
|
|
out.push( token.value );
|
|
|
|
} else {
|
|
|
|
var tstring = JSON.stringify( token );
|
|
|
|
console.log ( 'MWParserEnvironment::tokensToString: ' + tstring );
|
|
|
|
out.push( tstring );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out.join('');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-10 01:09:50 +00:00
|
|
|
|
2011-11-02 21:07:51 +00:00
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports.MWParserEnvironment = MWParserEnvironment;
|
|
|
|
}
|