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.
* @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,
if( $restoreText ) {
$textRestored = $this->undeleteRevisions( $timestamps );
+ if($textRestored < 0) // It must be one of UNDELETE_*
+ return $textRestored;
} else {
$textRestored = 0;
}
$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);
}
/**
* @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;
);
if( $dbw->numRows( $result ) < count( $timestamps ) ) {
wfDebug( __METHOD__.": couldn't find all requested rows\n" );
- return false;
+ return self::UNDELETE_NOTAVAIL;
}
$revision = null;
$revision->insertOn( $dbw );
$restored++;
}
+ // Was anything restored at all?
+ if($restored == 0)
+ return 0;
if( $revision ) {
// Attach the latest revision to the page...
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
$this->mComment,
$this->mFileVersions );
- if( $ok ) {
+ if( is_array($ok) ) {
$skin = $wgUser->getSkin();
$link = $skin->makeKnownLinkObj( $this->mTargetObj );
$wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );