Bartosz Dziewoński has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/329361 )
Change subject: Fixups for API error reporting refactoring
......................................................................
Fixups for API error reporting refactoring
Follow-up to I9c0ef778, I78f4afb7, I1e8d8dee. This is easier than amending.
* Restore support for 'parsererror' failures (they occur when there
are stupid proxies on the way or PHP fatals happen in API code).
* Always pass the new standard API to UploadWizardLicenseInput
(from mw.UploadWizard and uw.DeedChooserDetailsWidget) to fix error
handling. Update mw.UploadWizardLicenseInput for 'formatversion: 2'.
* Remove silly uses of window.console.
* Restore support for mw.Message objects in uw.FieldLayout, we're still
relying on this in a lot of places. Also, don't double-escape HTML.
* Fix error handling for chunked uploads in mw.FormDataTransport.
(Also, remove some dead code copying this.formData twice.)
* Remove a few newly unused messages.
Change-Id: Ia48fd7842205dfba16948349b9c6acf0e9fa939c
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M resources/details/uw.DeedChooserDetailsWidget.js
M resources/mw.UploadWizard.js
M resources/mw.UploadWizardDetails.js
M resources/mw.UploadWizardLicenseInput.js
M resources/transports/mw.FormDataTransport.js
M resources/uw.FieldLayout.js
9 files changed, 37 insertions(+), 39 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/61/329361/1
diff --git a/extension.json b/extension.json
index 74d15ea..e59c411 100644
--- a/extension.json
+++ b/extension.json
@@ -261,6 +261,7 @@
"api-error-firefogg",
"api-error-noimageinfo",
"api-error-offline",
+ "api-error-parsererror",
"api-error-timeout",
"api-error-unknown-warning",
"unknown-error",
@@ -422,11 +423,8 @@
"mwe-upwiz-error-bad-descriptions",
"mwe-upwiz-error-title-blacklisted",
"mwe-upwiz-error-title-senselessimagename",
- "mwe-upwiz-error-title-hosting",
"mwe-upwiz-error-title-invalid",
"mwe-upwiz-error-title-thumbnail",
-
"mwe-upwiz-error-title-fileexists-shared-forbidden",
- "mwe-upwiz-error-title-double-apostrophe",
"mwe-upwiz-error-title-extension",
"mwe-upwiz-error-title-protected",
"mwe-upwiz-error-title-duplicate",
diff --git a/i18n/en.json b/i18n/en.json
index 5b58105..e21cd55 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -13,6 +13,7 @@
"accesskey-cancel-upload-campaign": "c",
"group-upwizcampeditors.css": "/* CSS placed here will affect upload
wizard campaign editors only */",
"group-upwizcampeditors.js": "/* JS placed here will affect upload
wizard campaign editors only */",
+ "api-error-parsererror": "The server responded with an invalid JSON
document. This could be a problem with the API, or you could be using a proxy
server that prevents you from uploading files.",
"api-error-aborted": "Upload aborted.",
"api-error-duplicate": "There {{PLURAL:$1|is another file|are some
other files}} already on the site with the same content.",
"api-error-duplicate-archive": "There {{PLURAL:$1|was another file|were
some other files}} already on the site with the same content, but
{{PLURAL:$1|it was|they were}} deleted.",
@@ -216,10 +217,7 @@
"mwe-upwiz-error-bad-descriptions": "There are problems with some of
the descriptions.",
"mwe-upwiz-error-title-blacklisted": "This title contains some
undesirable text. Please revise it.",
"mwe-upwiz-error-title-senselessimagename": "Please make this title
more meaningful.",
- "mwe-upwiz-error-title-hosting": "This looks like a file you obtained
from another image host. Please make the title more meaningful. Also, double
check that you have the rights to publish it on this site.",
"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.",
- "mwe-upwiz-error-title-fileexists-shared-forbidden": "This title is
reserved by a file on a remote shared repository. Choose another name.",
- "mwe-upwiz-error-title-double-apostrophe": "This title contains a
double apostrophe; please remove it.",
"mwe-upwiz-error-title-extension": "You do not need to add a file
extension. Just make a human readable title and the application will take care
of the rest.",
"mwe-upwiz-error-title-protected": "This title corresponds to a
protected page on this wiki. Please choose a different one.",
"mwe-upwiz-error-title-duplicate": "This title has been specified for
more than one file you're going to upload. Underscores are treated as spaces, a
file extension is added automatically.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 06ba7f3..f6f32de 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -39,6 +39,7 @@
"accesskey-cancel-upload-campaign": "{{doc-accesskey}}",
"group-upwizcampeditors.css": "{{doc-group|upwizcampeditors|css}}",
"group-upwizcampeditors.js": "{{doc-group|upwizcampeditors|js}}",
+ "api-error-parsererror": "Error message for when, for an unknown
reason, the server sent the client an invalid response.",
"api-error-aborted": "Error message for when an upload was aborted.",
"api-error-duplicate": "API error message that can be used for client
side localisation of API errors. Parameters:\n* $1 - a number of files",
"api-error-duplicate-archive": "API error message that can be used for
client side localisation of API errors. Parameters:\n* $1 - a number of files",
@@ -242,10 +243,7 @@
"mwe-upwiz-error-bad-descriptions": "Used as error message.",
"mwe-upwiz-error-title-blacklisted": "Error message shown to the user
when they have entered a file name that matches the 'blacklist' of banned
words.",
"mwe-upwiz-error-title-senselessimagename": "Error message shown to the
user when they have entered a file name that looks like an automatic name
rather than a useful one.",
- "mwe-upwiz-error-title-hosting": "Appears when the upload title is
similar to another site's default format for downloads - like Flickr.",
"mwe-upwiz-error-title-thumbnail": "Appears when thumbnail title is
similar to \"22px-Example.jpg\" - the prefix is what MW adds when downloading
pictures as thumbnails.",
- "mwe-upwiz-error-title-fileexists-shared-forbidden": "Appears when the
proposed title is used by a file on a remote repository, like Commons.",
- "mwe-upwiz-error-title-double-apostrophe": "Error message shown to the
user when they have entered a file name that has '' in it, which isn't
allowed.",
"mwe-upwiz-error-title-extension": "Reminder message shown to the user
that they do not have to put the file extension in the file name.",
"mwe-upwiz-error-title-protected": "Appears when the filename chosen
will put this file in a protected page. Obviously the user cannot replace it
(or we would not get this error), so we ask them to rename.",
"mwe-upwiz-error-title-duplicate": "Appears when the title chosen is
not unique amongst the files being uploaded. In other words, the user specified
the same title (in normalized form) for at least two files they're uploading.",
diff --git a/resources/details/uw.DeedChooserDetailsWidget.js
b/resources/details/uw.DeedChooserDetailsWidget.js
index 966d720..a0f87e6 100644
--- a/resources/details/uw.DeedChooserDetailsWidget.js
+++ b/resources/details/uw.DeedChooserDetailsWidget.js
@@ -51,7 +51,7 @@
undefined,
config,
1,
- new mw.Api()
+ upload.api
);
deed.licenseInput.$element.addClass(
'mwe-upwiz-custom-deed' );
deed.licenseInputField = new uw.FieldLayout(
deed.licenseInput );
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 0378659..730e5e5 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -121,6 +121,8 @@
} else if ( result &&
result.textStatus === 'timeout' ) {
// in case of
$.ajax.fail(), there is no response json
response.errors[ 0
].html = mw.message( 'api-error-timeout' ).parse();
+ } else if ( result &&
result.textStatus === 'parsererror' ) {
+ response.errors[ 0
].html = mw.message( 'api-error-parsererror' ).parse();
} else if ( code === 'http' &&
result && result.xhr && result.xhr.status === 0 ) {
// failed to even
connect to server
response.errors[ 0
].html = mw.message( 'api-error-offline' ).parse();
@@ -145,12 +147,12 @@
* @return {mw.UploadWizardDeed[]}
*/
mw.UploadWizard.getLicensingDeeds = function ( uploadsLength, config ) {
- var deed,
+ var deed, api,
deeds = {},
doOwnWork = false,
doThirdParty = false;
- this.api = this.api || new mw.Api( { ajax: { timeout: 0 } } );
+ api = this.prototype.getApi( { ajax: { timeout: 0 } } );
if ( config.licensing.ownWorkDefault === 'choice' ) {
doOwnWork = doThirdParty = true;
@@ -161,11 +163,11 @@
}
if ( doOwnWork ) {
- deed = new mw.UploadWizardDeedOwnWork( uploadsLength,
this.api, config );
+ deed = new mw.UploadWizardDeedOwnWork( uploadsLength,
api, config );
deeds[ deed.name ] = deed;
}
if ( doThirdParty ) {
- deed = new mw.UploadWizardDeedThirdParty(
uploadsLength, this.api, config );
+ deed = new mw.UploadWizardDeedThirdParty(
uploadsLength, api, config );
deeds[ deed.name ] = deed;
}
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index 1c9a940..705917e 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -809,7 +809,7 @@
html: 'Unknown server error'
} } );
} else {
- if ( result.upload.stage === undefined
&& window.console ) {
+ if ( result.upload.stage === undefined
) {
return deferred.reject(
'no-stage', { error: {
code: 'no-stage',
html: 'Unable to check
file\'s status'
diff --git a/resources/mw.UploadWizardLicenseInput.js
b/resources/mw.UploadWizardLicenseInput.js
index 09768fc..246a6c2 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -529,7 +529,7 @@
template = result.parse.templates[ i ];
// normalize templates to
mw.Title.getPrefixedDb() format
- title = new mw.Title( template[ '*' ],
template.ns );
+ title = new mw.Title( template.title,
template.ns );
templates.push( title.getPrefixedDb() );
}
diff --git a/resources/transports/mw.FormDataTransport.js
b/resources/transports/mw.FormDataTransport.js
index 1ac8629..81c4c92 100644
--- a/resources/transports/mw.FormDataTransport.js
+++ b/resources/transports/mw.FormDataTransport.js
@@ -249,19 +249,6 @@
return
transport.retryWithMethod( 'checkStatus' );
}
} else {
- // Ain't this some great machine readable
output eh
- if (
- response.errors &&
- response.errors[ 0 ].code ===
'stashfailed' &&
- response.errors[ 0 ].html ===
mw.message( 'apierror-stashfailed-complete' ).parse()
- ) {
- return transport.retryWithMethod(
'checkStatus' );
- }
-
- // Failed to upload, try again in 3 seconds
- // This is really dumb, we should only do this
for cases where retrying has a chance to work
- // (so basically, network failures). If your
upload was blocked by AbuseFilter you're
- // shafted anyway. But some server-side errors
really are temporary...
return transport.maybeRetry(
'on unknown response',
response.error ? response.error.code :
'unknown-error',
@@ -271,6 +258,19 @@
);
}
}, function ( code, result ) {
+ // Ain't this some great machine readable output eh
+ if (
+ result.errors &&
+ result.errors[ 0 ].code === 'stashfailed' &&
+ result.errors[ 0 ].html === mw.message(
'apierror-stashfailed-complete' ).parse()
+ ) {
+ return transport.retryWithMethod( 'checkStatus'
);
+ }
+
+ // Failed to upload, try again in 3 seconds
+ // This is really dumb, we should only do this for
cases where retrying has a chance to work
+ // (so basically, network failures). If your upload was
blocked by AbuseFilter you're
+ // shafted anyway. But some server-side errors really
are temporary...
return transport.maybeRetry(
'on error event',
code,
@@ -361,9 +361,6 @@
if ( !this.firstPoll ) {
this.firstPoll = ( new Date() ).getTime();
}
- $.each( this.formData, function ( key, value ) {
- params[ key ] = value;
- } );
params.checkstatus = true;
params.filekey = this.filekey;
return this.api.post( params )
@@ -376,8 +373,8 @@
html: mw.message(
'apierror-unknownerror' ).parse()
} } );
} else {
- if ( response.upload.stage ===
undefined && window.console ) {
- window.console.log(
'Unable to check file\'s status' );
+ if ( response.upload.stage ===
undefined ) {
+ mw.log.warn( 'Unable to
check file\'s status' );
return
$.Deferred().reject( 'server-error', { error: {
code:
'server-error',
html:
mw.message( 'apierror-unknownerror' ).parse()
diff --git a/resources/uw.FieldLayout.js b/resources/uw.FieldLayout.js
index c886a06..5e271ef 100644
--- a/resources/uw.FieldLayout.js
+++ b/resources/uw.FieldLayout.js
@@ -85,15 +85,20 @@
/**
* @protected
* @param {string} kind 'error' or 'notice'
- * @param {Object} error Object in { key: ..., html: ... } format
+ * @param {mw.Message|Object} error Message, or an object in { key:
..., html: ... } format
* @return {jQuery}
*/
uw.FieldLayout.prototype.makeMessage = function ( kind, error ) {
- var
+ var code, html, $listItem;
+ if ( error.parseDom ) {
+ code = error.key;
+ content = error.parseDom();
+ } else {
code = error.code,
- html = error.html,
- $listItem =
uw.FieldLayout.parent.prototype.makeMessage.call( this, kind, html );
- $listItem.addClass( 'mwe-upwiz-fieldLayout-' + kind + '-' +
code );
+ content = $( $.parseHTML( error.html ) );
+ }
+ $listItem = uw.FieldLayout.parent.prototype.makeMessage.call(
this, kind, content )
+ .addClass( 'mwe-upwiz-fieldLayout-' + kind + '-' + code
);
return $listItem;
};
--
To view, visit https://gerrit.wikimedia.org/r/329361
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia48fd7842205dfba16948349b9c6acf0e9fa939c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits