Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71160
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.
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, 74 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/60/71160/1
diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index dfb3f6c..4190d6a 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -255,7 +255,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 +294,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 +367,9 @@
'minor' => null,
'watch' => null,
'html' => null,
- 'summary' => null
+ 'summary' => null,
+ 'captchaid' => null,
+ 'captchaword' => null,
);
}
diff --git a/VisualEditor.php b/VisualEditor.php
index 55a0387..0cd41e5 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -626,6 +626,10 @@
'visualeditor-toolbar-savedialog',
'visualeditor-viewpage-savewarning',
'visualeditor-window-title',
+
+ // Only used if FancyCaptcha is installed and triggered
on save
+ 'captcha-label',
+ 'fancycaptcha-edit'
),
),
'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 22fe047..49fcd3d 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( ': ' ),
+ $( $.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 retreived 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: newchange
Gerrit-Change-Id: Ia7d2102cba89d00ec8508e846061023b330ece4f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits