From fbd17f8f52a0dde1bf6fdfc06cc49bb314ecdce9 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 16 Apr 2012 13:18:10 +0200 Subject: [PATCH] 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 --- includes/api/ApiDelete.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 ) { -- 2.20.1