raise timeout for CdbTest::testCdb()
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index ec1b06e..74d3e14 100644 (file)
@@ -54,28 +54,6 @@ class ApiEditPage extends ApiBase {
                        $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                }
 
-               if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
-                       $contentHandler = $pageObj->getContentHandler();
-               } else {
-                       $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
-               }
-
-               // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such
-
-               if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) {
-                       $params['contentformat'] = $contentHandler->getDefaultFormat();
-               }
-
-               $contentFormat = $params['contentformat'];
-
-               if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
-                       $name = $titleObj->getPrefixedDBkey();
-                       $model = $contentHandler->getModelID();
-
-                       $this->dieUsage( "The requested format $contentFormat is not supported for content model ".
-                                                       " $model used by $name", 'badformat' );
-               }
-
                $apiResult = $this->getResult();
 
                if ( $params['redirect'] ) {
@@ -90,12 +68,12 @@ class ApiEditPage extends ApiBase {
                                $redirValues = array();
                                foreach ( $titles as $id => $newTitle ) {
 
-                                       if ( !isset( $titles[ $id - 1 ] ) ) {
-                                               $titles[ $id - 1 ] = $oldTitle;
+                                       if ( !isset( $titles[$id - 1] ) ) {
+                                               $titles[$id - 1] = $oldTitle;
                                        }
 
                                        $redirValues[] = array(
-                                               'from' => $titles[ $id - 1 ]->getPrefixedText(),
+                                               'from' => $titles[$id - 1]->getPrefixedText(),
                                                'to' => $newTitle->getPrefixedText()
                                        );
 
@@ -104,9 +82,34 @@ class ApiEditPage extends ApiBase {
 
                                $apiResult->setIndexedTagName( $redirValues, 'r' );
                                $apiResult->addValue( null, 'redirects', $redirValues );
+
+                               // Since the page changed, update $pageObj
+                               $pageObj = WikiPage::factory( $titleObj );
                        }
                }
 
+               if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
+                       $contentHandler = $pageObj->getContentHandler();
+               } else {
+                       $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
+               }
+
+               // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such
+
+               if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) {
+                       $params['contentformat'] = $contentHandler->getDefaultFormat();
+               }
+
+               $contentFormat = $params['contentformat'];
+
+               if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
+                       $name = $titleObj->getPrefixedDBkey();
+                       $model = $contentHandler->getModelID();
+
+                       $this->dieUsage( "The requested format $contentFormat is not supported for content model ".
+                                                       " $model used by $name", 'badformat' );
+               }
+
                if ( $params['createonly'] && $titleObj->exists() ) {
                        $this->dieUsageMsg( 'createonly-exists' );
                }
@@ -246,6 +249,11 @@ class ApiEditPage extends ApiBase {
                        $requestArray['wpSectionTitle'] = $params['sectiontitle'];
                }
 
+               // TODO: Pass along information from 'undoafter' as well
+               if ( $params['undo'] > 0 ) {
+                       $requestArray['wpUndidRevision'] = $params['undo'];
+               }
+
                // Watch out for basetimestamp == ''
                // wfTimestamp() treats it as NOW, almost certainly causing an edit conflict
                if ( !is_null( $params['basetimestamp'] ) && $params['basetimestamp'] != '' ) {
@@ -399,6 +407,7 @@ class ApiEditPage extends ApiBase {
                                } else {
                                        $r['oldrevid'] = intval( $oldRevId );
                                        $r['newrevid'] = intval( $newRevId );
+                                       $pageObj->clear();
                                        $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
                                                $pageObj->getTimestamp() );
                                }
@@ -640,8 +649,4 @@ class ApiEditPage extends ApiBase {
        public function getHelpUrls() {
                return 'https://www.mediawiki.org/wiki/API:Edit';
        }
-
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }
 }