From be97167ab61e7d59d86f6a9dca53b7016d615735 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Fri, 26 Jul 2013 13:43:08 +0200 Subject: [PATCH] Make APIEditBeforeSave give the whole revision rather then just the current section. This makes the hook behave as documented in docs/hooks.txt. Bug: 52077 Change-Id: Ia59fb6bbcbf2ae4119aa9dc316af8130e0235e78 --- RELEASE-NOTES-1.22 | 2 ++ includes/api/ApiEditPage.php | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 2658193461..517a44ccb0 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -232,6 +232,8 @@ production. * (bug 51891) Fixed PHP notice on Special:PagesWithProp when no properties are defined. * (bug 52006) Corrected documentation of $wgTranscludeCacheExpiry. +* (bug 52077) The APIEditBeforeSave hook is giving the content of the whole + revision as second argument now, rather than just the current section. * (bug 49694) $wgSpamRegex is now also applied on the new section headline text adding a new topic on a page diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 5b29ea6ef0..051958027b 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -320,11 +320,37 @@ class ApiEditPage extends ApiBase { $ep->setContextTitle( $titleObj ); $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() ) { + + $sectionTitle = ''; + // 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 ); + + $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 = array(); - if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) { + if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) { if ( count( $r ) ) { $r['result'] = 'Failure'; $apiResult->addValue( null, $this->getModuleName(), $r ); -- 2.20.1