Merge "Improved readability of MediaWikiParserTest::suite code"
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index 1d6dc66..ab60008 100644 (file)
@@ -46,10 +46,6 @@ class ApiEditPage extends ApiBase {
 
                $pageObj = $this->getTitleOrPageId( $params );
                $titleObj = $pageObj->getTitle();
-               if ( $titleObj->isExternal() ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
-               }
-
                $apiResult = $this->getResult();
 
                if ( $params['redirect'] ) {
@@ -62,6 +58,8 @@ class ApiEditPage extends ApiBase {
                                // array_shift( $titles );
 
                                $redirValues = array();
+
+                               /** @var $newTitle Title */
                                foreach ( $titles as $id => $newTitle ) {
 
                                        if ( !isset( $titles[$id - 1] ) ) {
@@ -102,7 +100,7 @@ class ApiEditPage extends ApiBase {
                        $name = $titleObj->getPrefixedDBkey();
                        $model = $contentHandler->getModelID();
 
-                       $this->dieUsage( "The requested format $contentFormat is not supported for content model ".
+                       $this->dieUsage( "The requested format $contentFormat is not supported for content model " .
                                                        " $model used by $name", 'badformat' );
                }
 
@@ -261,7 +259,7 @@ class ApiEditPage extends ApiBase {
                if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) {
                        $requestArray['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] );
                } else {
-                       $requestArray['wpStarttime'] = wfTimestampNow();        // Fake wpStartime
+                       $requestArray['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
                }
 
                if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) )       {
@@ -303,12 +301,13 @@ class ApiEditPage extends ApiBase {
                // TODO: Make them not or check if they still do
                $wgTitle = $titleObj;
 
-               $articleObject = new Article( $titleObj );
-
                $articleContext = new RequestContext;
                $articleContext->setRequest( $req );
-               $articleContext->setTitle( $titleObj );
-               $articleObject->setContext( $articleContext );
+               $articleContext->setWikiPage( $pageObj );
+               $articleContext->setUser( $this->getUser() );
+
+               /** @var $articleObject Article */
+               $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
 
                $ep = new EditPage( $articleObject );
 
@@ -397,6 +396,7 @@ class ApiEditPage extends ApiBase {
 
                        case EditPage::AS_SUCCESS_NEW_ARTICLE:
                                $r['new'] = '';
+                               // fall-through
 
                        case EditPage::AS_SUCCESS_UPDATE:
                                $r['result'] = 'Success';
@@ -409,7 +409,6 @@ class ApiEditPage extends ApiBase {
                                } else {
                                        $r['oldrevid'] = intval( $oldRevId );
                                        $r['newrevid'] = intval( $newRevId );
-                                       $pageObj->clear();
                                        $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
                                                $pageObj->getTimestamp() );
                                }
@@ -497,7 +496,6 @@ class ApiEditPage extends ApiBase {
                        'section' => null,
                        'sectiontitle' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => false,
                        ),
                        'text' => null,
                        'token' => array(
@@ -637,10 +635,8 @@ class ApiEditPage extends ApiBase {
 
        public function getExamples() {
                return array(
-
                        'api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\'
                                => 'Edit a page (anonymous user)',
-
                        'api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\'
                                => 'Prepend __NOTOC__ to a page (anonymous user)',
                        'api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\'