Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/238642
Change subject: Display duplicates inline rather than in a popup
......................................................................
Display duplicates inline rather than in a popup
This results some changes in the localisation messages, which are
inexplicably defined in MediaWiki core. Submitted a core patch
I9661f24323371f186976df1f5569aba002d4f34e to update them (should be
merged after this patch).
* 'api-error-duplicate-archive-popup-title' and
'api-error-duplicate-popup-title' are no longer in use.
* 'api-error-duplicate-archive' and 'api-error-duplicate' no longer
need to generate a link (but we're compatible with either version).
Also correctly generate red links when applicable.
Code quality:
* UploadWizardUpload no longer reaches into UploadWizardUploadInterface
to display the 'Upload anyway' link.
* Got rid of one ghastly jQuery UI dialog.
* Removed a JSHint override.
Bug: T34606
Change-Id: I706d76ab4720a94e772d03196c91697d9047f5b9
---
M UploadWizardHooks.php
M resources/mw.UploadWizardUpload.js
M resources/mw.UploadWizardUploadInterface.js
M resources/uploadWizard.css
4 files changed, 73 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/42/238642/1
diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 4d710f5..ea6555e 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -27,6 +27,7 @@
'jquery.tipsy',
'jquery.ui.widget',
'jquery.validate',
+ 'jquery.makeCollapsible',
'mediawiki.Uri',
'mediawiki.util',
'mediawiki.libs.jpegmeta',
@@ -156,9 +157,7 @@
'api-error-badtoken',
'api-error-fetchfileerror',
'api-error-duplicate',
- 'api-error-duplicate-popup-title',
'api-error-duplicate-archive',
- 'api-error-duplicate-archive-popup-title',
'api-error-unknown-warning',
'api-error-timeout',
'api-error-noimageinfo',
diff --git a/resources/mw.UploadWizardUpload.js
b/resources/mw.UploadWizardUpload.js
index 73392ef..d99d8c1 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -153,14 +153,14 @@
/**
* Stop the upload -- we have failed for some reason
*/
- mw.UploadWizardUpload.prototype.setError = function ( code, info ) {
+ mw.UploadWizardUpload.prototype.setError = function ( code, info,
additionalStatus ) {
if ( this.state === 'aborted' ) {
// There's no point in reporting an error anymore.
return;
}
this.state = 'error';
this.transportProgress = 0;
- this.ui.showError( code, info );
+ this.ui.showError( code, info, additionalStatus );
this.emit( 'error', code, info );
};
@@ -181,13 +181,8 @@
return;
}
- function rmErrs( theCode ) {
- upload.removeErrors( theCode );
- }
-
// default error state
- var comma, warnCode, $override,
- upload = this,
+ var comma, warnCode,
code = 'unknown',
info = 'unknown';
@@ -237,24 +232,9 @@
// we ignore these warnings,
because the title is not our final title.
break;
case 'duplicate':
- code = warnCode;
- this.setError( warnCode,
this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
- break;
case 'duplicate-archive':
- // This is the case where the
file did exist, but it was deleted.
- // We should definitely tell
the user, but let them override.
- // If they already have, then
don't execute any of this.
code = warnCode;
- this.setError( warnCode,
this.duplicateErrorInfo( warnCode, result.upload.warnings[warnCode] ) );
- $override = $( '<a></a>' )
- /*jshint
scripturl:true*/
- .attr( 'href',
'javascript:void(0)' )
- .text( mw.message(
'mwe-upwiz-override' ).text() )
- .click( rmErrs.bind(
this, warnCode ) );
- $(
'.mwe-upwiz-file-status-line-item', this.ui.visibleFilenameDiv )
- .first()
- .append( ' ' )
- .append( $override );
+ this.setDuplicateError(
warnCode, result.upload.warnings[warnCode] );
break;
default:
// we have an unknown warning,
so let's say what we know
@@ -287,26 +267,14 @@
};
/**
- * Helper function to generate duplicate errors with dialog box. Works
with existing duplicates and deleted dupes.
- * @param {String} error code, should have matching strings in .i18n.php
- * @param {Object} portion of the API error result listing duplicates
+ * Helper function to generate duplicate errors in a possibly
collapsible list.
+ * Works with existing duplicates and deleted dupes.
+ * @param {String} code Error code, should have matching strings in
.i18n.php
+ * @param {Object} resultDuplicate Portion of the API error result
listing duplicates
+ * @return {jQuery}
*/
- mw.UploadWizardUpload.prototype.duplicateErrorInfo = function ( code,
resultDuplicate ) {
- function dialogFn(e) {
- $( '<div></div>' )
- .html( $ul )
- .dialog( {
- width: 500,
- zIndex: 200000,
- autoOpen: true,
- title: mw.message( 'api-error-' + code
+ '-popup-title', duplicates.length ).escaped(),
- modal: true
- } );
- e.preventDefault();
- }
-
- var duplicates,
- $ul = $( '<ul>' );
+ mw.UploadWizardUpload.prototype.setDuplicateError = function ( code,
resultDuplicate ) {
+ var duplicates, $ul, $override, $extra;
if ( typeof resultDuplicate === 'object' ) {
duplicates = resultDuplicate;
@@ -314,14 +282,18 @@
duplicates = [ resultDuplicate ];
}
+ $ul = $( '<ul>' );
$.each( duplicates, function ( i, filename ) {
- var href, $a;
+ var href, $a, params = {};
try {
- href = new mw.Title( filename, fileNsId
).getUrl();
- $a = $( '<a>' )
- .text( filename )
- .attr( { href: href, target: '_blank' }
);
+ $a = $( '<a>' ).text( filename );
+ if ( code === 'duplicate-archive' ) {
+ $a.addClass( 'new' );
+ params = { action: 'edit', redlink: '1'
};
+ }
+ href = new mw.Title( filename, fileNsId
).getUrl( params );
+ $a.attr( { href: href, target: '_blank' } );
} catch ( e ) {
// For example, if the file was revdeleted
$a = $( '<em>' )
@@ -330,7 +302,27 @@
$ul.append( $( '<li>' ).append( $a ) );
} );
- return [ duplicates.length, dialogFn ];
+ if ( duplicates.length > 1 ) {
+ $ul.makeCollapsible( { collapsed: true } );
+ }
+
+ $extra = $ul;
+ if ( code === 'duplicate-archive' ) {
+ $override = $( '<a>' )
+ .attr( 'href', '#' )
+ .text( mw.message( 'mwe-upwiz-override'
).text() )
+ .click( function () {
+ this.removeErrors( 'duplicate-archive'
);
+ }.bind( this ) );
+ $extra = $extra.add( $override );
+ }
+
+ // HACK Have to pass a noop function for
backwards-compatibility with old message translations
+ this.setError( code, [ duplicates.length, $.noop ], $extra );
+ // HACK Remove a link that does nothing
+ $( this.ui.div ).find( '.mwe-upwiz-file-status' ).find( 'a'
).replaceWith( function () {
+ return $( this ).text();
+ } );
};
/**
diff --git a/resources/mw.UploadWizardUploadInterface.js
b/resources/mw.UploadWizardUploadInterface.js
index 28690f2..b26976b 100644
--- a/resources/mw.UploadWizardUploadInterface.js
+++ b/resources/mw.UploadWizardUploadInterface.js
@@ -221,10 +221,25 @@
};
/**
+ * Set additional status information
+ * @param {jQuery} [$status] If not given or null, additional status is
cleared
+ */
+ mw.UploadWizardUploadInterface.prototype.setAdditionalStatus = function
( $status ) {
+ if ( this.$additionalStatus ) {
+ this.$additionalStatus.remove();
+ }
+ this.$additionalStatus = $status;
+ if ( this.$additionalStatus ) {
+ $( this.div ).find( '.mwe-upwiz-file-status' ).after(
this.$additionalStatus );
+ }
+ };
+
+ /**
* Clear the status line for this upload (hide it, in case there are
paddings and such which offset other things.)
*/
mw.UploadWizardUploadInterface.prototype.clearStatus = function () {
$( this.div ).find( '.mwe-upwiz-file-status' ).hide();
+ this.setAdditionalStatus( null );
};
/**
@@ -235,6 +250,7 @@
// if fraction available, update individual progress bar /
estimates, etc.
this.showIndicator( 'progress' );
this.setStatus( 'mwe-upwiz-uploading' );
+ this.setAdditionalStatus( null );
};
/**
@@ -249,14 +265,16 @@
this.showIndicator( 'stashed' );
this.setStatus( 'mwe-upwiz-stashed-upload' );
+ this.setAdditionalStatus( null );
};
/**
* Show that transport has failed
* @param String code: error code from API
* @param {String|Object} info: extra info
+ * @param {jQuery} [$additionalStatus]
*/
- mw.UploadWizardUploadInterface.prototype.showError = function ( code,
info ) {
+ mw.UploadWizardUploadInterface.prototype.showError = function ( code,
info, $additionalStatus ) {
this.showIndicator( 'error' );
// is this an error that we expect to have a message for?
var msgKey, args;
@@ -276,6 +294,7 @@
args = [ code ].concat( $.makeArray( info ) );
}
this.setStatus( msgKey, args );
+ this.setAdditionalStatus( $additionalStatus );
};
mw.UploadWizardUploadInterface.prototype.initFileInputCtrl = function
() {
diff --git a/resources/uploadWizard.css b/resources/uploadWizard.css
index 4fbb2a8..5074f3b 100644
--- a/resources/uploadWizard.css
+++ b/resources/uploadWizard.css
@@ -167,6 +167,11 @@
color: #797979;
}
+.mwe-upwiz-file-status-line ul {
+ margin-top: 0;
+ margin-bottom: 0;
+}
+
.mwe-upwiz-file-preview {
float: left;
height: 100px;
@@ -179,6 +184,12 @@
background: url('images/32px-Blank-document.svg.png') no-repeat center
center;
}
+.mwe-upwiz-file-texts {
+ /* This also create a new block formatting context, resulting in the
the whole block
+ displaying next to image thumbnail, rather than wrapping the lines
of text around it */
+ overflow: hidden;
+}
+
.mwe-upwiz-file-preview-broken {
height: 60px !important;
width: 60px !important;
--
To view, visit https://gerrit.wikimedia.org/r/238642
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I706d76ab4720a94e772d03196c91697d9047f5b9
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