From 6f1ded506c2fb67d33dc11afba38c33cb0f0d073 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 24 Feb 2009 16:17:23 +0000 Subject: [PATCH] * (bug 17649) Added isDeletedQuick() and replaced some slow checks --- includes/EditPage.php | 2 +- includes/Title.php | 35 ++++++++++++++++++++++++----- includes/filerepo/File.php | 2 +- includes/specials/SpecialUpload.php | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 4163a127a8..840497ed6a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -324,7 +324,7 @@ class EditPage { protected function wasDeletedSinceLastEdit() { if ( $this->deletedSinceEdit ) return true; - if ( $this->mTitle->isDeleted() ) { + if ( $this->mTitle->isDeletedQuick() ) { $this->lastDelete = $this->getLastDelete(); if ( $this->lastDelete ) { $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp ); diff --git a/includes/Title.php b/includes/Title.php index 8ae93fe26f..888c47a4a0 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1979,20 +1979,45 @@ class Title { * @return \type{\int} the number of archived revisions */ public function isDeleted() { - $fname = 'Title::isDeleted'; - if ( $this->getNamespace() < 0 ) { + if( $this->getNamespace() < 0 ) { $n = 0; } else { $dbr = wfGetDB( DB_SLAVE ); - $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(), - 'ar_title' => $this->getDBkey() ), $fname ); + $n = $dbr->selectField( 'archive', 'COUNT(*)', + array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), + __METHOD__ + ); if( $this->getNamespace() == NS_FILE ) { $n += $dbr->selectField( 'filearchive', 'COUNT(*)', - array( 'fa_name' => $this->getDBkey() ), $fname ); + array( 'fa_name' => $this->getDBkey() ), + __METHOD__ + ); } } return (int)$n; } + + /** + * Is there a version of this page in the deletion archive? + * @return bool + */ + public function isDeletedQuick() { + if( $this->getNamespace() < 0 ) { + return false; + } + $dbr = wfGetDB( DB_SLAVE ); + $deleted = (bool)$dbr->selectField( 'archive', '1', + array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), + __METHOD__ + ); + if( !$deleted && $this->getNamespace() == NS_FILE ) { + $deleted = (bool)$dbr->selectField( 'filearchive', '1', + array( 'fa_name' => $this->getDBkey() ), + __METHOD__ + ); + } + return $deleted; + } /** * Get the article ID for this Title from the link cache, diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 03a8322030..523a1c0921 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -951,7 +951,7 @@ abstract class File { */ function wasDeleted() { $title = $this->getTitle(); - return $title && $title->isDeleted() > 0; + return $title && $title->isDeletedQuick(); } /** diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 074a9f2430..2d4b7f98f7 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -993,7 +993,7 @@ wgUploadAutoFill = {$autofill}; } // Show the relevant lines from deletion log (for still deleted files only) - if( $title instanceof Title && $title->isDeleted() > 0 && !$title->exists() ) { + if( $title instanceof Title && $title->isDeletedQuick() && !$title->exists() ) { $this->showDeletionLog( $wgOut, $title->getPrefixedText() ); } } -- 2.20.1