From d69ffc8d6e7008851a1ea9f1c7201efbb94ef6fe Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Fri, 6 Feb 2015 19:51:09 +0000 Subject: [PATCH] Add a hook run after EditPage::attemptSave for WikiEditor So that we can determine whether a save attempt succeeded or failed, to log saveSuccess and saveFailure events from the server to Schema:Edit on meta. Bug: T88027 Change-Id: Ib861262603872e67600d1aab9bde3b58a8dd1738 --- RELEASE-NOTES-1.25 | 3 +++ docs/hooks.txt | 5 +++++ includes/EditPage.php | 14 +++++++++----- includes/api/ApiEditPage.php | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 83a569aeee..f365d7008d 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -378,6 +378,9 @@ changes to languages because of Bugzilla reports. addSecondaryDataUpdate throwing an exception. These functions will be removed in 1.26, since they interfere with caching of ParserOutput objects. * Introduced new hook 'SecondaryDataUpdates' that allows extensions to inject custom updates. +* EditPage::attemptSave has been modified not to call handleStatus itself and + instead just returns the Status object. Extension calling it should be aware of + this. == Compatibility == diff --git a/docs/hooks.txt b/docs/hooks.txt index cf2e3dd225..5899154b5a 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1144,6 +1144,11 @@ $editPage: EditPage object saved, that is before WikiPage::doEditContent() is called $editpage_Obj: the current EditPage object +'EditPage::attemptSave:after': Called after an article save attempt +$editpage_Obj: the current EditPage object +$status: the resulting Status object +$resultDetails: Result details array + 'EditPage::importFormData': allow extensions to read additional data posted in the form $editpage: EditPage instance diff --git a/includes/EditPage.php b/includes/EditPage.php index f5d98a7fbe..6789259f6a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -534,7 +534,9 @@ class EditPage { # in the back door with a hand-edited submission URL. if ( 'save' == $this->formtype ) { - if ( !$this->attemptSave() ) { + $resultDetails = null; + $status = $this->attemptSave( $resultDetails ); + if ( !$this->handleStatus( $status, $resultDetails ) ) { return; } } @@ -1284,18 +1286,20 @@ class EditPage { /** * Attempt submission + * @param array $resultDetails See docs for $result in internalAttemptSave * @throws UserBlockedError|ReadOnlyError|ThrottledError|PermissionsError - * @return bool False if output is done, true if the rest of the form should be displayed + * @return Status The resulting status object. */ - public function attemptSave() { + public function attemptSave( &$resultDetails = false ) { global $wgUser; - $resultDetails = false; # Allow bots to exempt some edits from bot flagging $bot = $wgUser->isAllowed( 'bot' ) && $this->bot; $status = $this->internalAttemptSave( $resultDetails, $bot ); - return $this->handleStatus( $status, $resultDetails ); + Hooks::run( 'EditPage::attemptSave:after', array( $this, $status, $resultDetails ) ); + + return $status; } /** diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 8ad2ad9383..15fa333f73 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -255,6 +255,7 @@ class ApiEditPage extends ApiBase { 'wpIgnoreBlankSummary' => true, 'wpIgnoreBlankArticle' => true, 'wpIgnoreSelfRedirect' => true, + 'bot' => $params['bot'], ); if ( !is_null( $params['summary'] ) ) { @@ -401,7 +402,7 @@ class ApiEditPage extends ApiBase { $oldRequest = $wgRequest; $wgRequest = $req; - $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] ); + $status = $ep->attemptSave( $result ); $wgRequest = $oldRequest; switch ( $status->value ) { -- 2.20.1