From ee8bbf0be8a4f2e5ccf39a0e7fa0ad4369e697b0 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 17 Nov 2011 10:33:20 +0000 Subject: [PATCH] * Use the fact that WikiPage::getLatest() is updated when editing the page since r103383 * Moved override of $wgTitle and creation of EditPage object to the place they will be used --- includes/api/ApiEditPage.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index acd9ba17ae..7ae93706a4 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -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; -- 2.20.1