From 070783d314205b00e94256b2ef47dfab77a36118 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 7 Apr 2016 08:01:11 +0200 Subject: [PATCH] Revert "Make APIEditBeforeSave give the whole revision" This may negatively affect performance and the whole purpose of the hook (making it possible to reject an edit from an extension while providing detailed error information in the API result) has been invalidated by 09a5febb7b024c0b6585141bb05cba13a642f3eb, which lets EditFilterMergedContent do this too. I think it was intentional that the hook was called with just the text passed to action=edit API. Making it actually be called with the text that's going to be saved would require more work (e.g. for automatically resolved edit conflicts, T73947). Very few extensions use this hook. I'm fixing AbuseFilter to use EditFilterMergedContent in I30c1e3d0a6c10888e6ac53745313434474663cce, we should also review ConfirmEdit, ProofreadPage and SpamBlacklist to see what behavior they really expect. This reverts commit be97167ab61e7d59d86f6a9dca53b7016d615735. Change-Id: I62713419496bcf57364a8fa9de93c0c8ddc3e91c --- RELEASE-NOTES-1.27 | 3 +++ docs/hooks.txt | 6 +++++- includes/api/ApiEditPage.php | 29 ----------------------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27 index 3aa5d7cce8..c13be519cc 100644 --- a/RELEASE-NOTES-1.27 +++ b/RELEASE-NOTES-1.27 @@ -262,6 +262,9 @@ The following PHP extensions are strongly recommended: === Bug fixes in 1.27 === * Special:Upload will now display correct maximum allowed file size when running under HHVM (T116347). +* (T54077) The APIEditBeforeSave hook will once again give only the content of + the section being edited, rather than the whole revision. This reverts the + change made in MediaWiki 1.22. === Action API changes in 1.27 === * Added list=allrevisions. diff --git a/docs/hooks.txt b/docs/hooks.txt index c91354d2ff..93f84a1b5a 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -375,8 +375,12 @@ $user: Current user processing request parameters. Return false to let the request fail, returning an error message or an tag if $resultArr was filled. Unlike for example 'EditFilterMergedContent' this also being run on undo. +Since MediaWiki 1.25, 'EditFilterMergedContent' can also return error details +for the API and it's recommended to use it instead of this hook. $editPage: the EditPage object -$text: the new text of the article (has yet to be saved) +$text: the text passed to the API. Note that this includes only the single + section for section edit, and is not necessarily the final text in case of + automatically resolved edit conflicts. &$resultArr: data in this array will be added to the API result 'ApiFeedContributions::feedItem': Called to convert the result of ContribsPager diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 08aba9482e..d3d7a4df6b 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -398,35 +398,6 @@ class ApiEditPage extends ApiBase { $ep->importFormData( $req ); $content = $ep->textbox1; - // The following is needed to give the hook the full content of the - // new revision rather than just the current section. (Bug 52077) - if ( !is_null( $params['section'] ) && - $contentHandler->supportsSections() && $titleObj->exists() - ) { - // If sectiontitle is set, use it, otherwise use the summary as the section title (for - // backwards compatibility with old forms/bots). - if ( $ep->sectiontitle !== '' ) { - $sectionTitle = $ep->sectiontitle; - } else { - $sectionTitle = $ep->summary; - } - - $contentObj = $contentHandler->unserializeContent( $content, $contentFormat ); - - $fullContentObj = $articleObject->replaceSectionContent( - $params['section'], - $contentObj, - $sectionTitle - ); - if ( $fullContentObj ) { - $content = $fullContentObj->serialize( $contentFormat ); - } else { - // This most likely means we have an edit conflict which means that the edit - // wont succeed anyway. - $this->dieUsageMsg( 'editconflict' ); - } - } - // Run hooks // Handle APIEditBeforeSave parameters $r = []; -- 2.20.1