<commit_before>/*********************************************
* A minimal wrapper for kaltura server api
* 
* Supports static requests,
* Auto includes kWidget for userKS queries ( where admin ks is not provided )
* Makes use of defined: 
* 	'Kaltura.ServiceUrl', 'http://cdnapi.kaltura.com' );
* 		&&
*	'Kaltura.ServiceBase'
**********************************************/
(function( kWidget ){ "use strict"
if( !kWidget ){
	kWidget = window.kWidget = {};
}
kWidget.api = function( options ){
	return this.init( options );
};
kWidget.api.prototype = {
	ks: null,
	// the default api request method
	// will dictate if the CDN can cache on a per url basis
	type: 'auto',
	// initialize callback index to zero
	callbackIndex: 0,
	baseParam: {
		'apiVersion' : '3.1',
		'expiry' : '86400',
		'clientTag': 'kwidget:v' + window[ 'MWEMBED_VERSION' ],
		'format' : 9, // 9 = JSONP format
		'ignoreNull' : 1
	},
	/**
	 * Init the api object:
	 * options {Object} Set of init options
	 */
	init: function( options  ){
		for( var i in options ){
			this[i] = options[i];
		}
		// check for globals if not set, use mw.getConfig
		if( ! this.serviceUrl ){
			this.serviceUrl = mw.getConfig( 'Kaltura.ServiceUrl' );
		}
		if( ! this.serviceBase ){
			this.serviceBase = mw.getConfig( 'Kaltura.ServiceBase' ); 
		}
		if( ! this.statsServiceUrl ){
			this.statsServiceUrl = mw.getConfig( 'Kaltura.StatsServiceUrl' );
		}
		if( typeof this.disableCache == 'undefined' ){
			this.disableCache = mw.getConfig('Kaltura.NoApiCache');
		}
	},
	setKs: function( ks ){
		this.ks = ks;
	},
	getKs: function(){
		return this.ks;
	},
	forceKs:function(wid,callback,errorCallback){
		if( this.getKs() ){
			callback( this.getKs() );
			return true;
		}
		var _this = this;
		// Add the Kaltura session ( if not already set )
		var ksParam = {
			'action' : 'startwidgetsession',
			'widgetId': wid
		};
		// add in the base parameters:
		var param = kWidget.extend( { 'service' : 'session' }, this.baseParam, ksParam );
		this.doRequest( param, function( data ){
			_this.ks = data.ks;
			callback( _this.ks );
		},null,errorCallback);
	},
	/**
	 * Do an api request and get data in callback
	 */
	doRequest: function ( requestObject, callback,skipKS, errorCallback, withProxyData){
		var _this = this;
		var param = {};
		var globalCBName = null;
		// If we have Kaltura.NoApiCache flag, pass 'nocache' param to the client
		if( this.disableCache === true ) {
			param['nocache'] = 'true';
		}
		
		// Add in the base parameters:
		for( var i in this.baseParam ){
			if( typeof param[i] == 'undefined' ){
				param[i] = this.baseParam[i];
			}
		};

		// Check for "user" service queries ( no ks or wid is provided  )
		if( requestObject['service'] != 'user' && !skipKS ){
			kWidget.extend( param, this.handleKsServiceRequest( requestObject ) );
		} else {
			kWidget.extend( param, requestObject );
		}

		// set format to JSON ( Access-Control-Allow-Origin:* )
		param['format'] = 1;

		// Add kalsig to query:
		param[ 'kalsig' ] = this.hashCode( kWidget.param( param ) );
		
		// Remove service tag ( hard coded into the api url )
		var serviceType = param['service'];
		delete param['service'];

		var timeoutError = setTimeout(function(){
			if ( globalCBName ) {
				window[globalCBName] = undefined;
			}
			if (errorCallback){
				errorCallback();
			}
			//mw.log("Timeout occur in doApiRequest");
		},mw.getConfig("Kaltura.APITimeout"));

		var handleDataResult = function( data ){
			clearTimeout(timeoutError);
			// check if the base param was a session
            data = data || [];
            if( data.length > 1 && param[ '1:service' ] == 'session' && !withProxyData){
				//Set the returned ks
	            _this.setKs(data[0].ks);
	            // if original request was not a multirequest then directly return the data object
	            // if original request was a multirequest then remove the session from the returned data objects
	            if (data.length == 2){
		            data = data[1];
	            } else {
		            data.shift();
	            }
			}
			// issue the local scope callback:
			if( callback ){
				callback( data );
				callback = null;
			}
		};

		// Run the request
		// NOTE kaltura api server should return: 
		// Access-Control-Allow-Origin:* most browsers support this. 
		// ( old browsers with large api payloads are not supported )
		var userAgent = navigator.userAgent.toLowerCase();
		var forceJSONP = document.documentMode && document.documentMode <= 10;
		try {
			if ( forceJSONP ){
				throw "forceJSONP";
			}<commit_msg>adding a comment for using the proxyData parameter<commit_after>/*********************************************
* A minimal wrapper for kaltura server api
* 
* Supports static requests,
* Auto includes kWidget for userKS queries ( where admin ks is not provided )
* Makes use of defined: 
* 	'Kaltura.ServiceUrl', 'http://cdnapi.kaltura.com' );
* 		&&
*	'Kaltura.ServiceBase'
**********************************************/
(function( kWidget ){ "use strict"
if( !kWidget ){
	kWidget = window.kWidget = {};
}
kWidget.api = function( options ){
	return this.init( options );
};
kWidget.api.prototype = {
	ks: null,
	// the default api request method
	// will dictate if the CDN can cache on a per url basis
	type: 'auto',
	// initialize callback index to zero
	callbackIndex: 0,
	baseParam: {
		'apiVersion' : '3.1',
		'expiry' : '86400',
		'clientTag': 'kwidget:v' + window[ 'MWEMBED_VERSION' ],
		'format' : 9, // 9 = JSONP format
		'ignoreNull' : 1
	},
	/**
	 * Init the api object:
	 * options {Object} Set of init options
	 */
	init: function( options  ){
		for( var i in options ){
			this[i] = options[i];
		}
		// check for globals if not set, use mw.getConfig
		if( ! this.serviceUrl ){
			this.serviceUrl = mw.getConfig( 'Kaltura.ServiceUrl' );
		}
		if( ! this.serviceBase ){
			this.serviceBase = mw.getConfig( 'Kaltura.ServiceBase' ); 
		}
		if( ! this.statsServiceUrl ){
			this.statsServiceUrl = mw.getConfig( 'Kaltura.StatsServiceUrl' );
		}
		if( typeof this.disableCache == 'undefined' ){
			this.disableCache = mw.getConfig('Kaltura.NoApiCache');
		}
	},
	setKs: function( ks ){
		this.ks = ks;
	},
	getKs: function(){
		return this.ks;
	},
	forceKs:function(wid,callback,errorCallback){
		if( this.getKs() ){
			callback( this.getKs() );
			return true;
		}
		var _this = this;
		// Add the Kaltura session ( if not already set )
		var ksParam = {
			'action' : 'startwidgetsession',
			'widgetId': wid
		};
		// add in the base parameters:
		var param = kWidget.extend( { 'service' : 'session' }, this.baseParam, ksParam );
		this.doRequest( param, function( data ){
			_this.ks = data.ks;
			callback( _this.ks );
		},null,errorCallback);
	},
	/**
	 * Do an api request and get data in callback
	 */
	doRequest: function ( requestObject, callback,skipKS, errorCallback, withProxyData){
		var _this = this;
		var param = {};
		var globalCBName = null;
		// If we have Kaltura.NoApiCache flag, pass 'nocache' param to the client
		if( this.disableCache === true ) {
			param['nocache'] = 'true';
		}
		
		// Add in the base parameters:
		for( var i in this.baseParam ){
			if( typeof param[i] == 'undefined' ){
				param[i] = this.baseParam[i];
			}
		};

		// Check for "user" service queries ( no ks or wid is provided  )
		if( requestObject['service'] != 'user' && !skipKS ){
			kWidget.extend( param, this.handleKsServiceRequest( requestObject ) );
		} else {
			kWidget.extend( param, requestObject );
		}

		// set format to JSON ( Access-Control-Allow-Origin:* )
		param['format'] = 1;

		// Add kalsig to query:
		param[ 'kalsig' ] = this.hashCode( kWidget.param( param ) );
		
		// Remove service tag ( hard coded into the api url )
		var serviceType = param['service'];
		delete param['service'];

		var timeoutError = setTimeout(function(){
			if ( globalCBName ) {
				window[globalCBName] = undefined;
			}
			if (errorCallback){
				errorCallback();
			}
			//mw.log("Timeout occur in doApiRequest");
		},mw.getConfig("Kaltura.APITimeout"));

		var handleDataResult = function( data ){
			clearTimeout(timeoutError);
			// check if the base param was a session
            data = data || [];
            if( data.length > 1 && param[ '1:service' ] == 'session' && !withProxyData){ // in case of proxyData (OTT) we request a session but KS doesn't exist
																						 // so the response doesn't contain it so don't handle
				//Set the returned ks
	            _this.setKs(data[0].ks);
	            // if original request was not a multirequest then directly return the data object
	            // if original request was a multirequest then remove the session from the returned data objects
	            if (data.length == 2){
		            data = data[1];
	            } else {
		            data.shift();
	            }
			}
			// issue the local scope callback:
			if( callback ){
				callback( data );
				callback = null;
			}
		};

		// Run the request
		// NOTE kaltura api server should return: 
		// Access-Control-Allow-Origin:* most browsers support this. 
		// ( old browsers with large api payloads are not supported )
		var userAgent = navigator.userAgent.toLowerCase();
		var forceJSONP = document.documentMode && document.documentMode <= 10;
		try {
			if ( forceJSONP ){
				throw "forceJSONP";
			}
{'fraction_non_alphanumeric': 0.15233704974271012, 'fraction_numerical': 0.004073756432246998, 'mean_word_length': 2.9816474605207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3181680', 'n_tokens_mistral': 3326, 'n_tokens_neox': 2932, 'n_words': 877}