Use content format for unserializing in ApiEditPage
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index e7e5e1d..22e4ded 100644 (file)
@@ -146,7 +146,7 @@ class ApiEditPage extends ApiBase {
                                }
                        }
 
-                       // @todo: Add support for appending/prepending to the Content interface
+                       // @todo Add support for appending/prepending to the Content interface
 
                        if ( !( $content instanceof TextContent ) ) {
                                $mode = $contentHandler->getModelID();
@@ -293,6 +293,10 @@ class ApiEditPage extends ApiBase {
                        $requestArray['wpWatchthis'] = '';
                }
 
+               // Pass through anything else we might have been given, to support extensions
+               // This is kind of a hack but it's the best we can do to make extensions work
+               $requestArray += $this->getRequest()->getValues();
+
                global $wgTitle, $wgRequest;
 
                $req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
@@ -316,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, $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 = 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 );