Revert "Make APIEditBeforeSave give the whole revision"
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 7 Apr 2016 06:01:11 +0000 (08:01 +0200)
committerOri.livneh <ori@wikimedia.org>
Fri, 10 Jun 2016 21:29:30 +0000 (21:29 +0000)
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
docs/hooks.txt
includes/api/ApiEditPage.php

index 3aa5d7c..c13be51 100644 (file)
@@ -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.
index c91354d..93f84a1 100644 (file)
@@ -375,8 +375,12 @@ $user: Current user
 processing request parameters. Return false to let the request fail, returning
 an error message or an <edit result="Failure"> 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
index 08aba94..d3d7a4d 100644 (file)
@@ -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 = [];