From: Alexandre Emsenhuber Date: Fri, 20 Apr 2012 09:57:01 +0000 (+0200) Subject: Make data loading a bit better in ApiProtect. X-Git-Tag: 1.31.0-rc.0~23820^2 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=8cc5236e18da6ddae2cb2a0fa2e601764c8fcf8f;p=lhc%2Fweb%2Fwiklou.git Make data loading a bit better in ApiProtect. * Use WikiPage::newFromID() directly instead of Title::newFromID() (change pending review to improve it) * Directly load the data from the master when creating a page from its name, it avoids a second database query when calling $this->getLatest() in WikiPage::doUpdateRestrictions() Change-Id: I993d087961c0ef41a2e3f8d949922d3d30ca1fde --- diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index ec7b560b88..596bc5ca71 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -44,11 +44,14 @@ class ApiProtect extends ApiBase { if ( !$titleObj ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } + $pageObj = WikiPage::factory( $titleObj ); + $pageObj->loadPageData( 'fromdbmaster' ); } elseif ( isset( $params['pageid'] ) ) { - $titleObj = Title::newFromID( $params['pageid'] ); - if ( !$titleObj ) { + $pageObj = WikiPage::newFromID( $params['pageid'] ); + if ( !$pageObj ) { $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) ); } + $titleObj = $pageObj->getTitle(); } $errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() ); @@ -115,7 +118,6 @@ class ApiProtect extends ApiBase { $watch = $params['watch'] ? 'watch' : $params['watchlist']; $this->setWatch( $watch, $titleObj ); - $pageObj = WikiPage::factory( $titleObj ); $status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() ); if ( !$status->isOK() ) {