From d2a9aefba707544779be5dc209efd0417b60ea34 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Thu, 10 Mar 2016 18:58:41 +0000 Subject: [PATCH] Better handling of read-only mode * Don't just fail to load, action=visualeditor itself should not write to the DB (we have action=visualeditoredit for that) * Send notice to the client in the usual way * Handle read only errors on save, log as unknown This won't let you review changes because that uses visualeditoredit Bug: T129501 Change-Id: Id78c06b031423e47a7ddf94ec615b6d6975309d3 --- ApiVisualEditor.php | 6 +++++- extension.json | 1 + .../ve-mw/init/ve.init.mw.ArticleTarget.js | 20 +++++++++++++++++++ .../init/ve.init.mw.ArticleTargetEvents.js | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php index f57c3f9e6d..b49108d3a1 100644 --- a/ApiVisualEditor.php +++ b/ApiVisualEditor.php @@ -381,6 +381,10 @@ class ApiVisualEditor extends ApiBase { $notices[] = $this->msg( 'editingold' )->parseAsBlock(); } + if ( wfReadOnly() ) { + $notices[] = $this->msg( 'readonlywarning', wfReadOnlyReason() ); + } + // New page notices if ( !$title->exists() ) { $notices[] = $this->msg( @@ -698,6 +702,6 @@ class ApiVisualEditor extends ApiBase { } public function isWriteMode() { - return true; + return false; } } diff --git a/extension.json b/extension.json index 2919a82d83..acf6a1c1a6 100644 --- a/extension.json +++ b/extension.json @@ -360,6 +360,7 @@ "editing", "lastmodifiedat", "parentheses", + "readonlywarning", "redirectpagesub", "visualeditor-loadwarning", "visualeditor-loadwarning-token", diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js index ab8d5c1b1f..a2ad144ff6 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js @@ -135,6 +135,11 @@ OO.inheritClass( ve.init.mw.ArticleTarget, ve.init.mw.Target ); * Fired when the user tries to save page in violation of the TitleBlacklist */ +/** + * @event saveErrorReadOnly + * Fired when the user tries to save page but the database is locked + */ + /** * @event loadError */ @@ -467,6 +472,9 @@ ve.init.mw.ArticleTarget.prototype.saveFail = function ( doc, saveData, jqXHR, s } else if ( data.error && data.error.code === 'titleblacklist-forbidden' ) { this.saveErrorTitleBlacklist(); return; + } else if ( data.error && data.error.code === 'readonly' ) { + this.saveErrorReadOnly( data.error.readonlyreason ); + return; } // Handle captcha @@ -741,6 +749,18 @@ ve.init.mw.ArticleTarget.prototype.saveErrorPageDeleted = function () { this.emit( 'saveErrorPageDeleted' ); }; +/** + * Handle read only error + * + * @method + * @param {string} reason The reason given by the system administrator. + * @fires saveErrorReadOnly + */ +ve.init.mw.ArticleTarget.prototype.saveErrorReadOnly = function ( reason ) { + this.showSaveError( $( $.parseHTML( mw.message( 'readonlywarning', reason ).parse() ) ), true, true ); + this.emit( 'saveErrorReadOnly' ); +}; + /** * Handle an edit conflict * diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js index c6c10f8780..1a58ce2dd8 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js @@ -31,6 +31,7 @@ ve.init.mw.ArticleTargetEvents = function VeInitMwArticleTargetEvents( target ) saveErrorPageDeleted: [ 'trackSaveError', 'pagedeleted' ], saveErrorTitleBlacklist: [ 'trackSaveError', 'titleblacklist' ], saveErrorCaptcha: [ 'trackSaveError', 'captcha' ], + saveErrorReadOnly: [ 'trackSaveError', 'unknown' ], saveErrorUnknown: [ 'trackSaveError', 'unknown' ], editConflict: [ 'trackSaveError', 'editconflict' ], surfaceReady: 'onSurfaceReady',