From: Alexandre Emsenhuber Date: Mon, 16 Apr 2012 11:18:10 +0000 (+0200) Subject: Make data loading a bit better in ApiDelete. X-Git-Tag: 1.31.0-rc.0~23902^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=fbd17f8f52a0dde1bf6fdfc06cc49bb314ecdce9;p=lhc%2Fweb%2Fwiklou.git Make data loading a bit better in ApiDelete. * 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 --- diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 8a4a17fd93..b8ffff9f53 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -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 ) {