* Use the fact that WikiPage::getLatest() is updated when editing the page since...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 17 Nov 2011 10:33:20 +0000 (10:33 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 17 Nov 2011 10:33:20 +0000 (10:33 +0000)
* Moved override of $wgTitle and creation of EditPage object to the place they will be used

includes/api/ApiEditPage.php

index acd9ba1..7ae9370 100644 (file)
@@ -82,11 +82,6 @@ class ApiEditPage extends ApiBase {
                        }
                }
 
-               // Some functions depend on $wgTitle == $ep->mTitle
-               // TODO: Make them not or check if they still do
-               global $wgTitle;
-               $wgTitle = $titleObj;
-
                if ( $params['createonly'] && $titleObj->exists() ) {
                        $this->dieUsageMsg( 'createonly-exists' );
                }
@@ -103,7 +98,8 @@ class ApiEditPage extends ApiBase {
                        $this->dieUsageMsg( $errors[0] );
                }
 
-               $articleObj = new Article( $titleObj );
+               $articleObj = Article::newFromTitle( $titleObj, $this->getContext() );
+
                $toMD5 = $params['text'];
                if ( !is_null( $params['appendtext'] ) || !is_null( $params['prependtext'] ) )
                {
@@ -174,9 +170,6 @@ class ApiEditPage extends ApiBase {
                        $this->dieUsageMsg( 'hashcheckfailed' );
                }
 
-               $ep = new EditPage( $articleObj );
-               $ep->setContextTitle( $titleObj );
-
                // EditPage wants to parse its stuff from a WebRequest
                // That interface kind of sucks, but it's workable
                $reqArr = array(
@@ -234,8 +227,16 @@ class ApiEditPage extends ApiBase {
                        $reqArr['wpWatchthis'] = '';
                }
 
-               global $wgRequest;
-               $req = new DerivativeRequest( $wgRequest, $reqArr, true );
+               global $wgTitle, $wgRequest;
+
+               $req = new DerivativeRequest( $this->getRequest(), $reqArr, true );
+
+               // Some functions depend on $wgTitle == $ep->mTitle
+               // TODO: Make them not or check if they still do
+               $wgTitle = $titleObj;
+
+               $ep = new EditPage( $articleObj );
+               $ep->setContextTitle( $titleObj );
                $ep->importFormData( $req );
 
                // Run hooks
@@ -329,19 +330,14 @@ class ApiEditPage extends ApiBase {
                                $r['result'] = 'Success';
                                $r['pageid'] = intval( $titleObj->getArticleID() );
                                $r['title'] = $titleObj->getPrefixedText();
-                               // HACK: We create a new Article object here because getRevIdFetched()
-                               // refuses to be run twice, and because Title::getLatestRevId()
-                               // won't fetch from the master unless we select for update, which we
-                               // don't want to do.
-                               $newArticle = new Article( $titleObj );
-                               $newRevId = $newArticle->getRevIdFetched();
+                               $newRevId = $articleObj->getLatest();
                                if ( $newRevId == $oldRevId ) {
                                        $r['nochange'] = '';
                                } else {
                                        $r['oldrevid'] = intval( $oldRevId );
                                        $r['newrevid'] = intval( $newRevId );
                                        $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
-                                               $newArticle->getTimestamp() );
+                                               $articleObj->getTimestamp() );
                                }
                                break;