r53715 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53714‎ | r53715 | r53716 >
Date:12:21, 24 July 2009
Author:aaron
Status:ok (Comments)
Tags:
Comment:
(bug 19905) Clean up revdelete/restore interaction
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -386,13 +386,14 @@
387387
388388 # Does this page already exist? We'll have to update it...
389389 $article = new Article( $this->title );
390 - $options = 'FOR UPDATE';
 390+ $options = 'FOR UPDATE'; // lock page
391391 $page = $dbw->selectRow( 'page',
392392 array( 'page_id', 'page_latest' ),
393393 array( 'page_namespace' => $this->title->getNamespace(),
394394 'page_title' => $this->title->getDBkey() ),
395395 __METHOD__,
396 - $options );
 396+ $options
 397+ );
397398 if( $page ) {
398399 $makepage = false;
399400 # Page already exists. Import the history, and if necessary
@@ -449,13 +450,34 @@
450451 $oldones ),
451452 __METHOD__,
452453 /* options */ array( 'ORDER BY' => 'ar_timestamp' )
453 - );
 454+ );
454455 $ret = $dbw->resultObject( $result );
455456 $rev_count = $dbw->numRows( $result );
 457+ if( !$rev_count ) {
 458+ wfDebug( __METHOD__.": no revisions to restore\n" );
 459+ return false; // ???
 460+ }
456461
 462+ $ret->seek( $rev_count - 1 ); // move to last
 463+ $row = $ret->fetchObject(); // get newest archived rev
 464+ $ret->seek( 0 ); // move back
 465+
457466 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...
458472 $newid = $article->insertOn( $dbw );
459473 $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+ }
460482 }
461483
462484 $revision = null;
@@ -467,7 +489,8 @@
468490 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
469491 if( $exists ) continue; // don't throw DB errors
470492 }
471 -
 493+ // Insert one revision at a time...maintaining deletion status
 494+ // unless we are specifically removing all restrictions...
472495 $revision = Revision::newFromArchiveRow( $row,
473496 array(
474497 'page' => $pageId,
@@ -495,16 +518,6 @@
496519 // Attach the latest revision to the page...
497520 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
498521 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 - }
509522 // Update site stats, link tables, etc
510523 $article->createUpdates( $revision );
511524 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r53854Merge r53715 (bug 19905) Clean up revdelete/restore interactionbrion03:31, 28 July 2009

Comments

#Comment by Aaron Schulz (talk | contribs)   12:29, 24 July 2009

This reverts r43300

Status & tagging log