Merge "Set default type attribute for button html elements"
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index 87302e6..81b3ef2 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'] ) {
@@ -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' );
                }
@@ -128,17 +131,10 @@ class ApiEditPage extends ApiBase {
                {
                        $content = $pageObj->getContent();
 
-                       // @todo: Add support for appending/prepending to the Content interface
-
-                       if ( !( $content instanceof TextContent ) ) {
-                               $mode = $contentHandler->getModelID();
-                               $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
-                       }
-
                        if ( !$content ) {
-                               # If this is a MediaWiki:x message, then load the messages
-                               # and return the message value for x.
                                if ( $titleObj->getNamespace() == NS_MEDIAWIKI ) {
+                                       # If this is a MediaWiki:x message, then load the messages
+                                       # and return the message value for x.
                                        $text = $titleObj->getDefaultMessageText();
                                        if ( $text === false ) {
                                                $text = '';
@@ -150,9 +146,19 @@ class ApiEditPage extends ApiBase {
                                                $this->dieUsage( $ex->getMessage(), 'parseerror' );
                                                return;
                                        }
+                               } else {
+                                       # Otherwise, make a new empty content.
+                                       $content = $contentHandler->makeEmptyContent();
                                }
                        }
 
+                       // @todo: Add support for appending/prepending to the Content interface
+
+                       if ( !( $content instanceof TextContent ) ) {
+                               $mode = $contentHandler->getModelID();
+                               $this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
+                       }
+
                        if ( !is_null( $params['section'] ) ) {
                                if ( !$contentHandler->supportsSections() ) {
                                        $modelName = $contentHandler->getModelID();
@@ -243,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'] != '' ) {
@@ -565,7 +576,7 @@ class ApiEditPage extends ApiBase {
                        'watch' => 'Add the page to your watchlist',
                        'unwatch' => 'Remove the page from your watchlist',
                        'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
-                       'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
+                       'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
                                        'If set, the edit won\'t be done unless the hash is correct' ),
                        'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
                        'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.",