r27312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r27311‎ | r27312 | r27313 >
Date:13:56, 8 November 2007
Author:catrope
Status:old
Tags:
Comment:
APIEDIT BRANCH MERGE:
* 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
Modified paths:
  • /trunk/phase3/includes/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialUndelete.php
@@ -303,6 +303,9 @@
304304 return ($n > 0);
305305 }
306306
 307+ const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
 308+ const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
 309+ const UNDELETE_UNKNOWNERR = -2; // Unknown error
307310 /**
308311 * Restore the given (or all) text and file revisions for the page.
309312 * Once restored, the items will be removed from the archive tables.
@@ -312,7 +315,7 @@
313316 * @param string $comment
314317 * @param array $fileVersions
315318 *
316 - * @return true on success.
 319+ * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
317320 */
318321 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
319322 // If both the set of text revisions and file revisions are empty,
@@ -332,6 +335,8 @@
333336
334337 if( $restoreText ) {
335338 $textRestored = $this->undeleteRevisions( $timestamps );
 339+ if($textRestored < 0) // It must be one of UNDELETE_*
 340+ return $textRestored;
336341 } else {
337342 $textRestored = 0;
338343 }
@@ -352,18 +357,14 @@
353358 $wgContLang->formatNum( $filesRestored ) );
354359 } else {
355360 wfDebug( "Undelete: nothing undeleted...\n" );
356 - return false;
 361+ return self::UNDELETE_NOTHINGRESTORED;
357362 }
358363
359364 if( trim( $comment ) != '' )
360365 $reason .= ": {$comment}";
361366 $log->addEntry( 'restore', $this->title, $reason );
362367
363 - if ( $this->fileStatus && !$this->fileStatus->ok ) {
364 - return false;
365 - } else {
366 - return true;
367 - }
 368+ return array($textRestored, $filesRestored, $reason);
368369 }
369370
370371 /**
@@ -375,7 +376,7 @@
376377 * @param string $comment
377378 * @param array $fileVersions
378379 *
379 - * @return int number of revisions restored
 380+ * @return int number of revisions restored on success or UNDELETE_* on failure
380381 */
381382 private function undeleteRevisions( $timestamps ) {
382383 if ( wfReadOnly() ) return 0;
@@ -442,7 +443,7 @@
443444 );
444445 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
445446 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
446 - return false;
 447+ return self::UNDELETE_NOTAVAIL;
447448 }
448449
449450 $revision = null;
@@ -476,6 +477,9 @@
477478 $revision->insertOn( $dbw );
478479 $restored++;
479480 }
 481+ // Was anything restored at all?
 482+ if($restored == 0)
 483+ return 0;
480484
481485 if( $revision ) {
482486 // Attach the latest revision to the page...
@@ -494,7 +498,8 @@
495499 Article::onArticleEdit( $this->title );
496500 }
497501 } else {
498 - # Something went terribly wrong!
 502+ // Revision couldn't be created. This is very weird
 503+ return self::UNDELETE_UNKNOWNERR;
499504 }
500505
501506 # Now that it's safely stored, take it out of the archive
@@ -1039,7 +1044,7 @@
10401045 $this->mComment,
10411046 $this->mFileVersions );
10421047
1043 - if( $ok ) {
 1048+ if( is_array($ok) ) {
10441049 $skin = $wgUser->getSkin();
10451050 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
10461051 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r87920Removed dead code path since r27312: $revision cannot be null if $restored is...ialex18:06, 12 May 2011

Status & tagging log