Index: branches/wmf-deployment/includes/specials/SpecialUndelete.php |
— | — | @@ -386,13 +386,14 @@ |
387 | 387 | |
388 | 388 | # Does this page already exist? We'll have to update it... |
389 | 389 | $article = new Article( $this->title ); |
390 | | - $options = 'FOR UPDATE'; |
| 390 | + $options = 'FOR UPDATE'; // lock page |
391 | 391 | $page = $dbw->selectRow( 'page', |
392 | 392 | array( 'page_id', 'page_latest' ), |
393 | 393 | array( 'page_namespace' => $this->title->getNamespace(), |
394 | 394 | 'page_title' => $this->title->getDBkey() ), |
395 | 395 | __METHOD__, |
396 | | - $options ); |
| 396 | + $options |
| 397 | + ); |
397 | 398 | if( $page ) { |
398 | 399 | $makepage = false; |
399 | 400 | # Page already exists. Import the history, and if necessary |
— | — | @@ -449,13 +450,34 @@ |
450 | 451 | $oldones ), |
451 | 452 | __METHOD__, |
452 | 453 | /* options */ array( 'ORDER BY' => 'ar_timestamp' ) |
453 | | - ); |
| 454 | + ); |
454 | 455 | $ret = $dbw->resultObject( $result ); |
455 | 456 | $rev_count = $dbw->numRows( $result ); |
| 457 | + if( !$rev_count ) { |
| 458 | + wfDebug( __METHOD__.": no revisions to restore\n" ); |
| 459 | + return false; // ??? |
| 460 | + } |
456 | 461 | |
| 462 | + $ret->seek( $rev_count - 1 ); // move to last |
| 463 | + $row = $ret->fetchObject(); // get newest archived rev |
| 464 | + $ret->seek( 0 ); // move back |
| 465 | + |
457 | 466 | if( $makepage ) { |
| 467 | + // Check the state of the newest to-be version... |
| 468 | + if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) { |
| 469 | + return false; // we can't leave the current revision like this! |
| 470 | + } |
| 471 | + // Safe to insert now... |
458 | 472 | $newid = $article->insertOn( $dbw ); |
459 | 473 | $pageId = $newid; |
| 474 | + } else { |
| 475 | + // Check if a deleted revision will become the current revision... |
| 476 | + if( $row->ar_timestamp > $previousTimestamp ) { |
| 477 | + // Check the state of the newest to-be version... |
| 478 | + if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) { |
| 479 | + return false; // we can't leave the current revision like this! |
| 480 | + } |
| 481 | + } |
460 | 482 | } |
461 | 483 | |
462 | 484 | $revision = null; |
— | — | @@ -467,7 +489,8 @@ |
468 | 490 | $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ ); |
469 | 491 | if( $exists ) continue; // don't throw DB errors |
470 | 492 | } |
471 | | - |
| 493 | + // Insert one revision at a time...maintaining deletion status |
| 494 | + // unless we are specifically removing all restrictions... |
472 | 495 | $revision = Revision::newFromArchiveRow( $row, |
473 | 496 | array( |
474 | 497 | 'page' => $pageId, |
— | — | @@ -495,16 +518,6 @@ |
496 | 519 | // Attach the latest revision to the page... |
497 | 520 | $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId ); |
498 | 521 | if( $newid || $wasnew ) { |
499 | | - // We don't handle well with top revision deleted |
500 | | - // FIXME: any sysop can unsuppress any revision by just undeleting it into a non-existent page! |
501 | | - if( $revision->getVisibility() ) { |
502 | | - $dbw->update( 'revision', |
503 | | - array( 'rev_deleted' => 0 ), |
504 | | - array( 'rev_id' => $revision->getId() ), |
505 | | - __METHOD__ |
506 | | - ); |
507 | | - $revision->mDeleted = 0; // Don't pollute the parser cache |
508 | | - } |
509 | 522 | // Update site stats, link tables, etc |
510 | 523 | $article->createUpdates( $revision ); |
511 | 524 | } |