More robust existence/sanity checking
authorRob Church <robchurch@users.mediawiki.org>
Mon, 20 Aug 2007 14:49:07 +0000 (14:49 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 20 Aug 2007 14:49:07 +0000 (14:49 +0000)
includes/FileDeleteForm.php
languages/messages/MessagesEn.php

index a0b861a..fec993a 100644 (file)
@@ -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
index 2ff1c13..b30a350 100644 (file)
@@ -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' => "<span class=\"plainlinks\">The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.</span>",
 '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