* Introduced FileRepoStatus -- result class for file repo operations.
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
index 8f49a29..52f1ecc 100644 (file)
@@ -23,6 +23,7 @@ function wfSpecialUndelete( $par ) {
  */
 class PageArchive {
        protected $title;
+       var $fileStatus;
 
        function __construct( $title ) {
                if( is_null( $title ) ) {
@@ -270,7 +271,8 @@ class PageArchive {
                
                if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
                        $img = wfLocalFile( $this->title );
-                       $filesRestored = $img->restore( $fileVersions );
+                       $this->fileStatus = $img->restore( $fileVersions );
+                       $filesRestored = $this->fileStatus->successCount;
                } else {
                        $filesRestored = 0;
                }
@@ -280,7 +282,7 @@ class PageArchive {
                } else {
                        $textRestored = 0;
                }
-               
+
                // Touch the log!
                global $wgContLang;
                $log = new LogPage( 'delete' );
@@ -303,8 +305,12 @@ class PageArchive {
                if( trim( $comment ) != '' )
                        $reason .= ": {$comment}";
                $log->addEntry( 'restore', $this->title, $reason );
-               
-               return true;
+
+               if ( $this->fileStatus && !$this->fileStatus->ok ) {
+                       return false;
+               } else {
+                       return true;
+               }
        }
        
        /**
@@ -448,6 +454,7 @@ class PageArchive {
                return $restored;
        }
 
+       function getFileStatus() { return $this->fileStatus; }
 }
 
 /**
@@ -731,8 +738,13 @@ class UndeleteForm {
                $logViewer = new LogViewer(
                        new LogReader(
                                new FauxRequest(
-                                       array( 'page' => $this->mTargetObj->getPrefixedText(),
-                                                  'type' => 'delete' ) ) ) );
+                                       array( 
+                                               'page' => $this->mTargetObj->getPrefixedText(),
+                                               'type' => 'delete' 
+                                       ) 
+                               )
+                       ), LogViewer::NO_ACTION_LINK
+               );
                $logViewer->showList( $wgOut );
                
                if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
@@ -836,15 +848,23 @@ class UndeleteForm {
                                $this->mTargetTimestamp,
                                $this->mComment,
                                $this->mFileVersions );
-                       
+
                        if( $ok ) {
                                $skin = $wgUser->getSkin();
                                $link = $skin->makeKnownLinkObj( $this->mTargetObj );
                                $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
-                               return true;
+                       } else {
+                               $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
                        }
+
+                       // Show file deletion warnings and errors
+                       $status = $archive->getFileStatus();
+                       if ( $status && !$status->isGood() ) {
+                               $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
+                       }
+               } else {
+                       $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
                }
-               $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
                return false;
        }
 }