APIEDIT BRANCH MERGE:
authorRoan Kattouw <catrope@users.mediawiki.org>
Thu, 8 Nov 2007 13:56:56 +0000 (13:56 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Thu, 8 Nov 2007 13:56:56 +0000 (13:56 +0000)
* Changing return type of PageArchive::undelete() from bool to array (success) or UNDELETE_* constant (failure)
* PageArchive::undeleteRevisions() now returns an UNDELETE_* constant rather than false on error

includes/SpecialUndelete.php

index 786b4c9..563befa 100644 (file)
@@ -303,6 +303,9 @@ class PageArchive {
                return ($n > 0);
        }
 
+       const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
+       const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
+       const UNDELETE_UNKNOWNERR = -2; // Unknown error
        /**
         * Restore the given (or all) text and file revisions for the page.
         * Once restored, the items will be removed from the archive tables.
@@ -312,7 +315,7 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return true on success.
+        * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
         */
        function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
                // If both the set of text revisions and file revisions are empty,
@@ -332,6 +335,8 @@ class PageArchive {
                
                if( $restoreText ) {
                        $textRestored = $this->undeleteRevisions( $timestamps );
+                       if($textRestored < 0) // It must be one of UNDELETE_*
+                               return $textRestored;
                } else {
                        $textRestored = 0;
                }
@@ -352,18 +357,14 @@ class PageArchive {
                                $wgContLang->formatNum( $filesRestored ) );
                } else {
                        wfDebug( "Undelete: nothing undeleted...\n" );
-                       return false;
+                       return self::UNDELETE_NOTHINGRESTORED;
                }
                
                if( trim( $comment ) != '' )
                        $reason .= ": {$comment}";
                $log->addEntry( 'restore', $this->title, $reason );
 
-               if ( $this->fileStatus && !$this->fileStatus->ok ) {
-                       return false;
-               } else {
-                       return true;
-               }
+               return array($textRestored, $filesRestored, $reason);
        }
        
        /**
@@ -375,7 +376,7 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return int number of revisions restored
+        * @return int number of revisions restored on success or UNDELETE_* on failure
         */
        private function undeleteRevisions( $timestamps ) {
                if ( wfReadOnly() ) return 0;
@@ -442,7 +443,7 @@ class PageArchive {
                        );
                if( $dbw->numRows( $result ) < count( $timestamps ) ) {
                        wfDebug( __METHOD__.": couldn't find all requested rows\n" );
-                       return false;
+                       return self::UNDELETE_NOTAVAIL;
                }
                
                $revision = null;
@@ -476,6 +477,9 @@ class PageArchive {
                        $revision->insertOn( $dbw );
                        $restored++;
                }
+               // Was anything restored at all?
+               if($restored == 0)
+                       return 0;
 
                if( $revision ) {
                        // Attach the latest revision to the page...
@@ -494,7 +498,8 @@ class PageArchive {
                                Article::onArticleEdit( $this->title );
                        }
                } else {
-                       # Something went terribly wrong!
+                       // Revision couldn't be created. This is very weird
+                       return self::UNDELETE_UNKNOWNERR;
                }
 
                # Now that it's safely stored, take it out of the archive
@@ -1039,7 +1044,7 @@ class UndeleteForm {
                                $this->mComment,
                                $this->mFileVersions );
 
-                       if( $ok ) {
+                       if( is_array($ok) ) {
                                $skin = $wgUser->getSkin();
                                $link = $skin->makeKnownLinkObj( $this->mTargetObj );
                                $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );