jenkins-bot has submitted this change and it was merged.

Change subject: mw: Implement support for ConfirmEdit and FancyCaptcha
......................................................................


mw: Implement support for ConfirmEdit and FancyCaptcha

* 'captcha' property from ConfirmEdit API is already exposed
  in ApiEdit and ApiVisualEditor through the 'edit' property
  in our response data.
* Add parameters 'captchaid' and 'captchaword' to ApiVisualEditor
  and mw.ViewPageTarget#getSaveOptions. ApiVisualEditor will
  forward these to ApiEdit which forwards them to FancyCaptcha.
* We display the captcha through a saveDialog warning.

Bug: 50356
Change-Id: Ia7d2102cba89d00ec8508e846061023b330ece4f
---
M ApiVisualEditor.php
M VisualEditor.php
M modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
M modules/ve/init/mw/ve.init.mw.Target.js
4 files changed, 90 insertions(+), 12 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index dfb3f6c..183a120 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -105,11 +105,22 @@
                        'starttimestamp' => $params['starttimestamp'],
                        'token' => $params['token'],
                );
+
                if ( $params['minor'] ) {
                        $apiParams['minor'] = true;
                }
+
                // FIXME add some way that the user's preferences can be 
respected
                $apiParams['watchlist'] = $params['watch'] ? 'watch' : 
'unwatch';
+
+               if ( $params['captchaid'] ) {
+                       $apiParams['captchaid'] = $params['captchaid'];
+               }
+
+               if ( $params['captchaword'] ) {
+                       $apiParams['captchaword'] = $params['captchaword'];
+               }
+
                $api = new ApiMain(
                        new DerivativeRequest(
                                $this->getRequest(),
@@ -118,7 +129,9 @@
                        ),
                        true // enable write
                );
+
                $api->execute();
+
                return $api->getResultData();
        }
 
@@ -255,7 +268,11 @@
                                        $this->dieUsage( 'Error contacting the 
Parsoid server', 'parsoidserver' );
                                } else {
                                        $result = array_merge(
-                                               array( 'result' => 'success', 
'notices' => $notices ), $parsed['result']
+                                               array(
+                                                       'result' => 'success',
+                                                       'notices' => $notices
+                                               ),
+                                               $parsed['result']
                                        );
                                }
                                break;
@@ -290,14 +307,15 @@
 
                                $result = $this->saveWikitext( $page, 
$wikitext, $params );
                                $editStatus = $result['edit']['result'];
-                               if (
-                                       !isset( $result['edit']['result'] ) ||
-                                       $editStatus !== 'Success'
-                               ) {
+
+                               // Error
+                               if ( !isset( $result['edit']['result'] ) || 
$editStatus !== 'Success' ) {
                                        $result = array(
                                                'result' => 'error',
                                                'edit' => $result['edit']
                                        );
+
+                               // Success
                                } else {
                                        if ( isset( $result['edit']['newrevid'] 
) && $wgVisualEditorUseChangeTagging ) {
                                                ChangeTags::addTags( 
'visualeditor', null,
@@ -362,7 +380,9 @@
                        'minor' => null,
                        'watch' => null,
                        'html' => null,
-                       'summary' => null
+                       'summary' => null,
+                       'captchaid' => null,
+                       'captchaword' => null,
                );
        }
 
@@ -402,6 +422,8 @@
                        'token' => 'Edit token',
                        'needcheck' => 'When saving, set this parameter if the 
revision might have roundtrip'
                                . 'problems. This will result in the edit being 
tagged.',
+                       'captchaid' => 'Captcha id (when saving with a captcha 
response).',
+                       'captchaword' => 'Answer to the captcha (when saving 
with a captcha response).',
                );
        }
 
diff --git a/VisualEditor.php b/VisualEditor.php
index 55a0387..14b208b 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -626,6 +626,11 @@
                        'visualeditor-toolbar-savedialog',
                        'visualeditor-viewpage-savewarning',
                        'visualeditor-window-title',
+
+                       // Only used if FancyCaptcha is installed and triggered 
on save
+                       'captcha-label',
+                       'fancycaptcha-edit',
+                       'colon-separator',
                ),
        ),
        'ext.visualEditor.experimental' => $wgVisualEditorResourceTemplate + 
array(
diff --git a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
index 399cb71..3d6df5f 100644
--- a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js
@@ -463,13 +463,48 @@
  * @method
  * @param {Object} jqXHR
  * @param {string} status Text status message
- * @param {Mixed} error Thrown exception or HTTP error string
- */
-ve.init.mw.ViewPageTarget.prototype.onSaveError = function ( jqXHR, status ) {
-       // TODO: Don't use alert.
-       alert( ve.msg( 'visualeditor-saveerror', status ) );
+ * @param {Object|null} data API response data
+  */
+ve.init.mw.ViewPageTarget.prototype.onSaveError = function ( jqXHR, status, 
data ) {
        this.saveDialogSaveButton.setDisabled( false );
        this.$saveDialogLoadingIcon.hide();
+
+       this.clearWarning( 'captcha' );
+
+       // Captcha "errors" usually aren't errors. We simply don't know about 
them ahead
+       // of time, so we save once, then (if required) we get a captcha back 
and try again
+       // with captcha.
+       // TODO: ConfirmEdit API is horrible, there is no reliable way to know 
whether
+       // it is a "math", "question" or "fancy" type of captcha. They all 
expose differently
+       // named properties in the API for different things. At this point we 
only support
+       // the FancyCaptha which we very intuitively detect by the presence of 
a "url" property.
+       if ( data.edit && data.edit.captcha && data.edit.captcha.url ) {
+               this.captcha = {
+                       input: new ve.ui.TextInputWidget(),
+                       id: data.edit.captcha.id
+               };
+               this.showWarning(
+                       'captcha',
+                       $( '<div>').append(
+                               // msg: simplecaptcha-edit, fancycaptcha-edit, 
..
+                               $( '<p>' ).append(
+                                       $( '<strong>' ).text( mw.msg( 
'captcha-label' ) ),
+                                       document.createTextNode( mw.msg( 
'colon-separator' ) ),
+                                       $( $.parseHTML( mw.message( 
'fancycaptcha-edit' ).parse() ) )
+                                               .filter( 'a' ).attr( 'target', 
'_blank ' ).end()
+                               ),
+                               $( '<img>' ).attr( 'src', data.edit.captcha.url 
),
+                               this.captcha.input.$
+                       ),
+                       {
+                               wrap: false
+                       }
+               );
+               return;
+       }
+
+       // TODO: Don't use alert.
+       alert( ve.msg( 'visualeditor-saveerror', status ) );
 };
 
 /**
@@ -736,7 +771,15 @@
 ve.init.mw.ViewPageTarget.prototype.onSaveDialogSaveButtonClick = function () {
        var doc = this.surface.getModel().getDocument(),
                saveOptions = this.getSaveOptions();
+
+       // Once we've retrieved the save options,
+       // reset save start and any old captcha data
        this.saveStart = +new Date();
+       if ( this.captcha ) {
+               this.clearWarning( 'captcha' );
+               delete this.captcha;
+       }
+
        if (
                +mw.user.options.get( 'forceeditsummary' ) &&
                saveOptions.summary === '' &&
@@ -789,7 +832,9 @@
                'summary': $( 
'#ve-init-mw-viewPageTarget-saveDialog-editSummary' ).val(),
                'minor': $( '#ve-init-mw-viewPageTarget-saveDialog-minorEdit' 
).prop( 'checked' ),
                'watch': $( '#ve-init-mw-viewPageTarget-saveDialog-watchList' 
).prop( 'checked' ),
-               'needcheck': this.sanityCheckPromise.state() === 'rejected'
+               'needcheck': this.sanityCheckPromise.state() === 'rejected',
+               'captchaid': this.captcha && this.captcha.id,
+               'captchaword': this.captcha && this.captcha.input.getValue()
        };
 };
 
diff --git a/modules/ve/init/mw/ve.init.mw.Target.js 
b/modules/ve/init/mw/ve.init.mw.Target.js
index 8cf07fe..5735026 100644
--- a/modules/ve/init/mw/ve.init.mw.Target.js
+++ b/modules/ve/init/mw/ve.init.mw.Target.js
@@ -580,6 +580,12 @@
        if ( options.needcheck ) {
                data.needcheck = 1;
        }
+       if ( options.captchaid ) {
+               data.captchaid = options.captchaid;
+       }
+       if ( options.captchaword ) {
+               data.captchaword = options.captchaword;
+       }
 
        // Save DOM
        this.saving = true;

-- 
To view, visit https://gerrit.wikimedia.org/r/71160
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7d2102cba89d00ec8508e846061023b330ece4f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to