Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/224295
Change subject: Handle CAPTCHAs with different mime types different ...................................................................... Handle CAPTCHAs with different mime types different ConfirmEdit supports different CAPTCHA modules, which return different CAPTCHAs. MobileFrontend actually supports only images as CAPTCHAs. This change adds support for text based CAPTCHAs, like text/plain (SimpleCaptcha and QuestyCaptcha) and text/tex (MathCaptcha), as well as image based CAPTCHAs, like image/png (FancyCaptcha and ReCaptcha) and image/jpg (not used, yet). Extra points: * Fix a FIXME Bug: T105617 Change-Id: Ica9e4ed7ce4af20822fd7969508e2fcbf3145256 --- M resources/mobile.editor.common/EditorOverlayBase.hogan M resources/mobile.editor.common/EditorOverlayBase.js M resources/mobile.editor.overlay/EditorOverlay.js M resources/mobile.editor.ve/VisualEditorOverlay.js 4 files changed, 27 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/95/224295/1 diff --git a/resources/mobile.editor.common/EditorOverlayBase.hogan b/resources/mobile.editor.common/EditorOverlayBase.hogan index 7aff9b5..064a87f 100644 --- a/resources/mobile.editor.common/EditorOverlayBase.hogan +++ b/resources/mobile.editor.common/EditorOverlayBase.hogan @@ -13,7 +13,8 @@ </div> <div class="captcha-panel panel hideable hidden"> <div class="captcha-box"> - <img src=""> + <img id="image" src=""> + <div id="question"></div> <input class="captcha-word mw-ui-input" placeholder="{{captchaMsg}}" /> </div> </div> diff --git a/resources/mobile.editor.common/EditorOverlayBase.js b/resources/mobile.editor.common/EditorOverlayBase.js index 5f7e8f6..b7a3f3f 100644 --- a/resources/mobile.editor.common/EditorOverlayBase.js +++ b/resources/mobile.editor.common/EditorOverlayBase.js @@ -362,19 +362,13 @@ return true; }, + /** - * Checks whether the state of the thing being edited as changed. Expects to be - * implemented by child class. + * Handles a failed save due to a CAPTCHA. * @method + * @param {Object} details Details returned from the api. */ - hasChanged: $.noop(), - /** - * Reveal the captcha in the View - * @method - * @private - * @param {String} url a url to an image representing the current captcha. - */ - _showCaptcha: function ( url ) { + handleCaptcha: function ( details ) { var self = this, $input = this.$( '.captcha-word' ); @@ -386,9 +380,26 @@ }, 2000 ); } - this.$( '.captcha-panel img' ).attr( 'src', url ); - this.showHidden( '.save-header, .captcha-panel' ); + switch ( details.mime ) { + default: + // this should never happen, if there is no funky new CAPTCHA module in ConfirmEdit with + // an unsupported mime-type. + toast.show( 'Unhandeld CAPTCHA type', 'error' ); + this.hide(); + break; + case 'text/plain': + case 'text/tex': + this.$( '.captcha-panel #image' ).detach(); + this.$( '.captcha-panel #question' ).text( details.question ); + break; + case 'image/png': + case 'image/jpg': + this.$( '.captcha-panel#question' ).detach(); + this.$( '.captcha-panel img' ).attr( 'src', details.url ); + break; + } + this.showHidden( '.save-header, .captcha-panel' ); this.captchaShown = true; } } ); diff --git a/resources/mobile.editor.overlay/EditorOverlay.js b/resources/mobile.editor.overlay/EditorOverlay.js index 776e258..1b72a83 100644 --- a/resources/mobile.editor.overlay/EditorOverlay.js +++ b/resources/mobile.editor.overlay/EditorOverlay.js @@ -423,8 +423,7 @@ if ( data.type === 'captcha' ) { self.captchaId = data.details.id; - // FIXME: Don't call a private method that is outside the class. - self._showCaptcha( data.details.url ); + self.handleCaptcha( data.details ); } else if ( data.type === 'abusefilter' ) { self._showAbuseFilter( data.details.type, data.details.message ); } else { diff --git a/resources/mobile.editor.ve/VisualEditorOverlay.js b/resources/mobile.editor.ve/VisualEditorOverlay.js index 5a715f0..1875009 100644 --- a/resources/mobile.editor.ve/VisualEditorOverlay.js +++ b/resources/mobile.editor.ve/VisualEditorOverlay.js @@ -290,8 +290,7 @@ */ onSaveErrorCaptcha: function ( editApi ) { this.captchaId = editApi.captcha.id; - // FIXME: Don't call a private method that is outside the class. - this._showCaptcha( editApi.captcha.url ); + this.handleCaptcha( editApi.captcha ); }, /** @inheritdoc **/ hasChanged: function () { -- To view, visit https://gerrit.wikimedia.org/r/224295 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ica9e4ed7ce4af20822fd7969508e2fcbf3145256 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits