From 8f6287bf44b7599b9d20713e100f4a4829ba2e2d Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 20 Aug 2007 14:49:07 +0000 Subject: [PATCH] More robust existence/sanity checking --- includes/FileDeleteForm.php | 24 ++++++++---------------- languages/messages/MessagesEn.php | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index a0b861a927..fec993afc7 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -10,6 +10,8 @@ class FileDeleteForm { private $title = null; private $file = null; + + private $oldfile = null; private $oldimage = ''; /** @@ -50,6 +52,8 @@ class FileDeleteForm { $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) ); return; } + if( $this->oldimage ) + $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage ); if( !$this->haveDeletableFile() ) { $wgOut->addHtml( $this->prepareMessage( 'filedelete-nofile' ) ); @@ -57,14 +61,6 @@ class FileDeleteForm { return; } - // Don't allow accidental deletion of a single file revision - // if this is, in fact, the current revision; things might break - if( $this->oldimage && $this->file->getTimestamp() == $this->getTimestamp() ) { - $wgOut->addHtml( wfMsgExt( 'filedelete-iscurrent', 'parse' ) ); - $wgOut->addReturnTo( $this->title ); - return; - } - // Perform the deletion if appropriate if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) { $comment = $wgRequest->getText( 'wpComment' ); @@ -173,8 +169,9 @@ class FileDeleteForm { * @return bool */ private function haveDeletableFile() { - $file = wfFindFile( $this->title, $this->oldimage ); - return $file && $file->exists() && $file->isLocal(); + return $this->oldimage + ? $this->oldfile && $this->oldfile->exists() && $this->oldfile->isLocal() + : $this->file && $this->file->exists() && $this->file->isLocal(); } /** @@ -196,12 +193,7 @@ class FileDeleteForm { * @return string */ private function getTimestamp() { - static $timestamp = false; - if( $timestamp === false ) { - $file = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage ); - $timestamp = $file->getTimestamp(); - } - return $timestamp; + return $this->oldfile->getTimestamp(); } } \ No newline at end of file diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 2ff1c13905..b30a350668 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1512,7 +1512,7 @@ If you have this image in full resolution upload this one, otherwise change the 'filedelete-success' => "'''$1''' has been deleted.", 'filedelete-success-old' => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.", 'filedelete-nofile' => "'''$1''' does not exist on this site.", -'filedelete-nofile-old' => "There is no version of '''$1''' dated $3, $2.", +'filedelete-nofile-old' => "There is no archived version of '''$1''' with the specified attributes.", 'filedelete-iscurrent' => 'You are attempting to delete the most recent version of this file. Please revert to an older version first.', # MIME search -- 2.20.1