Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -128,6 +128,9 @@ |
129 | 129 | 'mwe-upwiz-api-error-fetchfileerror', |
130 | 130 | 'mwe-upwiz-api-error-duplicate', |
131 | 131 | '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', |
132 | 135 | 'mwe-upwiz-api-error-timeout', |
133 | 136 | 'mwe-upwiz-api-error-noimageinfo', |
134 | 137 | |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -59,6 +59,9 @@ |
60 | 60 | 'mwe-upwiz-api-error-fetchfileerror' => 'Internal error: something went wrong while fetching the file.', |
61 | 61 | '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', |
62 | 62 | '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', |
63 | 66 | 'mwe-upwiz-api-error-timeout' => 'The server did not respond within the expected time.', |
64 | 67 | 'mwe-upwiz-api-error-noimageinfo' => 'The upload succeeded, but the server did not give us any information about the file.', |
65 | 68 | '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 @@ |
162 | 162 | |
163 | 163 | /* really a warning, but we treat it like an error */ |
164 | 164 | 'duplicate', |
| 165 | + 'duplicate-archive', |
165 | 166 | |
166 | 167 | /* upload succeeded, but no image info. |
167 | 168 | this is probably impossible, but might as well check for it */ |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -115,7 +115,7 @@ |
116 | 116 | var info = 'unknown'; |
117 | 117 | |
118 | 118 | if ( result.upload && result.upload.warnings ) { |
119 | | - if ( result.upload.warnings.exists ) { |
| 119 | + if ( result.upload.warnings['exists'] ) { |
120 | 120 | // the filename we uploaded is in use already. Not a problem since we stashed it under a temporary name anyway |
121 | 121 | // 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. |
122 | 122 | // however, we don't get imageinfo, so let's try to get it and pretend that we did |
— | — | @@ -138,43 +138,27 @@ |
139 | 139 | } |
140 | 140 | }; |
141 | 141 | _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 ] ); |
173 | 157 | } |
174 | 158 | } else if ( result.upload && result.upload.result === 'Success' ) { |
175 | 159 | if ( result.upload.imageinfo ) { |
176 | 160 | _this.setSuccess( result ); |
177 | 161 | } else { |
178 | | - _this.setError( 'noimageinfo' ); |
| 162 | + _this.setError( 'noimageinfo', info ); |
179 | 163 | } |
180 | 164 | } else { |
181 | 165 | if ( result.error ) { |
— | — | @@ -193,6 +177,46 @@ |
194 | 178 | |
195 | 179 | |
196 | 180 | /** |
| 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 | + /** |
197 | 221 | * Called from any upload success condition |
198 | 222 | * @param {Mixed} result -- result of AJAX call |
199 | 223 | */ |