Index: trunk/phase3/includes/SpecialUndelete.php |
— | — | @@ -303,6 +303,9 @@ |
304 | 304 | return ($n > 0); |
305 | 305 | } |
306 | 306 | |
| 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 |
307 | 310 | /** |
308 | 311 | * Restore the given (or all) text and file revisions for the page. |
309 | 312 | * Once restored, the items will be removed from the archive tables. |
— | — | @@ -312,7 +315,7 @@ |
313 | 316 | * @param string $comment |
314 | 317 | * @param array $fileVersions |
315 | 318 | * |
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 |
317 | 320 | */ |
318 | 321 | function undelete( $timestamps, $comment = '', $fileVersions = array() ) { |
319 | 322 | // If both the set of text revisions and file revisions are empty, |
— | — | @@ -332,6 +335,8 @@ |
333 | 336 | |
334 | 337 | if( $restoreText ) { |
335 | 338 | $textRestored = $this->undeleteRevisions( $timestamps ); |
| 339 | + if($textRestored < 0) // It must be one of UNDELETE_* |
| 340 | + return $textRestored; |
336 | 341 | } else { |
337 | 342 | $textRestored = 0; |
338 | 343 | } |
— | — | @@ -352,18 +357,14 @@ |
353 | 358 | $wgContLang->formatNum( $filesRestored ) ); |
354 | 359 | } else { |
355 | 360 | wfDebug( "Undelete: nothing undeleted...\n" ); |
356 | | - return false; |
| 361 | + return self::UNDELETE_NOTHINGRESTORED; |
357 | 362 | } |
358 | 363 | |
359 | 364 | if( trim( $comment ) != '' ) |
360 | 365 | $reason .= ": {$comment}"; |
361 | 366 | $log->addEntry( 'restore', $this->title, $reason ); |
362 | 367 | |
363 | | - if ( $this->fileStatus && !$this->fileStatus->ok ) { |
364 | | - return false; |
365 | | - } else { |
366 | | - return true; |
367 | | - } |
| 368 | + return array($textRestored, $filesRestored, $reason); |
368 | 369 | } |
369 | 370 | |
370 | 371 | /** |
— | — | @@ -375,7 +376,7 @@ |
376 | 377 | * @param string $comment |
377 | 378 | * @param array $fileVersions |
378 | 379 | * |
379 | | - * @return int number of revisions restored |
| 380 | + * @return int number of revisions restored on success or UNDELETE_* on failure |
380 | 381 | */ |
381 | 382 | private function undeleteRevisions( $timestamps ) { |
382 | 383 | if ( wfReadOnly() ) return 0; |
— | — | @@ -442,7 +443,7 @@ |
443 | 444 | ); |
444 | 445 | if( $dbw->numRows( $result ) < count( $timestamps ) ) { |
445 | 446 | wfDebug( __METHOD__.": couldn't find all requested rows\n" ); |
446 | | - return false; |
| 447 | + return self::UNDELETE_NOTAVAIL; |
447 | 448 | } |
448 | 449 | |
449 | 450 | $revision = null; |
— | — | @@ -476,6 +477,9 @@ |
477 | 478 | $revision->insertOn( $dbw ); |
478 | 479 | $restored++; |
479 | 480 | } |
| 481 | + // Was anything restored at all? |
| 482 | + if($restored == 0) |
| 483 | + return 0; |
480 | 484 | |
481 | 485 | if( $revision ) { |
482 | 486 | // Attach the latest revision to the page... |
— | — | @@ -494,7 +498,8 @@ |
495 | 499 | Article::onArticleEdit( $this->title ); |
496 | 500 | } |
497 | 501 | } else { |
498 | | - # Something went terribly wrong! |
| 502 | + // Revision couldn't be created. This is very weird |
| 503 | + return self::UNDELETE_UNKNOWNERR; |
499 | 504 | } |
500 | 505 | |
501 | 506 | # Now that it's safely stored, take it out of the archive |
— | — | @@ -1039,7 +1044,7 @@ |
1040 | 1045 | $this->mComment, |
1041 | 1046 | $this->mFileVersions ); |
1042 | 1047 | |
1043 | | - if( $ok ) { |
| 1048 | + if( is_array($ok) ) { |
1044 | 1049 | $skin = $wgUser->getSkin(); |
1045 | 1050 | $link = $skin->makeKnownLinkObj( $this->mTargetObj ); |
1046 | 1051 | $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) ); |