Make data loading a bit better in ApiDelete.
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 16 Apr 2012 11:18:10 +0000 (13:18 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 16 Apr 2012 11:18:10 +0000 (13:18 +0200)
* Use WikiPage::newFromID() directly instead of Title::newFromID() (for now it does not change anything but it will soon)
* Directly load the data from the master when creating a page from its name, it avoids both having out-of-date information
  when doing the existence check and a second database query from LinkCache::addLinkObj() when calling (WikiPage|Title)::exists()
* Moved the page existence check to only be executed when creating a title from its name since if we have a WikiPage from its ID it must exist.

Change-Id: Ifaff725d955ce111c46d6b7f00610191820f3ced

includes/api/ApiDelete.php

index 8a4a17f..b8ffff9 100644 (file)
@@ -53,18 +53,20 @@ class ApiDelete extends ApiBase {
                        if ( !$titleObj ) {
                                $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                        }
+                       $pageObj = WikiPage::factory( $titleObj );
+                       $pageObj->loadPageData( 'fromdbmaster' );
+                       if ( !$pageObj->exists() ) {
+                               $this->dieUsageMsg( 'notanarticle' );
+                       }
                } elseif ( isset( $params['pageid'] ) ) {
-                       $titleObj = Title::newFromID( $params['pageid'] );
-                       if ( !$titleObj ) {
+                       $pageObj = WikiPage::newFromID( $params['pageid'] );
+                       if ( !$pageObj ) {
                                $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
                        }
-               }
-               if ( !$titleObj->exists() ) {
-                       $this->dieUsageMsg( 'notanarticle' );
+                       $titleObj = $pageObj->getTitle();
                }
 
                $reason = ( isset( $params['reason'] ) ? $params['reason'] : null );
-               $pageObj = WikiPage::factory( $titleObj );
                $user = $this->getUser();
 
                if ( $titleObj->getNamespace() == NS_FILE ) {