r87747 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87746‎ | r87747 | r87748 >
Date:17:42, 9 May 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
error recovery on filename errors
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/uploadWizard.css (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -136,9 +136,9 @@
137137 'mwe-upwiz-api-error-unknown-warning',
138138 'mwe-upwiz-api-error-timeout',
139139 'mwe-upwiz-api-error-noimageinfo',
140 -
141140 'mwe-upwiz-api-error-fileexists-shared-forbidden',
142 -
 141+ 'mwe-upwiz-api-error-unclassified',
 142+ 'mwe-upwiz-api-warning-was-deleted',
143143 'mwe-upwiz-api-warning-exists',
144144 'mwe-upwiz-tutorial-error-localized-file-missing',
145145 'mwe-upwiz-tutorial-error-file-missing',
@@ -262,6 +262,8 @@
263263 'mwe-upwiz-error-title-senselessimagename',
264264 'mwe-upwiz-error-title-hosting',
265265 'mwe-upwiz-error-title-thumbnail',
 266+ 'mwe-upwiz-error-title-fileexists-shared-forbidden',
 267+ 'mwe-upwiz-error-title-double-apostrophe',
266268 'mwe-upwiz-license-cc-by-sa-3.0',
267269 'mwe-upwiz-license-cc-by-3.0',
268270 'mwe-upwiz-license-cc-zero',
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -23,6 +23,7 @@
2424 'mwe-upwiz-step-thanks' => 'Use',
2525 'mwe-upwiz-api-error-http' => 'Internal error: unable to connect to server.',
2626 'mwe-upwiz-api-error-ok-but-empty' => 'Internal error: no response from server.',
 27+ 'mwe-upwiz-api-error-unclassified' => 'An unknown error occurred',
2728 'mwe-upwiz-api-error-unknown-code' => 'Unknown error: "$1"',
2829 'mwe-upwiz-api-error-uploaddisabled' => 'Uploading is disabled on this wiki.',
2930 'mwe-upwiz-api-error-nomodule' => 'Internal error: no upload module set.',
@@ -54,10 +55,10 @@
5556 'mwe-upwiz-api-error-unknown-warning' => 'Unknown warning: $1',
5657 'mwe-upwiz-api-error-timeout' => 'The server did not respond within the expected time.',
5758 'mwe-upwiz-api-error-noimageinfo' => 'The upload succeeded, but the server did not give us any information about the file.',
58 - 'mwe-upwiz-api-error-fileexists-shared-forbidden' => 'This filename is reserved by a file on a remote shared repository. Choose another name.',
5959
6060
6161 'mwe-upwiz-api-warning-exists' => 'There is [$1 another file] already on the wiki with the same filename',
 62+ 'mwe-upwiz-api-warning-was-deleted' => 'There was a file by this name, "$1", but it was deleted and you can not reupload the file. If your file is different, try renaming it.',
6263 'mwe-upwiz-tutorial-error-localized-file-missing' => 'Sorry, we could not find a tutorial in your language. The English one is shown instead.',
6364 'mwe-upwiz-tutorial-error-file-missing' => 'Sorry, we could not find any files for the tutorial that is supposed to go here. Please contact the system administrators.',
6465 'mwe-upwiz-tutorial-error-cannot-transform' => 'Sorry, we could not get a scaled image of the tutorial to fit this screen. This may be a temporary problem with Wikimedia Commons; try again later.',
@@ -182,6 +183,8 @@
183184 'mwe-upwiz-error-title-senselessimagename' => 'Please make this title more meaningful.',
184185 'mwe-upwiz-error-title-hosting' => 'This looks like a file you obtained from another imagehost. Please make the title more meaningful. Also, double check that you have the rights to publish it on {{SITENAME}}.',
185186 'mwe-upwiz-error-title-thumbnail' => 'This looks like a thumbnail title. Please do not upload thumbnails back to the same wiki. Otherwise, please fix the filename so it is more meaningful, and does not have the thumbnail prefix.',
 187+ 'mwe-upwiz-error-title-fileexists-shared-forbidden' => 'This title is reserved by a file on a remote shared repository. Choose another name.',
 188+ 'mwe-upwiz-error-title-double-apostrophe' => 'This title contains a double apostrophe; please remove it.',
186189
187190 /* LICENSES & combinations of licenses */
188191 /* may be a good idea to shift to WikimediaLicenseTexts? */
Index: trunk/extensions/UploadWizard/resources/uploadWizard.css
@@ -597,12 +597,12 @@
598598 cursor: pointer;
599599 }
600600
601 -.mwe-error, .mwe-validator-error, .errorTitleUnique {
 601+.mwe-error, .mwe-validator-error {
602602 color: #ff0000;
603603 }
604604
605605 .mwe-upwiz-deed-thirdparty .mwe-upwiz-deed-form-internal label.mwe-error,
606 -.mwe-upwiz-deed-thirdparty .mwe-upwiz-deed-form-internal label.mwe-validator-error, label.errorTitleUnique {
 606+.mwe-upwiz-deed-thirdparty .mwe-upwiz-deed-form-internal label.mwe-validator-error {
607607 margin-left: 0;
608608 }
609609
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -62,8 +62,9 @@
6363 } );
6464
6565 _this.titleErrorDiv = $j('<div class="mwe-upwiz-details-input-error">'
66 - + '<label class="mwe-validator-error" for="' + _this.titleId + '" generated="true"/>'
67 - + '<label class="errorTitleUnique" for="' + _this.titleId + '" generated="true"/>'
 66+ + '<label class="mwe-error mwe-validator-error" for="' + _this.titleId + '" generated="true"/>'
 67+ + '<label class="mwe-error errorTitleUnique" for="' + _this.titleId + '" generated="true"/>'
 68+ + '<label class="mwe-error errorRecovery" for="' + _this.titleId + '" generated="true"/>'
6869 + '</div>');
6970
7071 var titleHintId = 'mwe-upwiz-title-hint-' + _this.upload.index;
@@ -162,7 +163,7 @@
163164
164165
165166 /* Build the form for the file upload */
166 - _this.$form = $j( '<form></form>' );
 167+ _this.$form = $j( '<form></form>' ).addClass( 'detailsForm' );
167168 _this.$form.append(
168169 titleContainerDiv,
169170 _this.descriptionsDiv,
@@ -702,8 +703,9 @@
703704
704705 var err = function( code, info ) {
705706 _this.upload.state = 'error';
706 - _this.showError( code, info );
 707+ _this.processError( code, info );
707708 };
 709+
708710
709711 var ok = function( result ) {
710712 if ( result && result.upload && result.upload.imageinfo ) {
@@ -712,6 +714,22 @@
713715 _this.upload.state = 'complete';
714716 _this.showIndicator( 'uploaded' );
715717 _this.setStatus( gM( 'mwe-upwiz-published' ) );
 718+ } else if ( result && result.upload.warnings ) {
 719+ var warnings = result.upload.warnings;
 720+ if ( warnings['was-deleted'] ) {
 721+ _this.recoverFromError( _this.titleId, gM( 'mwe-upwiz-api-warning-was-deleted' ) );
 722+ } else if ( warnings['thumb'] ) {
 723+ _this.recoverFromError( _this.titleId, gM( 'mwe-upwiz-error-title-thumbnail' ) );
 724+ } else if ( warnings['bad-prefix'] ) {
 725+ _this.recoverFromError( _this.titleId, gM( 'mwe-upwiz-error-title-senselessimagename' ) );
 726+ } else {
 727+ var warningsKeys = [];
 728+ $j.each( warnings, function( key, val ) {
 729+ warningsKeys.push( key );
 730+ } );
 731+ _this.upload.state = 'error';
 732+ _this.showError( 'unknown', gM( 'mwe-upwiz-api-error-unknown-warning', warningsKeys.join( ', ' ) ) );
 733+ }
716734 } else {
717735 err( 'details-info-missing', result );
718736 }
@@ -720,15 +738,59 @@
721739 _this.upload.api.postWithEditToken( params, ok, err );
722740 },
723741
724 - showError: function( code, result ) {
 742+
 743+ /**
 744+ * Create a recoverable error -- show the form again, and highlight the problematic field. Go to error state but do not block submission
 745+ * @param {String} name of field
 746+ * @param {String} error message to show
 747+ */
 748+ recoverFromError: function( fieldname, errorMessage ) {
 749+ this.upload.state = 'error';
 750+ this.dataDiv.morphCrossfade( '.detailsForm' );
 751+ this.$form.find( '[name=' + fieldname + ']' ).addClass( 'mwe-error' );
 752+ this.$form.find( 'label[for=' + fieldname + '].errorRecovery' ).html( errorMessage ).show();
 753+ },
 754+
 755+ /**
 756+ * Show error state, possibly using a recoverable error form
 757+ * @param {String} error code
 758+ * @param {String} status line
 759+ */
 760+ showError: function( code, statusLine ) {
725761 this.showIndicator( 'error' );
726 - // types of errors we know about...
727 - // recoverable by fixing title
728 - // TODO unmask and fix the error on the title
 762+ this.setStatus( statusLine );
 763+ },
729764
730 - // recoverable by trying again, or removing
731 - // TODO removal / retry interface
732 - this.setStatus( result.error.info );
 765+
 766+ /**
 767+ * Decide how to treat various errors
 768+ * @param {String} error code
 769+ * @param {Mixed} result from ajax call
 770+ */
 771+ processError: function( code, result ) {
 772+ var statusLine = gM( 'mwe-upwiz-unclassified' );
 773+ var titleErrorMap = {
 774+ 'senselessimagename': 'senselessimagename',
 775+ 'fileexists-shared-forbidden': 'fileexists-shared-forbidden',
 776+ 'titleblacklist-custom-filename': 'hosting',
 777+ 'titleblacklist-custom-SVG-thumbnail': 'thumbnail',
 778+ 'titleblacklist-custom-thumbnail': 'thumbnail',
 779+ 'titleblacklist-custom-double-apostrophe': 'double-apostrophe'
 780+ };
 781+ if ( result && result.error && result.error.code ) {
 782+ if ( titleErrorMap[code] ) {
 783+ _this.recoverFromError( _this.titleId, gM( 'mwe-upwiz-error-title-' + titleErrorMap[code] ) );
 784+ return;
 785+ } else {
 786+ statusKey = 'mwe-upwiz-api-error-' + code;
 787+ if ( result.error.info ) {
 788+ statusLine = gM( statusKey, result.error.info );
 789+ } else {
 790+ statusLine = gM( statusKey, '[no error info]' );
 791+ }
 792+ }
 793+ }
 794+ this.showError( code, statusLine );
733795 },
734796
735797 setStatus: function( s ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r87760followup to r87747 - look for labels for id, not nameneilk19:23, 9 May 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   18:17, 9 May 2011

recoverFromError seems to be finding matching fields & labels by finding a match on the 'name' attribute and the label's 'for' attribute; however a label's 'for' is matched up with the target element's 'id' not 'name'. Should be harmless as they match in these cases, but id is safer to use for matching.

#Comment by NeilK (talk | contribs)   19:23, 9 May 2011

fixed in r87760

#Comment by Brion VIBBER (talk | contribs)   20:36, 9 May 2011

There seems to still be _something_ awry with some cases of multiple submission (User:Brion VIBBER/Upwiz mystery 1), but per IRC it's still better than the previous case where there was no recovery. Marking OK.

Status & tagging log