r63795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63794‎ | r63795 | r63796 >
Date:01:46, 16 March 2010
Author:dale
Status:deferred
Tags:
Comment:
* bumped revision number
* added improved subtitle support for inside the add-media-wizard
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/baseRemoteSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/mediaWikiSearch.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/mediaWikiSearch.js
@@ -194,13 +194,20 @@
195195 }
196196
197197 // Skip if its an empty or missing imageinfo:
198 - if ( !page.imageinfo )
 198+ if ( !page.imageinfo ){
199199 continue;
 200+ }
 201+
 202+ // Get the url safe titleKey from the descriptionurl
 203+ var titleKey = page.imageinfo[0].descriptionurl.split( '/' );
 204+ titleKey = unescape( titleKey[ titleKey.length - 1 ] );
 205+ titleKey = titleKey.replace( /File:|Image:/, '' );
 206+
200207 var resource = {
201208 'id' : page_id,
202 - 'titleKey' : page.title,
 209+ 'titleKey' : titleKey,
203210 'link' : page.imageinfo[0].descriptionurl,
204 - 'title' : page.title.replace(/File:.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''),
 211+ 'title' : page.title.replace(/File:|.jpg|.png|.svg|.ogg|.ogv|.oga/ig, ''),
205212 'poster' : page.imageinfo[0].thumburl,
206213 'thumbwidth' : page.imageinfo[0].thumbwidth,
207214 'thumbheight': page.imageinfo[0].thumbheight,
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/searchLibs/baseRemoteSearch.js
@@ -241,22 +241,33 @@
242242 outHtml = this.getImageEmbedHTML( resource, options );
243243 }
244244
245 - if ( resource.mime == 'application/ogg' || resource.mime == 'video/ogg' || resource.mime == 'audio/ogg' ) {
 245+ if ( resource.mime == 'application/ogg'
 246+ || resource.mime == 'video/ogg'
 247+ || resource.mime == 'audio/ogg'
 248+ ) {
246249 // Setup the attribute html
247250 // NOTE: Can't use jQuery builder for video element, ( does not work consistently )
248251 var ahtml = ( options['id'] ) ? ' id = "' + options['id'] + '" ': '';
249 - ahtml+= 'src="' + mw.escapeQuotesHTML( resource.src ) + '" ' +
250 - //'class="' + mw.getConfig( 'skinName' ) + '" ' +
251 - // mannualy set kskin (while mw.setConfig is not available on all pages )
252 - 'class="kskin" '+
 252+ ahtml+= 'src="' + mw.escapeQuotesHTML( resource.src ) + '" ' +
 253+ // Mannualy set kskin, NOTE: should be config option
 254+ 'class="kskin" ' +
253255 'style="' + options.style + '" ' +
254256 'poster="' + mw.escapeQuotesHTML( resource.poster ) + '" '+
255257 'type="' + mw.escapeQuotesHTML( resource.mime ) + '" ';
256 -
 258+
 259+
257260 // Add the api title key if available:
258261 if( resource.titleKey ) {
259 - 'apiTitleKey="' + mw.escapeQuotesHTML( resource.titleKey ) + '" ';
260 - }
 262+ ahtml+= 'apiTitleKey="' + mw.escapeQuotesHTML( resource.titleKey ) + '" ';
 263+ }
 264+
 265+ // Add the commons apiProvider if the resource is from commons
 266+ // ( so that subtitles can be displayed / edited )
 267+ if( resource.pSobj.provider.id == 'wiki_commons'
 268+ || resource.commonsShareRepoFlag
 269+ ){
 270+ ahtml+= 'apiProvider="commons" ';
 271+ }
261272
262273 if ( resource.mime == 'application/ogg' || resource.mime == 'video/ogg' ) {
263274 outHtml = '<video ' + ahtml + '></video>';
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -156,10 +156,7 @@
157157 'default_provider': null,
158158
159159 // The timeout for search providers ( in seconds )
160 - 'search_provider_timeout': 10,
161 -
162 - // Default edit image width
163 - 'defaultEditImageWidth' : 400
 160+ 'search_provider_timeout': 10
164161 };
165162
166163 /**
@@ -1782,9 +1779,12 @@
17831780 .attr( {
17841781 id: 'res_' + provider.id + '__' + resIndex,
17851782 title: resource.title,
1786 - src: provider.sObj.getImageTransform( resource, { 'width': this.thumb_width } )
 1783+ src: provider.sObj.getImageTransform( resource, {
 1784+ 'width': this.thumb_width
 1785+ } )
17871786 } )
1788 - .width( this.thumb_width );
 1787+ .width( this.thumb_width )
 1788+ .height( parseInt( this.thumb_width * ( resource.height / resource.width ) ) )
17891789
17901790 $resultBox.append( $resultThumb );
17911791
@@ -2014,13 +2014,13 @@
20152015 mw.log("done adding resource editor");
20162016
20172017 var mediaType = _this.getMediaType( resource );
2018 - var width = _this.getDefaultEditWidth( resource );
 2018+ var targetWidth = _this.getDefaultEditWidth( resource );
20192019
2020 - var height = parseInt( width * ( resource.height / resource.width ) );
 2020+ var targetHeight = parseInt( targetWidth * ( resource.height / resource.width ) );
20212021
2022 - if( height > $j('#clip_edit_disp').height() ){
2023 - height = $j('#clip_edit_disp').height();
2024 - width = height * ( resource.width / resource.height);
 2022+ if( targetHeight > $j('#clip_edit_disp').height() ){
 2023+ targetHeight = $j('#clip_edit_disp').height();
 2024+ targetWidth = targetHeight * ( resource.width / resource.height);
20252025 }
20262026
20272027 //mw.log("org h/w" + resource.width + ' / ' + resource.height +' new w' + width + ' new h:' + height );
@@ -2032,28 +2032,40 @@
20332033 $j( _this.target_container ).dialog( 'option', 'title', dialogTitle );
20342034
20352035 mw.log( 'did append to: ' + _this.target_container );
2036 -
2037 - if ( mediaType == 'image' ) {
2038 - _this.loadHighQualityImage(
 2036+
 2037+ // issue a loadResourceImage request if needed ( image is > than target display resolution )
 2038+ if ( mediaType == 'image' && resource.width > targetWidth ) {
 2039+ _this.loadResourceImage(
20392040 resource,
20402041 {
2041 - 'width': width,
2042 - 'height' : height
 2042+ 'width': targetWidth,
 2043+ 'height' : targetHeight
20432044 },
2044 - 'rsd_edit_img',
20452045 function( img_src ) {
2046 - $j( '.loading_spinner' ).remove();
2047 - $j( '<img />' )
 2046+ $j('#clip_edit_disp').empty().append(
 2047+ $j( '<img />' )
20482048 .attr( {
20492049 'id' : 'rsd_edit_img',
20502050 'src' : img_src,
2051 - 'width': width,
2052 - 'height' : height
 2051+ 'width': targetWidth,
 2052+ 'height' : targetHeight
20532053 } )
2054 - .appendTo( '#clip_edit_disp' );
 2054+ );
20552055 }
20562056 );
 2057+ } else if ( mediaType == 'image' ) {
 2058+ //Just use the asset url directly
 2059+ $j('#clip_edit_disp').empty().append(
 2060+ $j( '<img />' )
 2061+ .attr( {
 2062+ 'id' : 'rsd_edit_img',
 2063+ 'src' : resource.src,
 2064+ 'width' : resource.width,
 2065+ 'height' : resource.height
 2066+ } )
 2067+ )
20572068 }
 2069+
20582070 // Also fade in the container:
20592071 $j( '#rsd_resource_edit' ).animate( {
20602072 'opacity': 1,
@@ -2070,27 +2082,25 @@
20712083 },
20722084
20732085 /*
2074 - * Loads a higher quality image
 2086+ * Loads a resource image of set size
20752087 *
20762088 * @param {Object} resource requested resource for higher quality image
20772089 * @param {Object} size the requested size of the higher quality image
2078 - * @param {string} target the image id to replace with higher quality image
20792090 * @param {Function} callback the function to be calle once the image is loaded
20802091 */
2081 - loadHighQualityImage: function( resource, size, target_img_id, callback ) {
2082 - mw.log( "loadHighQualityImage" );
2083 - // Get the high quality image url:
 2092+ loadResourceImage: function( resource, size, callback ) {
 2093+ mw.log( "loadResourceImage" );
 2094+ // Get the image url:
20842095 resource.pSobj.getImageObj( resource, size, function( imObj ) {
20852096 resource['edit_url'] = imObj.url;
20862097
20872098 mw.log( "edit url: " + resource.edit_url );
2088 - // Update the resource
 2099+ // Update the resource::
20892100 resource['width'] = imObj.width;
20902101 resource['height'] = imObj.height;
20912102
20922103 var width = imObj.width;
2093 - var height = imObj.height;
2094 -
 2104+ var height = imObj.height;
20952105
20962106 // Don't swap it in until its loaded
20972107 var img = new Image();
@@ -2218,7 +2228,8 @@
22192229 }
22202230 var embedHtml = resource.pSobj.getEmbedHTML( resource,
22212231 {
2222 - 'id' : 'embed_vid'
 2232+ 'id' : 'embed_vid',
 2233+ 'apiTitleKey' : resource.title
22232234 }
22242235 );
22252236 mw.log( 'append html: ' + embedHtml );
@@ -2227,7 +2238,7 @@
22282239 mw.log( "about to call $j.embedPlayer::embed_vid" );
22292240
22302241 // Rewrite by id
2231 - $j( '#embed_vid').embedPlayer ( function() {
 2242+ $j( '#embed_vid' ).embedPlayer ( function() {
22322243 // Add extra space at the top if the embed player is less than 90px high
22332244 // bug 22189
22342245 if( $j('#embed_vid').get(0).getPlayerHeight() < 90 ) {
@@ -2301,7 +2312,7 @@
23022313 // Add a loader on top
23032314 mw.addLoaderDialog( gM( 'mwe-checking-resource' ) );
23042315
2305 - // Extend the callback, closing the loader dialog before chaining
 2316+ // Extend the callback, closing the loader dialog before calling
23062317 var myCallback = function( status ) {
23072318 mw.closeLoaderDialog();
23082319 if ( typeof callback == 'function' ) {
@@ -2309,7 +2320,7 @@
23102321 }
23112322 }
23122323
2313 - // @@todo get the localized File/Image namespace name or do a general {NS}:Title
 2324+ // NOTE: get the localized File/Image namespace name or do a general {NS}:Title
23142325 var provider = resource.pSobj.provider;
23152326 var _this = this;
23162327
@@ -2328,7 +2339,7 @@
23292340 // or if import mode if just "linking" ( we should already have the 'url' )
23302341
23312342 if ( this.isProviderLocal( provider ) || this.import_url_mode == 'remote_link' ) {
2332 - // Local repo, jump directly to the callback:
 2343+ // Local repo or in remote_link mode, jump directly to the callback:
23332344 myCallback( 'local' );
23342345 return ;
23352346 } else {
@@ -2338,6 +2349,7 @@
23392350 _this.findFileInLocalWiki( fileTitle, function( imagePage ) {
23402351 if ( imagePage && imagePage['imagerepository'] == 'shared' ||
23412352 imagePage['imagerepository'] == 'commons') {
 2353+ resource.commonsShareRepoFlag = true;
23422354 myCallback( 'shared' );
23432355 } else {
23442356 _this.isFileAlreadyImported( resource, myCallback );
Index: branches/js2-work/phase3/js/mwEmbed/modules/EmbedPlayer/mw.EmbedPlayer.js
@@ -248,26 +248,29 @@
249249 *
250250 */
251251 $.fn.embedPlayer = function( attributes, callback ) {
252 - mw.log('fn:embedPlayer on: ' + this.selector);
 252+ mw.log('embedPlayer on: ' + this.selector);
253253 var player_select = this.selector;
254254 //Handle optional include of attributes argument:
255 - if( typeof attributes == 'function' && typeof( callback ) != 'function' )
 255+ if( typeof attributes == 'function' ){
256256 callback = attributes;
 257+ }
257258
258259 // Create the Global Embed Player Manager ( if not already created )
259 - if( ! mw.playerManager )
260 - mw.playerManager = new EmbedPlayerManager();
 260+ mw.log( "create the player manager:" );
 261+ if( ! mw.playerManager ){
 262+ mw.playerManager = new EmbedPlayerManager();
 263+ }
261264
262265 //Add the embedPlayer ready callback
263266 if( typeof callback == 'function' ){
264267 mw.playerManager.addCallback( callback );
265 - }
266 -
 268+ }
 269+ mw.log("about to run jQuery select on : " + player_select);
267270 // Add each selected element to the player manager:
268271 $j( player_select ).each( function(na, playerElement) {
269272 mw.playerManager.addElement( playerElement, attributes);
270273 } );
271 -
 274+
272275 // Once we are done adding new players start to check if players are ready:
273276 mw.playerManager.waitPlayersReadyCallback();
274277 }
@@ -411,7 +414,7 @@
412415 var width = $j( element ).css( 'width' );
413416 var height = $j( element ).css( 'height' );
414417
415 - // Css video defaults:
 418+ // Css video defaults
416419 if( $j( element ).css( 'width' ) == '300px'
417420 && $j( element ).css( 'height' ) == '150px'
418421 ){
@@ -491,7 +494,8 @@
492495 */
493496 waitPlayersReadyCallback: function() {
494497 var _this = this;
495 - // mw.log('checkClipsReady');
 498+ mw.log( 'waitPlayersReadyCallback' );
 499+
496500 var is_ready = true;
497501 for ( var i = 0; i < this.playerList.length; i++ ) {
498502 var player = $j( '#' + this.playerList[i] ).get( 0 );
@@ -502,8 +506,10 @@
503507 }
504508 if ( is_ready ) {
505509 // Run queued functions
506 - while ( this.callbackFunctions.length ) {
507 - this.callbackFunctions.shift()();
 510+ if( this.callbackFunctions ) {
 511+ while ( this.callbackFunctions.length ) {
 512+ this.callbackFunctions.shift()();
 513+ }
508514 }
509515 } else {
510516 // Continue checking the playerList
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -620,9 +620,9 @@
621621 function doProcessJs( $str ){
622622 global $wgEnableScriptLocalization;
623623
624 - // Strip out js_log debug lines (if not in debug mode)
 624+ // Strip out mw.log debug lines (if not in debug mode)
625625 if( !$this->debug ){
626 - $str = preg_replace('/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $str);
 626+ //$str = preg_replace('/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $str);
627627 }
628628
629629 // Do language swap by index:
@@ -630,7 +630,7 @@
631631 $inx = self::getAddMessagesIndex( $str );
632632 if($inx){
633633 $translated = $this->languageMsgReplace( substr($str, $inx['s'], ($inx['e']-$inx['s']) ));
634 - //return the final string (without double {})
 634+ // Return the final string (without double {})
635635 return substr($str, 0, $inx['s']-1) . $translated . substr($str, $inx['e']+1);
636636 }
637637 }
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -4,7 +4,7 @@
55 */
66 var urlparts = getRemoteEmbedPath();
77 var mwEmbedHostPath = urlparts[0];
8 -var mwRemoteVersion = 'r109';
 8+var mwRemoteVersion = 'r110';
99
1010 // Log the mwRemote version ( will determine what version of js we get )
1111 if( window.console ){

Status & tagging log