JGonera has uploaded a new change for review.
https://gerrit.wikimedia.org/r/114908
Change subject: Story 1629: Captcha and AbuseFilter support in lead photo
uploads
......................................................................
Story 1629: Captcha and AbuseFilter support in lead photo uploads
In the process move _showHidden to OverlayNew so that it can be reused
for swapping headers in other overlays.
Change-Id: I5e5130c2dd88454800bb57af7be4c2158e45a348
---
M includes/Resources.php
M javascripts/common/OverlayNew.js
M javascripts/modules/editor/EditorOverlayBase.js
M javascripts/modules/uploads/PhotoApi.js
M javascripts/modules/uploads/PhotoUploadOverlay.js
M javascripts/modules/uploads/PhotoUploadProgress.js
M less/common/OverlayNew.less
M templates/uploads/PhotoUploadProgress.html
M tests/javascripts/modules/uploads/test_PhotoApi.js
9 files changed, 138 insertions(+), 69 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/08/114908/1
diff --git a/includes/Resources.php b/includes/Resources.php
index 7999c54..4e8b95e 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -728,7 +728,9 @@
'mobile-frontend-editor-blocked',
'mobile-frontend-editor-cta',
'mobile-frontend-editor-edit',
- // modules/editor/EditorOverlay.js and modules/talk.js
+ // modules/editor/EditorOverlay.js
+ // modules/talk.js
+ // modules/uploads/PhotoUploadProgress.js
'mobile-frontend-editor-save',
// PageApi.js
'mobile-frontend-last-modified-with-user-date',
diff --git a/javascripts/common/OverlayNew.js b/javascripts/common/OverlayNew.js
index 07d72da..8076fc4 100644
--- a/javascripts/common/OverlayNew.js
+++ b/javascripts/common/OverlayNew.js
@@ -31,6 +31,13 @@
self.$(
'.overlay-header-container' ).addClass( 'position-fixed' );
} );
}
+ },
+
+ _showHidden: function( className ) {
+ // can't use jQuery's hide() and show() beause show()
sets display: block
+ // and we want display: table for headers
+ this.$( '.hideable' ).addClass( 'hidden' );
+ this.$( className ).removeClass( 'hidden' );
}
} );
diff --git a/javascripts/modules/editor/EditorOverlayBase.js
b/javascripts/modules/editor/EditorOverlayBase.js
index 556d739..12cbbc2 100644
--- a/javascripts/modules/editor/EditorOverlayBase.js
+++ b/javascripts/modules/editor/EditorOverlayBase.js
@@ -113,12 +113,6 @@
this._showHidden( '.save-header, .captcha-panel' );
this.captchaShown = true;
- },
- _showHidden: function( className ) {
- // can't use jQuery's hide() and show() beause show()
sets display: block
- // and we want display: table for headers
- this.$( '.hideable' ).addClass( 'hidden' );
- this.$( className ).removeClass( 'hidden' );
}
} );
diff --git a/javascripts/modules/uploads/PhotoApi.js
b/javascripts/modules/uploads/PhotoApi.js
index d2e2074..b1756b8 100644
--- a/javascripts/modules/uploads/PhotoApi.js
+++ b/javascripts/modules/uploads/PhotoApi.js
@@ -89,9 +89,9 @@
// FIXME: See UploadBase::checkWarnings - why these are not
errors only the MediaWiki Gods know See Bug 48261
_handleWarnings: function( result, warnings ) {
- var errorMsg = 'upload/warning/', humanErrorMsg;
+ var err = { stage: 'upload', type: 'warning' },
humanErrorMsg;
- errorMsg += $.map( warnings, function( value, code ) {
+ err.details = $.map( warnings, function( value, code ) {
return code + '/' + value;
} )[0] || 'unknown';
@@ -99,7 +99,7 @@
humanErrorMsg = mw.msg(
'mobile-frontend-photo-upload-error-filename' );
}
- return result.reject( errorMsg, humanErrorMsg );
+ return result.reject( err, humanErrorMsg );
},
save: function( options ) {
@@ -149,16 +149,16 @@
} ).done( function( data ) {
var descriptionUrl = '',
warnings = data.upload ?
data.upload.warnings : false,
- err = 'upload/error';
+ err = { stage: 'upload', type:
'error' };
if ( !data || !data.upload ) {
// error uploading image
if ( data.error ) {
if ( data.error.code ) {
- err += '/' +
data.error.code;
- }
- if ( data.error.details
&& data.error.details[0] ) {
- err += '/' +
data.error.details[0];
+ err.details =
data.error.code;
+ if (
data.error.details && data.error.details[0] ) {
+
err.details += '/' + data.error.details[0];
+ }
}
}
result.reject( err );
@@ -173,7 +173,7 @@
} else if ( warnings ) {
return
self._handleWarnings( result, warnings );
} else {
- return result.reject(
'upload/unknown/missing-filename' );
+ return result.reject( {
stage: 'upload', type: 'unknown', details: 'missing-filename' } );
}
}
@@ -189,11 +189,8 @@
result.resolve(
options.fileName, descriptionUrl );
} ).
fail( function( err ) {
- var msg =
'edit/' + err.type;
- if ( typeof
err.details === 'string' ) {
- msg +=
'/' + err.details;
- }
- result.reject(
msg );
+ err.stage =
'edit';
+ result.reject(
err );
} );
} else {
result.resolve(
options.fileName, descriptionUrl );
@@ -202,7 +199,7 @@
} ).fail( function() {
// error on the server side (abort
happens when user cancels the upload)
if ( status !== 'abort' ) {
- result.reject(
'upload/error/http' );
+ result.reject( { stage:
'upload', type: 'error', details: 'http' } );
}
} );
diff --git a/javascripts/modules/uploads/PhotoUploadOverlay.js
b/javascripts/modules/uploads/PhotoUploadOverlay.js
index dc8ff89..6085066 100644
--- a/javascripts/modules/uploads/PhotoUploadOverlay.js
+++ b/javascripts/modules/uploads/PhotoUploadOverlay.js
@@ -43,39 +43,43 @@
self.setImageUrl( dataUri );
};
}
- this._super( options );
- },
- _submit: function() {
- var self = this,
- saveOptions,
- title = this.options.pageTitle,
- description = this.getDescription(),
- progressPopup = new PhotoUploadProgress(),
- api;
- saveOptions = {
- file: this.file,
- description: description
- };
-
- if ( this.options.insertInPage ) {
- api = new PhotoApi( {
- editorApi: new EditorApi( { title:
title } )
+ if ( options.insertInPage ) {
+ this.api = new PhotoApi( {
+ editorApi: new EditorApi( { title:
options.pageTitle } )
} );
} else {
- api = new PhotoApi();
+ this.api = new PhotoApi();
}
-
- this.hide( true );
- this.emit( 'hide' );
-
- progressPopup.show();
- progressPopup.on( 'cancel', function() {
- api.abort();
- self.log( { action: 'cancel' } );
+ this.api.on( 'uploadProgress', function( value ) {
+ self.progressPopup.setValue( value );
} );
- api.save( saveOptions ).done( function( fileName,
descriptionUrl ) {
- progressPopup.hide( true );
+
+ this.progressPopup = new PhotoUploadProgress().on(
'cancel', function() {
+ self.api.abort();
+ self.log( { action: 'cancel' } );
+ } ).on( 'submit', function() {
+ // handle resubmitting after abusefilter message
+ self._save();
+ } );
+
+ this._super( options );
+ },
+
+ _save: function() {
+ var
+ self = this,
+ description = this.getDescription(),
+ saveOptions = {
+ file: this.file,
+ description: description
+ };
+
+ this.api.save( saveOptions ).done( function( fileName,
descriptionUrl ) {
+ var title = self.options.pageTitle;
+
+ self.progressPopup.hide( true );
+
self.log( { action: 'success' } );
if ( self.options.insertInPage ) {
popup.show( mw.msg(
'mobile-frontend-photo-upload-success-article' ), 'toast' );
@@ -93,16 +97,32 @@
} );
}
} ).fail( function( err, msg ) {
- progressPopup.hide( true );
- popup.show( msg || mw.msg(
'mobile-frontend-photo-upload-error' ), 'toast error' );
- self.log( { action: 'error', errorText: err } );
- } );
+ var errMsg;
- api.on( 'uploadProgress', function( value ) {
- progressPopup.setValue( value );
+ if ( err.type === 'abusefilter' ) {
+ self.progressPopup.showAbuseFilter(
err.details.type, err.details.message );
+ } else {
+ self.progressPopup.hide( true );
+ popup.show( msg || mw.msg(
'mobile-frontend-photo-upload-error' ), 'toast error' );
+
+ errMsg = err.stage + '/' + err.type;
+ if ( typeof err.details === 'string' ) {
+ errMsg += '/' + err.details;
+ }
+ self.log( { action: 'error', errorText:
errMsg } );
+ }
} );
},
+ _submit: function() {
+ this.hide( true );
+ this.emit( 'hide' );
+
+ this.progressPopup.show();
+
+ this._save();
+ },
+
postRender: function() {
var self = this, $submitButton;
diff --git a/javascripts/modules/uploads/PhotoUploadProgress.js
b/javascripts/modules/uploads/PhotoUploadProgress.js
index 55f418e..f939398 100644
--- a/javascripts/modules/uploads/PhotoUploadProgress.js
+++ b/javascripts/modules/uploads/PhotoUploadProgress.js
@@ -1,12 +1,13 @@
-( function( M ) {
+( function( M, $ ) {
var OverlayNew = M.require( 'OverlayNew' ),
ProgressBar = M.require( 'widgets/progress-bar' ),
+ AbuseFilterPanel = M.require( 'modules/editor/AbuseFilterPanel'
),
PhotoUploadProgress;
PhotoUploadProgress = OverlayNew.extend( {
defaults: {
uploadingMsg: mw.msg( 'mobile-frontend-image-uploading'
),
- closeMsg: mw.msg( 'cancel' )
+ saveMsg: mw.msg( 'mobile-frontend-editor-save' )
},
template: M.template.get( 'uploads/PhotoUploadProgress' ),
fullScreen: false,
@@ -14,6 +15,16 @@
initialize: function( options ) {
this._super( options );
this.progressBar = new ProgressBar();
+ },
+
+ postRender: function() {
+ this._super();
+ this.$( '.submit' ).on( M.tapEvent( 'click' ), $.proxy(
this, 'emit', 'submit' ) );
+ },
+
+ showAbuseFilter: function( type, message ) {
+ new AbuseFilterPanel().appendTo( this.$(
'.overlay-header-container' ) ).show( type, message );
+ this._showHidden( '.save-header' );
},
hide: function( force ) {
@@ -41,4 +52,4 @@
M.define( 'modules/uploads/PhotoUploadProgress', PhotoUploadProgress );
-}( mw.mobileFrontend ) );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/less/common/OverlayNew.less b/less/common/OverlayNew.less
index 915ea4c..046972d 100644
--- a/less/common/OverlayNew.less
+++ b/less/common/OverlayNew.less
@@ -204,7 +204,6 @@
// FIXME: make those overlays use position fixed headers
position: absolute;
top: 0;
- white-space: nowrap;
&.position-fixed {
// both top and left required for Android 2 for the
element to be visible
@@ -218,6 +217,8 @@
}
.overlay-header {
+ white-space: nowrap;
+
> div {
padding: (@headerTitleMarginV - @headerMargin)
@headerTitleMarginH;
}
diff --git a/templates/uploads/PhotoUploadProgress.html
b/templates/uploads/PhotoUploadProgress.html
index a63f3fc..26b6e05 100644
--- a/templates/uploads/PhotoUploadProgress.html
+++ b/templates/uploads/PhotoUploadProgress.html
@@ -1,5 +1,5 @@
<div class="overlay-header-container position-fixed">
- <div class="overlay-header">
+ <div class="overlay-header progress-header hideable">
<ul class="v-border bottom-border">
<li><button class="cancel
icon">{{closeMsg}}</button></li>
</ul>
@@ -10,4 +10,14 @@
<li><button class="loading
icon">{{{uploadingMsg}}}</button></li>
</ul>
</div>
+ <div class="overlay-header save-header hideable hidden">
+ <ul class="v-border bottom-border">
+ <li><button class="cancel
icon">{{closeMsg}}</button></li>
+ </ul>
+ <div class="bottom-border">
+ </div>
+ <ul>
+ <li><button class="submit
icon">{{saveMsg}}</button></li>
+ </ul>
+ </div>
</div>
diff --git a/tests/javascripts/modules/uploads/test_PhotoApi.js
b/tests/javascripts/modules/uploads/test_PhotoApi.js
index cabadbe..c490e36 100644
--- a/tests/javascripts/modules/uploads/test_PhotoApi.js
+++ b/tests/javascripts/modules/uploads/test_PhotoApi.js
@@ -31,7 +31,11 @@
description: 'yo:: yo ::'
} ).fail( spy );
- assert.ok( spy.calledWith( 'upload/warning/badfilename/::.JPG'
), 'The request caused a bad file name error' );
+ assert.ok( spy.calledWith( {
+ stage: 'upload',
+ type: 'warning',
+ details: 'badfilename/::.JPG'
+ } ), 'The request caused a bad file name error' );
} );
QUnit.test( '#save, successful upload', 2, function( assert ) {
@@ -64,14 +68,24 @@
} ).done( doneSpy ).fail( failSpy );
assert.ok( !doneSpy.called, "don't call done" );
- assert.ok( failSpy.calledWith(
'upload/error/verification-error/abusefilter-warning' ), "call fail" );
+ assert.ok( failSpy.calledWith( {
+ stage: 'upload',
+ type: 'error',
+ details: 'verification-error/abusefilter-warning'
+ } ), "call fail" );
} );
QUnit.test( '#save. error inserting in page, captcha', 2, function(
assert ) {
- var doneSpy = this.sandbox.spy(), failSpy = this.sandbox.spy();
+ var doneSpy = this.sandbox.spy(), failSpy = this.sandbox.spy(),
+ captcha = {
+ type: "image",
+ mime: "image/png",
+ id: "1852528679",
+ url:
"/w/index.php?title=Especial:Captcha/image&wpCaptchaId=1852528679"
+ };
editorApi.post.
- returns( $.Deferred().resolve( { edit: { captcha: {},
result: 'Failure' } } ) );
+ returns( $.Deferred().resolve( { edit: { captcha:
captcha, result: 'Failure' } } ) );
photoApi.save( {
insertInPage: true,
@@ -82,14 +96,20 @@
} ).done( doneSpy ).fail( failSpy );
assert.ok( !doneSpy.called, "don't call done" );
- assert.ok( failSpy.calledWith( 'edit/captcha' ), "call fail" );
+ assert.ok( failSpy.calledWith( { stage: 'edit', type:
'captcha', details: captcha } ), "call fail" );
} );
QUnit.test( '#save, error inserting in page, AbuseFilter', 2, function(
assert ) {
var doneSpy = this.sandbox.spy(), failSpy = this.sandbox.spy();
- editorApi.post.
- returns( $.Deferred().resolve( { edit: { code:
'abusefilter-warning', result: 'Failure' } } ) );
+ editorApi.post.returns( $.Deferred().resolve( {
+ edit: {
+ code: "abusefilter-warning-usuwanie-tekstu",
+ info: "Hit AbuseFilter: Usuwanie du\u017cej
ilo\u015bci tekstu",
+ warning: "horrible desktop-formatted message",
+ result: "Failure"
+ }
+ } ) );
photoApi.save( {
insertInPage: true,
@@ -100,7 +120,14 @@
} ).done( doneSpy ).fail( failSpy );
assert.ok( !doneSpy.called, "don't call done" );
- assert.ok( failSpy.calledWith( 'edit/abusefilter' ), "call
fail" );
+ assert.ok( failSpy.calledWith( {
+ stage: 'edit',
+ type: 'abusefilter',
+ details: {
+ type: 'warning',
+ message: "horrible desktop-formatted message"
+ }
+ } ), "call fail" );
} );
QUnit.module( 'MobileFrontend photo: filenames' );
--
To view, visit https://gerrit.wikimedia.org/r/114908
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e5130c2dd88454800bb57af7be4c2158e45a348
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits