Make data loading a bit better in ApiProtect.
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 20 Apr 2012 09:57:01 +0000 (11:57 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Wed, 25 Apr 2012 09:22:52 +0000 (11:22 +0200)
* 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

includes/api/ApiProtect.php

index ec7b560..596bc5c 100644 (file)
@@ -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() ) {