jenkins-bot has submitted this change and it was merged. Change subject: Clean up captcha form and remove <link> to stylesheet ......................................................................
Clean up captcha form and remove <link> to stylesheet The captcha response we're getting has a <link> to a stylesheet that is destructive and overrides styles in the wiki, especially RTL specific styles. This hack removes that link before letting the rest of the widgets display it in the DOM. Bug: T116910 Change-Id: Ieb9558c347c84917dac8b02fca41276e2b81303a (cherry picked from commit 65cc2f6c1d2e1ca8fe5ccd060c8f55a2adc177f2) --- M modules/flow-initialize.js M modules/flow/dm/api/mw.flow.dm.APIHandler.js M modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js M modules/flow/ui/widgets/mw.flow.ui.EditPostWidget.js M modules/flow/ui/widgets/mw.flow.ui.EditTopicSummaryWidget.js M modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js M modules/flow/ui/widgets/mw.flow.ui.ReplyWidget.js 7 files changed, 36 insertions(+), 11 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/flow-initialize.js b/modules/flow-initialize.js index 9772ec5..0e06f8c 100644 --- a/modules/flow-initialize.js +++ b/modules/flow-initialize.js @@ -389,7 +389,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { editor.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { editor.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); @@ -445,7 +445,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); diff --git a/modules/flow/dm/api/mw.flow.dm.APIHandler.js b/modules/flow/dm/api/mw.flow.dm.APIHandler.js index 13dc453..1080edb 100644 --- a/modules/flow/dm/api/mw.flow.dm.APIHandler.js +++ b/modules/flow/dm/api/mw.flow.dm.APIHandler.js @@ -210,7 +210,8 @@ return ( new mw.Api() ).postWithToken( 'edit', params ) .then( function ( response ) { return OO.getProp( response.flow, 'new-topic', 'committed', 'topiclist', 'topic-id' ); - } ); + } ) + .then( null, this.processCaptchaError.bind( this ) ); }; /** @@ -254,7 +255,8 @@ xhr = this.postEdit( 'edit-header', params ) .then( function ( data ) { return OO.getProp( data.flow, 'edit-header', 'committed', 'header', 'header-revision-id' ); - } ); + } ) + .then( null, this.processCaptchaError.bind( this ) ); return xhr.promise( { abort: xhr.abort } ); }; @@ -303,7 +305,8 @@ return this.postEdit( 'edit-post', params ) .then( function ( data ) { return OO.getProp( data.flow, 'edit-post', 'workflow' ); - } ); + } ) + .then( null, this.processCaptchaError.bind( this ) ); }; /** @@ -347,7 +350,8 @@ return this.postEdit( 'edit-topic-summary', params ) .then( function ( data ) { return OO.getProp( data.flow, 'edit-topic-summary', 'workflow' ); - } ); + } ) + .then( null, this.processCaptchaError.bind( this ) ); }; /** @@ -391,4 +395,25 @@ return this.lockTopic( topicId, 'unlock', 'flow-rev-message-restore-topic-reason' ); }; + /** + * Process captcha error and remove offending <link> tag + * This entire method is a necessary hack, because CAPTCHA returns an html block that + * contains a <link rel="stylesheet" ...> that contains destructive classes for RTL wikis. + * That link must be destroyed before being given to the DOM. + * HACK: This should really be done by making the CAPTCHA element not return garbage. + * + * @private + * @param {string} errorCode API error code + * @param {Object} errorObj API error object + * @return {jQuery.Promise} Rejected promise with the API error object adjusted + */ + mw.flow.dm.APIHandler.prototype.processCaptchaError = function ( errorCode, errorObj ) { + if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { + // // Remove the <link rel="stylesheet" ...> and <script> and <style> tags + errorObj.error.$info = $( $.parseHTML( errorObj.error.info ) ).not( 'link, script, style' ); + } + + return $.Deferred().reject( errorCode, errorObj ); + }; + }( jQuery ) ); diff --git a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js index 67fa12c..e9a35d5 100644 --- a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js +++ b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js @@ -246,7 +246,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { widget.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { widget.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); diff --git a/modules/flow/ui/widgets/mw.flow.ui.EditPostWidget.js b/modules/flow/ui/widgets/mw.flow.ui.EditPostWidget.js index 656d35b..fc0b9b6 100644 --- a/modules/flow/ui/widgets/mw.flow.ui.EditPostWidget.js +++ b/modules/flow/ui/widgets/mw.flow.ui.EditPostWidget.js @@ -137,7 +137,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { widget.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { widget.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); diff --git a/modules/flow/ui/widgets/mw.flow.ui.EditTopicSummaryWidget.js b/modules/flow/ui/widgets/mw.flow.ui.EditTopicSummaryWidget.js index 123a233..df7957c 100644 --- a/modules/flow/ui/widgets/mw.flow.ui.EditTopicSummaryWidget.js +++ b/modules/flow/ui/widgets/mw.flow.ui.EditTopicSummaryWidget.js @@ -138,7 +138,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { widget.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { widget.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); diff --git a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js index 6247307..c0c070d 100644 --- a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js +++ b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js @@ -178,7 +178,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { widget.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { widget.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); diff --git a/modules/flow/ui/widgets/mw.flow.ui.ReplyWidget.js b/modules/flow/ui/widgets/mw.flow.ui.ReplyWidget.js index b68c39d..0c13bc4 100644 --- a/modules/flow/ui/widgets/mw.flow.ui.ReplyWidget.js +++ b/modules/flow/ui/widgets/mw.flow.ui.ReplyWidget.js @@ -132,7 +132,7 @@ if ( /spamfilter$/.test( errorCode ) && errorObj.error.spamfilter === 'flow-spam-confirmedit-form' ) { widget.error.setLabel( // CAPTCHA form - new OO.ui.HtmlSnippet( errorObj.error.info ) + OO.getProp( errorObj, 'error', '$info' ) ); } else { widget.error.setLabel( errorObj.error && errorObj.error.info || errorObj.exception ); -- To view, visit https://gerrit.wikimedia.org/r/249910 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ieb9558c347c84917dac8b02fca41276e2b81303a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: wmf/1.27.0-wmf.4 Gerrit-Owner: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Mooeypoo <mor...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits