r86874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86873‎ | r86874 | r86875 >
Date:17:54, 25 April 2011
Author:neilk
Status:ok
Tags:
Comment:
duplicate-archive (deleted duplicates) handling
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.Api.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -128,6 +128,9 @@
129129 'mwe-upwiz-api-error-fetchfileerror',
130130 'mwe-upwiz-api-error-duplicate',
131131 'mwe-upwiz-api-error-duplicate-popup-title',
 132+ 'mwe-upwiz-api-error-duplicate-archive',
 133+ 'mwe-upwiz-api-error-duplicate-archive-popup-title',
 134+ 'mwe-upwiz-api-error-unknown-warning',
132135 'mwe-upwiz-api-error-timeout',
133136 'mwe-upwiz-api-error-noimageinfo',
134137
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -59,6 +59,9 @@
6060 'mwe-upwiz-api-error-fetchfileerror' => 'Internal error: something went wrong while fetching the file.',
6161 'mwe-upwiz-api-error-duplicate' => 'There {{PLURAL:$1|is [$2 another file]|are [$2 some other files]}} already on the site with the same content',
6262 'mwe-upwiz-api-error-duplicate-popup-title' => 'Duplicate {{PLURAL:$1|file|files}}',
 63+ 'mwe-upwiz-api-error-duplicate-archive' => 'There {{PLURAL:$1|was [$2 another file]|were [$2 some other files]}} already on the site with the same content, but {{PLURAL:$1|it was|they were}} deleted.',
 64+ 'mwe-upwiz-api-error-duplicate-archive-popup-title' => 'Duplicate {{PLURAL:$1|file|files}} already deleted',
 65+ 'mwe-upwiz-api-error-unknown-warning' => 'Unknown warning: $1',
6366 'mwe-upwiz-api-error-timeout' => 'The server did not respond within the expected time.',
6467 'mwe-upwiz-api-error-noimageinfo' => 'The upload succeeded, but the server did not give us any information about the file.',
6568 'mwe-upwiz-api-error-fileexists-shared-forbidden' => 'This filename is reserved by a file on a remote shared repository. Choose another name.',
Index: trunk/extensions/UploadWizard/resources/mw.Api.js
@@ -161,6 +161,7 @@
162162
163163 /* really a warning, but we treat it like an error */
164164 'duplicate',
 165+ 'duplicate-archive',
165166
166167 /* upload succeeded, but no image info.
167168 this is probably impossible, but might as well check for it */
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -115,7 +115,7 @@
116116 var info = 'unknown';
117117
118118 if ( result.upload && result.upload.warnings ) {
119 - if ( result.upload.warnings.exists ) {
 119+ if ( result.upload.warnings['exists'] ) {
120120 // the filename we uploaded is in use already. Not a problem since we stashed it under a temporary name anyway
121121 // potentially we could indicate to the upload that it should set the Title field to error state now, but we'll let them deal with that later.
122122 // however, we don't get imageinfo, so let's try to get it and pretend that we did
@@ -138,43 +138,27 @@
139139 }
140140 };
141141 _this.getStashImageInfo( success, [ 'timestamp', 'url', 'size', 'dimensions', 'sha1', 'mime', 'metadata', 'bitdepth' ] );
142 - } else if ( result.upload.warnings.duplicate ) {
143 - if ( typeof result.upload.warnings.duplicate == 'object' ) {
144 - var duplicates = result.upload.warnings.duplicate;
145 - var $ul = $j( '<ul></ul>' );
146 - $j.each( duplicates, function( i, filename ) {
147 - var $a = $j( '<a/>' ).append( filename );
148 - var href;
149 - try {
150 - href = _this.filenameToUrl( filename );
151 - $a.attr( { 'href': href, 'target': '_blank' } );
152 - } catch ( e ) {
153 - $a.click( function() { alert('could not parse filename=' + filename ); } );
154 - $a.attr( 'href', '#' );
155 - }
156 - $ul.append( $j( '<li></li>' ).append( $a ) );
157 - } );
158 - var dialogFn = function() {
159 - $j( '<div></div>' )
160 - .html( $ul )
161 - .dialog( {
162 - width: 500,
163 - zIndex: 200000,
164 - autoOpen: true,
165 - title: gM( 'mwe-upwiz-api-error-duplicate-popup-title', duplicates.length ),
166 - modal: true
167 - } );
168 - };
169 - code = 'duplicate';
170 - info = [ duplicates.length, dialogFn ];
171 - }
172 - _this.setError( code, info );
 142+ } else if ( result.upload.warnings['duplicate'] ) {
 143+ code = 'duplicate';
 144+ _this.setError( code, _this.duplicateErrorInfo( 'duplicate', result.upload.warnings['duplicate'] ) );
 145+ } else if ( result.upload.warnings['duplicate-archive'] ) {
 146+ code = 'duplicate-archive';
 147+ _this.setError( code, _this.duplicateErrorInfo( 'duplicate-archive', result.upload.warnings['duplicate-archive'] ) );
 148+ } else {
 149+ // we have an unknown warning. Assume fatal
 150+ code = 'unknown-warning';
 151+ var warningInfo = [];
 152+ $j.each( result.upload.warnings, function( k, v ) {
 153+ warningInfo.push( k + ': ' + v );
 154+ } );
 155+ info = warningInfo.join( ', ' );
 156+ _this.setError( code, [ info ] );
173157 }
174158 } else if ( result.upload && result.upload.result === 'Success' ) {
175159 if ( result.upload.imageinfo ) {
176160 _this.setSuccess( result );
177161 } else {
178 - _this.setError( 'noimageinfo' );
 162+ _this.setError( 'noimageinfo', info );
179163 }
180164 } else {
181165 if ( result.error ) {
@@ -193,6 +177,46 @@
194178
195179
196180 /**
 181+ * Helper function to generate duplicate errors with dialog box. Works with existing duplicates and deleted dupes.
 182+ * @param {String} error code, should have matching strings in .i18n.php
 183+ * @param {Object} portion of the API error result listing duplicates
 184+ */
 185+ duplicateErrorInfo: function( code, resultDuplicate ) {
 186+ var _this = this;
 187+ var duplicates;
 188+ if ( typeof resultDuplicate === 'object' ) {
 189+ duplicates = resultDuplicate;
 190+ } else if ( typeof resultDuplicate === 'string' ) {
 191+ duplicates = [ resultDuplicate ];
 192+ }
 193+ var $ul = $j( '<ul></ul>' );
 194+ $j.each( duplicates, function( i, filename ) {
 195+ var $a = $j( '<a/>' ).append( filename );
 196+ try {
 197+ var href = _this.filenameToUrl( filename );
 198+ $a.attr( { 'href': href, 'target': '_blank' } );
 199+ } catch ( e ) {
 200+ $a.click( function() { alert('could not parse filename=' + filename ); } );
 201+ $a.attr( 'href', '#' );
 202+ }
 203+ $ul.append( $j( '<li></li>' ).append( $a ) );
 204+ } );
 205+ var dialogFn = function() {
 206+ $j( '<div></div>' )
 207+ .html( $ul )
 208+ .dialog( {
 209+ width: 500,
 210+ zIndex: 200000,
 211+ autoOpen: true,
 212+ title: gM( 'mwe-upwiz-api-error-' + code + '-popup-title', duplicates.length ),
 213+ modal: true
 214+ } );
 215+ };
 216+ return [ duplicates.length, dialogFn ];
 217+ },
 218+
 219+
 220+ /**
197221 * Called from any upload success condition
198222 * @param {Mixed} result -- result of AJAX call
199223 */

Status & tagging log