"upload-options": "Upload options",
"watchthisupload": "Watch this file",
"filewasdeleted": "A file of this name has been previously uploaded and subsequently deleted.\nYou should check the $1 before proceeding to upload it again.",
+ "filename-thumb-name": "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.",
"filename-bad-prefix": "The name of the file you are uploading begins with <strong>\"$1\"</strong>, which is a non-descriptive name typically assigned automatically by digital cameras.\nPlease choose a more descriptive name for your file.",
"filename-prefix-blacklist": " #<!-- leave this line exactly as it is --> <pre>\n# Syntax is as follows:\n# * Everything from a \"#\" character to the end of the line is a comment\n# * Every non-blank line is a prefix for typical filenames assigned automatically by digital cameras\nCIMG # Casio\nDSC_ # Nikon\nDSCF # Fuji\nDSCN # Nikon\nDUW # some mobile phones\nIMG # generic\nJD # Jenoptik\nMGP # Pentax\nPICT # misc.\n #</pre> <!-- leave this line exactly as it is -->",
"upload-success-subj": "Successful upload",
"upload-options": "Caption above a section of the [[Special:Upload]] page",
"watchthisupload": "In [[Special:Upload]]",
"filewasdeleted": "This warning is shown when trying to upload a file that does not exist, but has previously been deleted.\n\nParameters:\n* $1 - a link to the deletion log, with the text from {{msg-mw|deletionlog}}",
+ "filename-thumb-name": "Appears when thumbnail title is similar to \"22px-Example.jpg\" - the prefix is what MW adds when downloading pictures as thumbnails.",
"filename-bad-prefix": "Used as warning in [[Special:Upload]]. Parameters:\n* $1 - prefix\nSee also:\n* {{msg-mw|fileexists}}\n* {{msg-mw|filepageexists}}\n* {{msg-mw|fileexists-extension}}\n* {{msg-mw|fileexists-thumbnail-yes}}\n* {{msg-mw|file-thumbnail-no}}\n* {{msg-mw|filewasdeleted}}",
"filename-prefix-blacklist": "{{optional}}\nDo not translate the file name prefixes before the hash mark (#). Leave all the wiki markup, including the spaces, as is. You can translate the text, including 'Leave this line exactly as it is'. The first line of this messages has one (1) leading space.",
"upload-success-subj": "Used as message subject which is posted on the user talk page.\n\nSee also:\n* {{msg-mw|upload-success-subj|subject}}\n* {{msg-mw|upload-success-msg|message}}\n* {{msg-mw|upload-failure-subj|subject}}\n* {{msg-mw|upload-failure-msg|message}}",
'dependencies' => array(
'oojs-ui',
'mediawiki.Upload',
+ 'mediawiki.jqueryMsg',
),
'messages' => array(
'upload-process-error',
'upload-form-label-infoform-description',
'upload-form-label-usage-title',
'upload-form-label-usage-filename',
+ 'fileexists',
+ 'filepageexists',
+ 'filename-bad-prefix',
+ 'filename-thumb-name',
+ 'badfilename',
+ 'api-error-duplicate-archive',
),
),
'mediawiki.ForeignStructuredUpload.BookletLayout' => array(
this.upload.setFilename( this.getFilename() );
this.upload.setText( this.getText() );
- this.uploadPromise.always( function () {
- layout.upload.finishStashUpload().always( function () {
+ this.uploadPromise.then( function () {
+ layout.upload.finishStashUpload().then( function () {
var name;
+ // Normalize page name and localise the 'File:' prefix
+ name = new mw.Title( 'File:' + layout.upload.getFilename() ).toString();
+ layout.filenameUsageWidget.setValue( '[[' + name + ']]' );
+ layout.setPage( 'insert' );
+
+ deferred.resolve();
+ layout.emit( 'fileSaved' );
+ }, function () {
+ var stateDetails = layout.upload.getStateDetails();
+
if ( layout.upload.getState() === mw.Upload.State.ERROR ) {
- deferred.reject( new OO.ui.Error( mw.msg( 'upload-process-error' ), {
+ deferred.reject( new OO.ui.Error( stateDetails, {
recoverable: false
} ) );
return false;
}
if ( layout.upload.getState() === mw.Upload.State.WARNING ) {
- deferred.reject( new OO.ui.Error( mw.msg( 'upload-process-warning' ), {
- recoverable: false
- } ) );
+ if ( stateDetails.exists !== undefined ) {
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'filepageexists', stateDetails.exists ).parse()
+ ),
+ { recoverable: false }
+ ) );
+ } else if ( stateDetails.duplicate !== undefined ) {
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'fileexists', stateDetails.duplicate[ 0 ] ).parse()
+ ),
+ { recoverable: false }
+ ) );
+ } else if ( stateDetails[ 'thumb-name' ] !== undefined ) {
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'filename-thumb-name' ).parse()
+ ),
+ { recoverable: false }
+ ) );
+ } else if ( stateDetails[ 'bad-prefix' ] !== undefined ) {
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'filename-bad-prefix', stateDetails[ 'bad-prefix' ] ).parse()
+ ),
+ { recoverable: false }
+ ) );
+ } else if ( stateDetails[ 'duplicate-archive' ] !== undefined ) {
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'api-error-duplicate-archive', stateDetails[ 'duplicate-archive' ] ).parse()
+ ),
+ { recoverable: false }
+ ) );
+ } else if ( stateDetails.badfilename !== undefined ) {
+ // Change the name if the current name isn't acceptable
+ layout.filenameWidget.setValue( stateDetails.badfilename );
+ deferred.reject( new OO.ui.Error(
+ $( '<p>' ).html(
+ mw.message( 'badfilename', stateDetails.badfilename ).parse()
+ )
+ ) );
+ }
+
return false;
}
-
- // Normalize page name and localise the 'File:' prefix
- name = new mw.Title( 'File:' + layout.upload.getFilename() ).toString();
- layout.filenameUsageWidget.setValue( '[[' + name + ']]' );
- layout.setPage( 'insert' );
-
- deferred.resolve();
- layout.emit( 'fileSaved' );
} );
} );
/**
* Sets the state and state details (if any) of the upload.
+ *
+ * @param {mw.Upload.State} state
+ * @param {string|Object} stateDetails
*/
UP.setState = function ( state, stateDetails ) {
this.state = state;
upload.setState( Upload.State.UPLOADED );
upload.imageinfo = result.upload.imageinfo;
return result;
- }, function () {
+ }, function ( result ) {
+ // Errors are strings that can be used to get error message
+ if ( typeof result === 'string' ) {
+ upload.setState( Upload.State.ERROR, mw.message( 'api-error-' + result ) );
+ return;
+ }
+
+ // Warnings come in the form of objects
+ if ( $.isPlainObject( result ) ) {
+ upload.setState( Upload.State.WARNING, result );
+ return;
+ }
+
+ // Throw an empty error if we can't figure it out
upload.setState( Upload.State.ERROR );
} );
} );