r93771 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93770‎ | r93771 | r93772 >
Date:18:08, 2 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
make a call to the image push api module for each image, to prevent timeouts when there are many images and aliased mediaWiki to mw
Modified paths:
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -5,7 +5,7 @@
66 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
77 */
88
9 -(function($) { $( document ).ready( function() {
 9+(function( $ ) { $( document ).ready( function() {
1010
1111 // Compatibility with pre-RL code.
1212 // Messages will have been loaded into wgPushMessages.
@@ -23,6 +23,8 @@
2424 }
2525 }
2626
 27+ mw = mediaWiki;
 28+
2729 var pages;
2830 var targetData = [];
2931
@@ -32,7 +34,7 @@
3335
3436 $('.push-button').click(function() {
3537 this.disabled = true;
36 - this.innerHTML = mediaWiki.msg( 'push-button-pushing' );
 38+ this.innerHTML = mw.msg( 'push-button-pushing' );
3739
3840 var errorDiv = $( '#targeterrors' + $(this).attr( 'targetid' ) );
3941 errorDiv.fadeOut( 'fast' );
@@ -55,7 +57,7 @@
5658
5759 $('#push-all-button').click(function() {
5860 this.disabled = true;
59 - this.innerHTML = mediaWiki.msg( 'push-button-pushing' );
 61+ this.innerHTML = mw.msg( 'push-button-pushing' );
6062 $.each($(".push-button"), function(i,v) {
6163 $(v).click();
6264 });
@@ -116,7 +118,7 @@
117119 }
118120
119121 if ( files.length > 0 ) {
120 - $('#txtFileList').text( '(' + mediaWiki.msg( 'push-tab-embedded-files' ) + ' ' );
 122+ $('#txtFileList').text( '(' + mw.msg( 'push-tab-embedded-files' ) + ' ' );
121123
122124 for ( i in files ) {
123125 if ( i > 0 ) $('#txtFileList').append( ', ' );
@@ -126,7 +128,7 @@
127129 $('#txtFileList').append( ')' );
128130 }
129131 else {
130 - $('#txtFileList').text( mediaWiki.msg( 'push-tab-no-embedded-files' ) );
 132+ $('#txtFileList').text( mw.msg( 'push-tab-no-embedded-files' ) );
131133 }
132134 }
133135 }
@@ -173,7 +175,7 @@
174176 var revision = remotePage.revisions[0];
175177 var dateTime = revision.timestamp.split( 'T' );
176178
177 - var message = mediaWiki.msg(
 179+ var message = mw.msg(
178180 'push-tab-last-edit',
179181 revision.user,
180182 dateTime[0],
@@ -182,7 +184,7 @@
183185 }
184186 else {
185187 $( '#targetlink' + targetId ).attr( {'class': 'new'} );
186 - var message = mediaWiki.msg( 'push-tab-not-created' );
 188+ var message = mw.msg( 'push-tab-not-created' );
187189 }
188190
189191 infoDiv.text( message );
@@ -218,7 +220,7 @@
219221
220222 if ( overideTemplates.length > 0 ) {
221223 $( '#targettemplateconflicts' + targetId )
222 - .text( mediaWiki.msg( 'push-tab-template-override', overideTemplates.join( ', ' ) ) )
 224+ .text( mw.msg( 'push-tab-template-override', overideTemplates.join( ', ' ) ) )
223225 .fadeIn( 'slow' );
224226 }
225227 else {
@@ -241,7 +243,7 @@
242244
243245 if ( overideFiles.length > 0 ) {
244246 $( '#targetfileconflicts' + targetId )
245 - .text( mediaWiki.msg( 'push-tab-files-override', overideFiles.join( ', ' ) ) )
 247+ .text( mw.msg( 'push-tab-files-override', overideFiles.join( ', ' ) ) )
246248 .fadeIn( 'slow' );
247249 }
248250 else {
@@ -267,14 +269,14 @@
268270 handleError( sender, targetUrl, data.error );
269271 }
270272 else if ( data.length > 0 && data[0].edit && data[0].edit.captcha ) {
271 - handleError( sender, targetUrl, { info: mediaWiki.msg( 'push-err-captacha', targetName ) } );
 273+ handleError( sender, targetUrl, { info: mw.msg( 'push-err-captacha', targetName ) } );
272274 }
273275 else {
274276 if ( $('#checkIncFiles').length != 0 && $('#checkIncFiles').attr('checked') ) {
275277 setButtonToImgPush( sender, targetUrl, targetName );
276278 }
277279 else {
278 - sender.innerHTML = mediaWiki.msg( 'push-button-completed' );
 280+ sender.innerHTML = mw.msg( 'push-button-completed' );
279281 setTimeout( function() {reEnableButton( sender, targetUrl, targetName );}, 1000 );
280282 }
281283 }
@@ -282,40 +284,50 @@
283285 );
284286 }
285287
286 - function setButtonToImgPush( button, targetUrl, targetName ) {
287 - button.innerHTML = mediaWiki.msg( 'push-button-pushing-files' );
288 - initiateImagePush( button, targetUrl, targetName );
 288+ function handleFilePushingCompletion( sender, targetUrl, targetName ) {
 289+ sender.innerHTML = mw.msg( 'push-button-completed' );
 290+
 291+ setTimeout( function() {
 292+ reEnableButton( sender, targetUrl, targetName );
 293+ }, 1000 );
289294 }
290295
291 - function initiateImagePush( sender, targetUrl, targetName ) {
 296+ function setButtonToImgPush( button, targetUrl, targetName ) {
 297+ button.innerHTML = mw.msg( 'push-button-pushing-files' );
 298+
292299 var images = window.wgPushPageFiles.concat( window.wgPushTemplateFiles );
 300+ var currentFile = images.pop();
293301
 302+ initiateImagePush( button, targetUrl, targetName, images, currentFile, handleFilePushingCompletion );
 303+ }
 304+
 305+ function initiateImagePush( sender, targetUrl, targetName, images, fileName, callback ) {
294306 $.getJSON(
295307 wgScriptPath + '/api.php',
296308 {
297309 'action': 'pushimages',
298310 'format': 'json',
299 - 'images': images.join( '|' ),
 311+ 'images': fileName,
300312 'targets': targetUrl
301313 },
302314 function( data ) {
303315 var fail = false;
304316
305317 if ( data.error ) {
306 - data.error.info = mediaWiki.msg( 'push-tab-err-filepush', data.error.info );
 318+ data.error.info = mw.msg( 'push-tab-err-filepush', data.error.info );
307319 handleError( sender, targetUrl, data.error );
308320 fail = true;
309321 }
310322 else {
311323 for ( i in data ) {
312324 if ( data[i].error ) {
313 - data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush', data[i].error.info );
 325+ data[i].error.info = mw.msg( 'push-tab-err-filepush', data[i].error.info );
314326 handleError( sender, targetUrl, data[i].error );
315327 fail = true;
316328 break;
317329 }
318330 else if ( !data[i].upload ) {
319 - data[i].error.info = mediaWiki.msg( 'push-tab-err-filepush-unknown' );
 331+ data[i].error.info = mw.msg( 'push-tab-err-filepush-unknown' );
320332 handleError( sender, targetUrl, data[i].error );
321333 fail = true;
322334 break;
@@ -324,15 +336,20 @@
325337 }
326338
327339 if ( !fail ) {
328 - sender.innerHTML = mediaWiki.msg( 'push-button-completed' );
329 - setTimeout( function() {reEnableButton( sender, targetUrl, targetName );}, 1000 );
 340+ if ( images.length > 0 ) {
 341+ var currentFile = images.pop();
 342+ initiateImagePush( sender, targetUrl, targetName, images, currentFile, callback );
 343+ }
 344+ else {
 345+ callback( sender, targetUrl, targetName );
 346+ }
330347 }
331348 }
332349 );
333350 }
334351
335352 function reEnableButton( button, targetUrl, targetName ) {
336 - button.innerHTML = mediaWiki.msg( 'push-button-text' );
 353+ button.innerHTML = mw.msg( 'push-button-text' );
337354 button.disabled = false;
338355
339356 getRemoteArticleInfo( $(button).attr( 'targetid' ), $(button).attr( 'pushtarget' ) );
@@ -352,7 +369,7 @@
353370
354371 if ( !hasDisabled ) {
355372 pushAllButton.attr( "disabled", false );
356 - pushAllButton.text( mediaWiki.msg( 'push-button-all' ) );
 373+ pushAllButton.text( mw.msg( 'push-button-all' ) );
357374 }
358375 }
359376 }
@@ -361,14 +378,14 @@
362379 var errorDiv = $( '#targeterrors' + $(sender).attr( 'targetid' ) );
363380
364381 if ( error.code && error.code == 'uploaddisabled' ) {
365 - error.info = mediaWiki.msg( 'push-tab-err-uploaddisabled' );
 382+ error.info = mw.msg( 'push-tab-err-uploaddisabled' );
366383 }
367384
368385 errorDiv.text( error.info );
369386 errorDiv.fadeIn( 'slow' );
370387
371 - sender.innerHTML = mediaWiki.msg( 'push-button-failed' );
 388+ sender.innerHTML = mw.msg( 'push-button-failed' );
372389 setTimeout( function() {reEnableButton( sender );}, 2500 );
373390 }
374391
375 -} ); })(jQuery);
 392+} ); })( jQuery );

Follow-up revisions

RevisionCommit summaryAuthorDate
r93772fu r93771; up rel notesjeroendedauw18:10, 2 August 2011

Status & tagging log