r60281 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60280‎ | r60281 | r60282 >
Date:22:36, 21 December 2009
Author:dale
Status:deferred
Tags:
Comment:
* added in stubs for "kaltura search"
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/kalturaSearch.js (added) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/mediaWikiSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/metavidSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/kalturaSearch.js
@@ -0,0 +1,128 @@
 2+/*
 3+ * Kaltura agragated search:
 4+ */
 5+
 6+var kalturaSearch = function ( options ) {
 7+ return this.init( options );
 8+}
 9+kalturaSearch.prototype = {
 10+
 11+ // Stores search library pointers
 12+ searchLibs:{ },
 13+
 14+ /**
 15+ * Initialize the flickr Search with provided options
 16+ *
 17+ * @param {Object} options Initial options for the kalturaSearch class
 18+ */
 19+ init:function( options ) {
 20+ this.options = options;
 21+ var baseSearch = new baseRemoteSearch( options );
 22+ for ( var i in baseSearch ) {
 23+ if ( typeof this[i] == 'undefined' ) {
 24+ this[i] = baseSearch[i];
 25+ } else {
 26+ this['parent_' + i] = baseSearch[i];
 27+ }
 28+ }
 29+ },
 30+
 31+ /**
 32+ * Get the Search results setting _loading flag to false once results have been added
 33+ *
 34+ * Runs an api call then calls addResults with the resulting data
 35+ * @param {String} search_query Text search string
 36+ */
 37+ getSearchResults:function( search_query ) {
 38+ var _this = this;
 39+ mw.log( "Kaltura::getSearchResults" );
 40+
 41+ // call parent for common initialisation:
 42+ this.parent_getSearchResults();
 43+
 44+ // setup the flickr request:
 45+ var request = {
 46+ 's': search_query
 47+ }
 48+ $j.getJSON( this.provider.api_url + '?callback=?', request, function( data ) {
 49+ _this.addResults( data );
 50+ _this.loading = false;
 51+ } );
 52+ },
 53+
 54+ /**
 55+ * Adds results from kaltura api data response object
 56+ *
 57+ * @param {Object} data Fliker response data
 58+ */
 59+ addResults:function( data ) {
 60+ var _this = this;
 61+ this.provider_libs = { };
 62+
 63+ if ( data ) {
 64+ // set result info:
 65+ //this.num_results = data.photos.total;
 66+ //if ( this.num_results > this.provider.offset + this.provider.limit ) {
 67+ // this.more_results = true;
 68+ //}
 69+ for ( var resource_id in data ) {
 70+ var result = data[ resource_id ];
 71+
 72+ // Update mapings:
 73+ result['poster'] = result['thumbnail'];
 74+ result['pSobj'] = _this;
 75+
 76+ if( !result['titleKey'] && result['src'] ){
 77+ result['titleKey'] = 'File:' + result['src'].split('/').pop();
 78+ }
 79+ _this.resultsObj[ resource_id ] = result;
 80+
 81+ }
 82+ }
 83+ },
 84+
 85+ /**
 86+ * Return image transform via callback
 87+ * Maps the image request to the proper search library helper
 88+ *
 89+ * @param {Object} resource Resource object
 90+ * @param {Number} size Requested size
 91+ * @param {Function} callback Callback function for image resource
 92+ */
 93+ getImageObj: function( resource, size, callback ) {
 94+ var _this = this;
 95+ this.getSerachLib( resource.content_provider_id, function( searchLib ){
 96+ searchLib.getImageObj( resource, size, callback );
 97+ });
 98+ },
 99+
 100+ /**
 101+ * Get and load provider via id
 102+ * @param {String} provider_id The id of the content provider
 103+ * @param {Function} callback Function to call once provider search lib is loaded
 104+ * callback is passed the search object
 105+ */
 106+ getSerachLib: function( provider_id, callback ){
 107+ var _this = this;
 108+ // Check if we already have the library loaded:
 109+ if( this.searchLibs[ provider_id ] ){
 110+ callback ( this.searchLibs[ provider_id ] );
 111+ return ;
 112+ }
 113+ // Else load the provider lib:
 114+ var provider = this.rsd.content_providers [ provider_id ];
 115+ mw.load( provider.lib + 'Search', function(){
 116+ //Set up the search lib options
 117+ var options = {
 118+ 'provider': provider,
 119+ // Same remote search driver as KalturaSearch
 120+ 'rsd': _this.rsd
 121+ }
 122+ _this.searchLibs[ provider_id ] = new window[ provider.lib + 'Search' ]( options );
 123+ callback ( _this.searchLibs[ provider_id ] );
 124+ } );
 125+ }
 126+
 127+
 128+
 129+}
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/mediaWikiSearch.js
@@ -299,7 +299,7 @@
300300 var request = {
301301 'action':'query',
302302 'format':'json',
303 - 'titles':resource.titleKey,
 303+ 'titles' : resource.titleKey,
304304 'prop':'imageinfo',
305305 'iiprop':'url|size|mime'
306306 }
@@ -307,11 +307,16 @@
308308 if ( size.width )
309309 request['iiurlwidth'] = size.width;
310310
311 - mw.log( 'going to do req: ' + this.provider.api_url + ' ' + request );
 311+ mw.log( 'going to do req: ' + this.provider.api_url + ' ' + resource.titleKey );
312312
313 - mw.getJSON( this.provider.api_url, request, function( data ) {
 313+ mw.getJSON( this.provider.api_url, request, function( data ) {
314314 var imObj = { };
315315 for ( var page_id in data.query.pages ) {
 316+ if( page_id == -1 ){
 317+ mw.log( 'Error: missing page for title: ' + resource.titleKey )
 318+ continue;
 319+ }
 320+
316321 var iminfo = data.query.pages[ page_id ].imageinfo[0];
317322 // store the orginal width:
318323 imObj['org_width'] = iminfo.width;
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/archiveOrgSearch.js
@@ -65,7 +65,7 @@
6666 * @param {Object} data Api result data
6767 */
6868 addResults:function( data ) {
69 - var _this = this;
 69+ var _this = this;
7070 if ( data.response && data.response.docs ) {
7171 // Set result info:
7272 this.num_results = data.response.numFound;
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/metavidSearch.js
@@ -117,7 +117,7 @@
118118 /**
119119 * Get additional wiki text description
120120 *
121 - * @param {Object} resource Resource to get addtional wikitext for.
 121+ * @param {Object} resource Resource to get additional wikitext for.
122122 */
123123 getExtraResourceDescWiki:function( resource ) {
124124 var o = "\n";
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js
@@ -21,7 +21,8 @@
2222 "metavidSearch" : "modules/AddMedia/searchLibs/metavidSearch.js",
2323 "archiveOrgSearch" : "modules/AddMedia/searchLibs/archiveOrgSearch.js",
2424 "flickrSearch" : "modules/AddMedia/searchLibs/flickrSearch.js",
25 - "baseRemoteSearch" : "modules/AddMedia/searchLibs/baseRemoteSearch.js"
 25+ "baseRemoteSearch" : "modules/AddMedia/searchLibs/baseRemoteSearch.js",
 26+ "kalturaSearch" : "modules/AddMedia/searchLibs/kalturaSearch.js"
2627 });
2728
2829 /**
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -57,6 +57,9 @@
5858 "rsd-wiki_commons-title": "Wikimedia Commons",
5959 "rsd-wiki_commons": "Wikimedia Commons, an archive of freely-licensed educational media content (images, sound and video clips)",
6060
 61+ "rsd-kaltura-title" : "Kaltura search",
 62+ "rsd-kaltura" : "Kaltura agragated search for free-licenced media across multiple search providers",
 63+
6164 "rsd-this_wiki-title" : "This wiki",
6265 "rsd-this_wiki-desc" : "The local wiki install",
6366
@@ -126,8 +129,11 @@
127130 // Enabled providers can be keyword 'all' or an array of enabled content provider keys
128131 'enabled_providers': 'all',
129132
 133+ // Set a default provider
 134+ 'default_provider': null,
 135+
130136 // Current provider (used internally)
131 - 'currentProvider': null,
 137+ 'current_provider': null,
132138
133139 // The timeout for search providers ( in seconds )
134140 'search_provider_timeout': 10
@@ -243,7 +249,7 @@
244250 'tab_img': false
245251 },
246252
247 - /*
 253+ /**
248254 * Wikipedia Commons search provider configuration
249255 */
250256 'wiki_commons': {
@@ -267,6 +273,18 @@
268274
269275 },
270276
 277+ /*
 278+ * Kaltura aggregated search
 279+ */
 280+ 'kaltura': {
 281+ 'enabled': 1,
 282+ 'checked': 1,
 283+ 'homepage': 'http://kaltura.com',
 284+ 'api_url': 'http://kaldev.kaltura.com/michael/federator.php',
 285+ 'lib': 'kaltura',
 286+ 'tab_image':false
 287+ },
 288+
271289 /**
272290 * Internet archive search provider configuration
273291 */
@@ -399,7 +417,7 @@
400418 // A flag for proxy setup.
401419 proxySetupDone: null,
402420
403 - /*
 421+ /**
404422 * The initialisation function
405423 *
406424 * @param {Object} options Options to override: default_remote_search_options
@@ -418,24 +436,27 @@
419437 if ( _this.enabled_providers.length == 1 && _this.enabled_providers[0] == 'all' )
420438 _this.enabled_providers = 'all';
421439
 440+ // Set the current_provider from default_provider
 441+ if( this.default_provider && this.content_providers[ this.default_provider ] ){
 442+ this.current_provider = this.default_provider;
 443+ }
 444+
422445 // Set up content_providers
423446 for ( var provider_id in this.content_providers ) {
 447+ var provider = this.content_providers[ provider_id ];
424448 // Set the provider id
425 - this.content_providers[ provider_id ][ 'id' ] = provider_id
426 -
427 - //Set local provider var:
428 - var provider = this.content_providers[ provider_id ];
429 -
430 - if ( _this.enabled_providers == 'all' && !this.currentProvider && provider.api_url ) {
431 - this.currentProvider = provider_id;
 449+ provider[ 'id' ] = provider_id
 450+
 451+ if ( _this.enabled_providers == 'all' && !this.current_provider && provider.api_url ) {
 452+ this.current_provider = provider_id;
432453 break;
433454 } else {
434455 if ( $j.inArray( provider_id, _this.enabled_providers ) != -1 ) {
435456 // This provider is enabled
436457 this.content_providers[ provider_id ].enabled = true;
437458 // Set the current provider to the first enabled one
438 - if ( !this.currentProvider ) {
439 - this.currentProvider = provider_id;
 459+ if ( !this.current_provider ) {
 460+ this.current_provider = provider_id;
440461 }
441462 } else {
442463 // This provider is disabled
@@ -634,6 +655,13 @@
635656 showDialog: function() {
636657 var _this = this;
637658 mw.log( "showDialog::" );
 659+
 660+ // Check if dialog target is present:
 661+ if( $j( _this.target_container ).length == 0 ){
 662+ this.createUI();
 663+ return ;
 664+ }
 665+
638666 _this.clearTextboxCache();
639667 var query = _this.getDefaultQuery();
640668 if ( query != $j( '#rsd_q' ).val() ) {
@@ -682,7 +710,7 @@
683711 return this.textboxValue;
684712 },
685713
686 - /*
 714+ /**
687715 * Get the default query from the text selection
688716 */
689717 getDefaultQuery: function() {
@@ -942,13 +970,13 @@
943971 },
944972
945973 /**
946 - * Show the current tab ( based on currentProvider var )
 974+ * Show the current tab ( based on current_provider var )
947975 */
948976 showCurrentTab: function() {
949 - if ( this.currentProvider == 'upload' ) {
 977+ if ( this.current_provider == 'upload' ) {
950978 this.showUploadTab();
951979 } else {
952 - this.showSearchTab( this.currentProvider, false );
 980+ this.showSearchTab( this.current_provider, false );
953981 }
954982 },
955983
@@ -1108,11 +1136,11 @@
11091137 } );
11101138 return false;
11111139 } else if ( !this.isProviderLocal( provider ) && this.import_url_mode == 'none' ) {
1112 - if ( this.currentProvider == 'combined' ) {
 1140+ if ( this.current_provider == 'combined' ) {
11131141 // combined results are harder to error handle just ignore that repo
11141142 provider.sObj.loading = false;
11151143 } else {
1116 - $j( '#tab-' + this.currentProvider ).html(
 1144+ $j( '#tab-' + this.current_provider ).html(
11171145 '<div style="padding:10px">' +
11181146 gM( 'mwe-no_import_by_url' ) +
11191147 '</div>' );
@@ -1149,12 +1177,12 @@
11501178 provider.lib + 'Search'
11511179 ], function() {
11521180 mw.log( "loaded lib:: " + provider.lib );
1153 - // else we need to run the search:
 1181+ // Else we need to run the search:
11541182 var options = {
11551183 'provider': provider,
11561184 'rsd': _this
11571185 };
1158 - eval( 'provider.sObj = new ' + provider.lib + 'Search( options );' );
 1186+ provider.sObj = new window[ provider.lib + 'Search' ]( options );
11591187 if ( !provider.sObj ) {
11601188 mw.log( 'Error: could not find search lib for ' + cp_id );
11611189 return false;
@@ -1227,7 +1255,7 @@
12281256 var tabImage = mw.getMwEmbedPath() + '/skins/common/remote_cp/' + providerName + '_tab.png';
12291257 if ( provider.enabled && provider.checked && provider.api_url ) {
12301258 // Add selected default if set
1231 - if ( this.currentProvider == providerName )
 1259+ if ( this.current_provider == providerName )
12321260 selected_tab = index;
12331261
12341262 s += '<li class="rsd_cp_tab">';
@@ -1252,7 +1280,7 @@
12531281 gM( 'mwe-upload_tab' ) +
12541282 '</a></li>';
12551283 content += '<div id="tab-upload" />';
1256 - if ( this.currentProvider == 'upload' )
 1284+ if ( this.current_provider == 'upload' )
12571285 selected_tab = index++;
12581286 }
12591287 s += '</ul>';
@@ -1301,33 +1329,33 @@
13021330 },
13031331
13041332 /**
1305 - * Show Results for the currentProvider
 1333+ * Show Results for the current_provider
13061334 */
13071335 showResults: function() {
1308 - mw.log( 'f:showResults::' + this.currentProvider );
 1336+ mw.log( 'f:showResults::' + this.current_provider );
13091337 var _this = this;
13101338 var o = '';
13111339 var tabSelector = '';
13121340
1313 - if ( this.currentProvider == 'upload' ) {
 1341+ if ( this.current_provider == 'upload' ) {
13141342 tabSelector = '#upload_bin';
13151343 var provider = _this.content_providers['this_wiki'];
13161344 } else {
1317 - var provider = this.content_providers[ this.currentProvider ];
1318 - tabSelector = '#tab-' + this.currentProvider;
 1345+ var provider = this.content_providers[ this.current_provider ];
 1346+ tabSelector = '#tab-' + this.current_provider;
13191347 // Output the results bar / controls
13201348 }
13211349
13221350 // Empty the existing results:
13231351 $j( tabSelector ).empty();
13241352
1325 - if ( this.currentProvider != 'upload' ) {
 1353+ if ( this.current_provider != 'upload' ) {
13261354 _this.showResultsHeader();
13271355 }
13281356
13291357 var numResults = 0;
13301358
1331 - // Output all the results for the current currentProvider
 1359+ // Output all the results for the current current_provider
13321360 if ( typeof provider['sObj'] != 'undefined' ) {
13331361 $j.each( provider.sObj.resultsObj, function( resIndex, resource ) {
13341362 o += _this.getResultHtml( provider, resIndex, resource );
@@ -1357,7 +1385,7 @@
13581386 showFailure : function( resultStatus ){
13591387 //only one type of resultStatus right now:
13601388 if( resultStatus == 'timeout' )
1361 - $j( '#tab-' + this.currentProvider ).text(
 1389+ $j( '#tab-' + this.current_provider ).text(
13621390 gM('rsd-search-timeout')
13631391 )
13641392 },
@@ -1397,7 +1425,7 @@
13981426 // Get a thumb with proper resolution transform if possible:
13991427 var thumbUrl = provider.sObj.getImageTransform( resource,
14001428 { 'width' : this.thumb_width } );
1401 -
 1429+
14021430 o += '<img title="' + resource.title + '" ' +
14031431 'class="rsd_res_item" id="res_' + provider.id + '__' + resIndex + '" ' +
14041432 'style="width:' + this.thumb_width + 'px;" ' +
@@ -1879,8 +1907,8 @@
18801908 var proto = {};
18811909 proto.prototype = resource;
18821910 var myRes = new proto;
1883 - */
1884 -
 1911+ */
 1912+
18851913 // Update base target_resource_title:
18861914 resource.target_resource_title = resource.titleKey.replace( /^(File:|Image:)/ , '' )
18871915
@@ -1948,7 +1976,8 @@
19491977 }
19501978 } );
19511979 },
1952 - /*
 1980+
 1981+ /**
19531982 * Show Import User Interface
19541983 *
19551984 * @param {Object} resource Resource Object to be imported
@@ -2484,12 +2513,12 @@
24852514 var darkListUrl = mw.getConfig( 'skin_img_path' ) + 'list_layout_icon_dark.png';
24862515 var lightListUrl = mw.getConfig( 'skin_img_path' ) + 'list_layout_icon.png';
24872516
2488 - if ( !this.content_providers[ this.currentProvider ] ) {
 2517+ if ( !this.content_providers[ this.current_provider ] ) {
24892518 return;
24902519 }
2491 - var cp = this.content_providers[this.currentProvider];
 2520+ var cp = this.content_providers[this.current_provider];
24922521 var resultsFromMsg = gM( 'mwe-results_from',
2493 - [ cp.homepage, gM( 'rsd-' + this.currentProvider + '-title' ) ] );
 2522+ [ cp.homepage, gM( 'rsd-' + this.current_provider + '-title' ) ] );
24942523 var defaultBoxUrl, defaultListUrl;
24952524 if ( _this.displayMode == 'box' ) {
24962525 defaultBoxUrl = darkBoxUrl;
@@ -2502,7 +2531,7 @@
25032532 var about_desc = '<span style="position:relative;top:0px;font-style:italic;">' +
25042533 '<i>' + resultsFromMsg + '</i></span>';
25052534
2506 - $j( '#tab-' + this.currentProvider ).append( '<div id="rds_results_bar">' +
 2535+ $j( '#tab-' + this.current_provider ).append( '<div id="rds_results_bar">' +
25072536 '<span style="float:left;top:0px;font-style:italic;">' +
25082537 gM( 'rsd_layout' ) + ' ' +
25092538 '<img id="msc_box_layout" ' +
@@ -2552,19 +2581,19 @@
25532582 },
25542583
25552584 /**
2556 - * Shows pagging for a given target for a given currentProvider
 2585+ * Shows pagging for a given target for a given current_provider
25572586 *
25582587 * @param {String} target jQuery Selector for pagging Header output
25592588 */
25602589 showPagingHeader: function( target ) {
25612590 var _this = this;
2562 - if ( _this.currentProvider == 'upload' ) {
 2591+ if ( _this.current_provider == 'upload' ) {
25632592 var provider = _this.content_providers['this_wiki'];
25642593 } else {
2565 - var provider = _this.content_providers[ _this.currentProvider ];
 2594+ var provider = _this.content_providers[ _this.current_provider ];
25662595 }
25672596 var search = provider.sObj;
2568 - mw.log( 'showPagingHeader:' + _this.currentProvider + ' len: ' + search.num_results );
 2597+ mw.log( 'showPagingHeader:' + _this.current_provider + ' len: ' + search.num_results );
25692598 var to_num = ( provider.limit > search.num_results ) ?
25702599 ( parseInt( provider.offset ) + parseInt( search.num_results ) ) :
25712600 ( parseInt( provider.offset ) + parseInt( provider.limit ) );
@@ -2610,8 +2639,8 @@
26112640 */
26122641 selectTab: function( provider_id ) {
26132642 mw.log( 'select tab: ' + provider_id );
2614 - this.currentProvider = provider_id;
2615 - if ( this.currentProvider == 'upload' ) {
 2643+ this.current_provider = provider_id;
 2644+ if ( this.current_provider == 'upload' ) {
26162645 this.showUploadTab();
26172646 } else {
26182647 // update the search results:
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1297,7 +1297,7 @@
12981298 if( !data['format'] )
12991299 data['format'] = 'json';
13001300
1301 - mw.log("run getJSON: " + url + ' data: ' + data['action'] + ' apiPost: ' +mw.getConfig( 'apiPostActions' ) );
 1301+ mw.log("run getJSON: " + url + ' data: ' + data['action'] );
13021302
13031303 if( $j.inArray( data['action'], mw.getConfig( 'apiPostActions' ) ) != -1 ){
13041304 if( ! mw.isLocalDomain( url ) ){

Status & tagging log