00001 <?php
00002
00014 function wfSpecialUndelete( $par ) {
00015 global $wgRequest;
00016
00017 $form = new UndeleteForm( $wgRequest, $par );
00018 $form->execute();
00019 }
00020
00025 class PageArchive {
00026 protected $title;
00027 var $fileStatus;
00028
00029 function __construct( $title ) {
00030 if( is_null( $title ) ) {
00031 throw new MWException( 'Archiver() given a null title.');
00032 }
00033 $this->title = $title;
00034 }
00035
00043 public static function listAllPages() {
00044 $dbr = wfGetDB( DB_SLAVE );
00045 return self::listPages( $dbr, '' );
00046 }
00047
00055 public static function listPagesByPrefix( $prefix ) {
00056 $dbr = wfGetDB( DB_SLAVE );
00057
00058 $title = Title::newFromText( $prefix );
00059 if( $title ) {
00060 $ns = $title->getNamespace();
00061 $prefix = $title->getDBkey();
00062 } else {
00063
00064
00065 $ns = 0;
00066 }
00067 $conds = array(
00068 'ar_namespace' => $ns,
00069 'ar_title' . $dbr->buildLike( $prefix, $dbr->anyString() ),
00070 );
00071 return self::listPages( $dbr, $conds );
00072 }
00073
00074 protected static function listPages( $dbr, $condition ) {
00075 return $dbr->resultObject(
00076 $dbr->select(
00077 array( 'archive' ),
00078 array(
00079 'ar_namespace',
00080 'ar_title',
00081 'COUNT(*) AS count'
00082 ),
00083 $condition,
00084 __METHOD__,
00085 array(
00086 'GROUP BY' => 'ar_namespace,ar_title',
00087 'ORDER BY' => 'ar_namespace,ar_title',
00088 'LIMIT' => 100,
00089 )
00090 )
00091 );
00092 }
00093
00100 function listRevisions() {
00101 $dbr = wfGetDB( DB_SLAVE );
00102 $res = $dbr->select( 'archive',
00103 array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len', 'ar_deleted' ),
00104 array( 'ar_namespace' => $this->title->getNamespace(),
00105 'ar_title' => $this->title->getDBkey() ),
00106 'PageArchive::listRevisions',
00107 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
00108 $ret = $dbr->resultObject( $res );
00109 return $ret;
00110 }
00111
00120 function listFiles() {
00121 if( $this->title->getNamespace() == NS_FILE ) {
00122 $dbr = wfGetDB( DB_SLAVE );
00123 $res = $dbr->select( 'filearchive',
00124 array(
00125 'fa_id',
00126 'fa_name',
00127 'fa_archive_name',
00128 'fa_storage_key',
00129 'fa_storage_group',
00130 'fa_size',
00131 'fa_width',
00132 'fa_height',
00133 'fa_bits',
00134 'fa_metadata',
00135 'fa_media_type',
00136 'fa_major_mime',
00137 'fa_minor_mime',
00138 'fa_description',
00139 'fa_user',
00140 'fa_user_text',
00141 'fa_timestamp',
00142 'fa_deleted' ),
00143 array( 'fa_name' => $this->title->getDBkey() ),
00144 __METHOD__,
00145 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
00146 $ret = $dbr->resultObject( $res );
00147 return $ret;
00148 }
00149 return null;
00150 }
00151
00159 function getRevisionText( $timestamp ) {
00160 $rev = $this->getRevision( $timestamp );
00161 return $rev ? $rev->getText() : null;
00162 }
00163
00170 function getRevision( $timestamp ) {
00171 $dbr = wfGetDB( DB_SLAVE );
00172 $row = $dbr->selectRow( 'archive',
00173 array(
00174 'ar_rev_id',
00175 'ar_text',
00176 'ar_comment',
00177 'ar_user',
00178 'ar_user_text',
00179 'ar_timestamp',
00180 'ar_minor_edit',
00181 'ar_flags',
00182 'ar_text_id',
00183 'ar_deleted',
00184 'ar_len' ),
00185 array( 'ar_namespace' => $this->title->getNamespace(),
00186 'ar_title' => $this->title->getDBkey(),
00187 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
00188 __METHOD__ );
00189 if( $row ) {
00190 return Revision::newFromArchiveRow( $row, array( 'page' => $this->title->getArticleId() ) );
00191 } else {
00192 return null;
00193 }
00194 }
00195
00206 function getPreviousRevision( $timestamp ) {
00207 $dbr = wfGetDB( DB_SLAVE );
00208
00209
00210 $row = $dbr->selectRow( 'archive',
00211 'ar_timestamp',
00212 array( 'ar_namespace' => $this->title->getNamespace(),
00213 'ar_title' => $this->title->getDBkey(),
00214 'ar_timestamp < ' .
00215 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
00216 __METHOD__,
00217 array(
00218 'ORDER BY' => 'ar_timestamp DESC',
00219 'LIMIT' => 1 ) );
00220 $prevDeleted = $row ? wfTimestamp( TS_MW, $row->ar_timestamp ) : false;
00221
00222 $row = $dbr->selectRow( array( 'page', 'revision' ),
00223 array( 'rev_id', 'rev_timestamp' ),
00224 array(
00225 'page_namespace' => $this->title->getNamespace(),
00226 'page_title' => $this->title->getDBkey(),
00227 'page_id = rev_page',
00228 'rev_timestamp < ' .
00229 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
00230 __METHOD__,
00231 array(
00232 'ORDER BY' => 'rev_timestamp DESC',
00233 'LIMIT' => 1 ) );
00234 $prevLive = $row ? wfTimestamp( TS_MW, $row->rev_timestamp ) : false;
00235 $prevLiveId = $row ? intval( $row->rev_id ) : null;
00236
00237 if( $prevLive && $prevLive > $prevDeleted ) {
00238
00239 return Revision::newFromId( $prevLiveId );
00240 } elseif( $prevDeleted ) {
00241
00242 return $this->getRevision( $prevDeleted );
00243 } else {
00244
00245 return null;
00246 }
00247 }
00248
00252 function getTextFromRow( $row ) {
00253 if( is_null( $row->ar_text_id ) ) {
00254
00255
00256 return Revision::getRevisionText( $row, "ar_" );
00257 } else {
00258
00259 $dbr = wfGetDB( DB_SLAVE );
00260 $text = $dbr->selectRow( 'text',
00261 array( 'old_text', 'old_flags' ),
00262 array( 'old_id' => $row->ar_text_id ),
00263 __METHOD__ );
00264 return Revision::getRevisionText( $text );
00265 }
00266 }
00267
00268
00277 function getLastRevisionText() {
00278 $dbr = wfGetDB( DB_SLAVE );
00279 $row = $dbr->selectRow( 'archive',
00280 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
00281 array( 'ar_namespace' => $this->title->getNamespace(),
00282 'ar_title' => $this->title->getDBkey() ),
00283 'PageArchive::getLastRevisionText',
00284 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
00285 if( $row ) {
00286 return $this->getTextFromRow( $row );
00287 } else {
00288 return null;
00289 }
00290 }
00291
00296 function isDeleted() {
00297 $dbr = wfGetDB( DB_SLAVE );
00298 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
00299 array( 'ar_namespace' => $this->title->getNamespace(),
00300 'ar_title' => $this->title->getDBkey() ) );
00301 return ($n > 0);
00302 }
00303
00317 function undelete( $timestamps, $comment = '', $fileVersions = array(), $unsuppress = false ) {
00318
00319
00320 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
00321
00322 $restoreText = $restoreAll || !empty( $timestamps );
00323 $restoreFiles = $restoreAll || !empty( $fileVersions );
00324
00325 if( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
00326 $img = wfLocalFile( $this->title );
00327 $this->fileStatus = $img->restore( $fileVersions, $unsuppress );
00328 $filesRestored = $this->fileStatus->successCount;
00329 } else {
00330 $filesRestored = 0;
00331 }
00332
00333 if( $restoreText ) {
00334 $textRestored = $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
00335 if($textRestored === false)
00336 return false;
00337 } else {
00338 $textRestored = 0;
00339 }
00340
00341
00342 global $wgContLang;
00343 $log = new LogPage( 'delete' );
00344
00345 if( $textRestored && $filesRestored ) {
00346 $reason = wfMsgExt( 'undeletedrevisions-files', array( 'content', 'parsemag' ),
00347 $wgContLang->formatNum( $textRestored ),
00348 $wgContLang->formatNum( $filesRestored ) );
00349 } elseif( $textRestored ) {
00350 $reason = wfMsgExt( 'undeletedrevisions', array( 'content', 'parsemag' ),
00351 $wgContLang->formatNum( $textRestored ) );
00352 } elseif( $filesRestored ) {
00353 $reason = wfMsgExt( 'undeletedfiles', array( 'content', 'parsemag' ),
00354 $wgContLang->formatNum( $filesRestored ) );
00355 } else {
00356 wfDebug( "Undelete: nothing undeleted...\n" );
00357 return false;
00358 }
00359
00360 if( trim( $comment ) != '' )
00361 $reason .= wfMsgForContent( 'colon-separator' ) . $comment;
00362 $log->addEntry( 'restore', $this->title, $reason );
00363
00364 return array($textRestored, $filesRestored, $reason);
00365 }
00366
00379 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
00380 if ( wfReadOnly() )
00381 return false;
00382 $restoreAll = empty( $timestamps );
00383
00384 $dbw = wfGetDB( DB_MASTER );
00385
00386 # Does this page already exist? We'll have to update it...
00387 $article = new Article( $this->title );
00388 $options = 'FOR UPDATE';
00389 $page = $dbw->selectRow( 'page',
00390 array( 'page_id', 'page_latest' ),
00391 array( 'page_namespace' => $this->title->getNamespace(),
00392 'page_title' => $this->title->getDBkey() ),
00393 __METHOD__,
00394 $options
00395 );
00396 if( $page ) {
00397 $makepage = false;
00398 # Page already exists. Import the history, and if necessary
00399 # we'll update the latest revision field in the record.
00400 $newid = 0;
00401 $pageId = $page->page_id;
00402 $previousRevId = $page->page_latest;
00403 # Get the time span of this page
00404 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
00405 array( 'rev_id' => $previousRevId ),
00406 __METHOD__ );
00407 if( $previousTimestamp === false ) {
00408 wfDebug( __METHOD__.": existing page refers to a page_latest that does not exist\n" );
00409 return 0;
00410 }
00411 } else {
00412 # Have to create a new article...
00413 $makepage = true;
00414 $previousRevId = 0;
00415 $previousTimestamp = 0;
00416 }
00417
00418 if( $restoreAll ) {
00419 $oldones = '1 = 1'; # All revisions...
00420 } else {
00421 $oldts = implode( ',',
00422 array_map( array( &$dbw, 'addQuotes' ),
00423 array_map( array( &$dbw, 'timestamp' ),
00424 $timestamps ) ) );
00425
00426 $oldones = "ar_timestamp IN ( {$oldts} )";
00427 }
00428
00432 $result = $dbw->select( 'archive',
00433 array(
00434 'ar_rev_id',
00435 'ar_text',
00436 'ar_comment',
00437 'ar_user',
00438 'ar_user_text',
00439 'ar_timestamp',
00440 'ar_minor_edit',
00441 'ar_flags',
00442 'ar_text_id',
00443 'ar_deleted',
00444 'ar_page_id',
00445 'ar_len' ),
00446 array(
00447 'ar_namespace' => $this->title->getNamespace(),
00448 'ar_title' => $this->title->getDBkey(),
00449 $oldones ),
00450 __METHOD__,
00451 array( 'ORDER BY' => 'ar_timestamp' )
00452 );
00453 $ret = $dbw->resultObject( $result );
00454 $rev_count = $dbw->numRows( $result );
00455 if( !$rev_count ) {
00456 wfDebug( __METHOD__.": no revisions to restore\n" );
00457 return false;
00458 }
00459
00460 $ret->seek( $rev_count - 1 );
00461 $row = $ret->fetchObject();
00462 $ret->seek( 0 );
00463
00464 if( $makepage ) {
00465
00466 if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
00467 return false;
00468 }
00469
00470 $newid = $article->insertOn( $dbw );
00471 $pageId = $newid;
00472 } else {
00473
00474 if( $row->ar_timestamp > $previousTimestamp ) {
00475
00476 if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
00477 return false;
00478 }
00479 }
00480 }
00481
00482 $revision = null;
00483 $restored = 0;
00484
00485 while( $row = $ret->fetchObject() ) {
00486
00487 if( $row->ar_rev_id ) {
00488 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
00489 if( $exists ) continue;
00490 }
00491
00492
00493 $revision = Revision::newFromArchiveRow( $row,
00494 array(
00495 'page' => $pageId,
00496 'deleted' => $unsuppress ? 0 : $row->ar_deleted
00497 ) );
00498
00499 $revision->insertOn( $dbw );
00500 $restored++;
00501
00502 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
00503 }
00504 # Now that it's safely stored, take it out of the archive
00505 $dbw->delete( 'archive',
00506 array(
00507 'ar_namespace' => $this->title->getNamespace(),
00508 'ar_title' => $this->title->getDBkey(),
00509 $oldones ),
00510 __METHOD__ );
00511
00512
00513 if( $restored == 0 )
00514 return 0;
00515
00516 if( $revision ) {
00517
00518 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
00519 if( $newid || $wasnew ) {
00520
00521 $article->createUpdates( $revision );
00522 }
00523
00524 if( $newid ) {
00525 wfRunHooks( 'ArticleUndelete', array( &$this->title, true, $comment ) );
00526 Article::onArticleCreate( $this->title );
00527 } else {
00528 wfRunHooks( 'ArticleUndelete', array( &$this->title, false, $comment ) );
00529 Article::onArticleEdit( $this->title );
00530 }
00531
00532 if( $this->title->getNamespace() == NS_FILE ) {
00533 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
00534 $update->doUpdate();
00535 }
00536 } else {
00537
00538 return self::UNDELETE_UNKNOWNERR;
00539 }
00540
00541 return $restored;
00542 }
00543
00544 function getFileStatus() { return $this->fileStatus; }
00545 }
00546
00552 class UndeleteForm {
00553 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
00554 var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken;
00555
00556 function UndeleteForm( $request, $par = "" ) {
00557 global $wgUser;
00558 $this->mAction = $request->getVal( 'action' );
00559 $this->mTarget = $request->getVal( 'target' );
00560 $this->mSearchPrefix = $request->getText( 'prefix' );
00561 $time = $request->getVal( 'timestamp' );
00562 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
00563 $this->mFile = $request->getVal( 'file' );
00564
00565 $posted = $request->wasPosted() &&
00566 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
00567 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
00568 $this->mInvert = $request->getCheck( 'invert' ) && $posted;
00569 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
00570 $this->mDiff = $request->getCheck( 'diff' );
00571 $this->mComment = $request->getText( 'wpComment' );
00572 $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
00573 $this->mToken = $request->getVal( 'token' );
00574
00575 if( $par != "" ) {
00576 $this->mTarget = $par;
00577 }
00578 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
00579 $this->mAllowed = true;
00580 $this->mCanView = true;
00581 } elseif ( $wgUser->isAllowed( 'deletedtext' ) ) {
00582 $this->mAllowed = false;
00583 $this->mCanView = true;
00584 } else {
00585 $this->mAllowed = false;
00586 $this->mCanView = false;
00587 $this->mTimestamp = '';
00588 $this->mRestore = false;
00589 }
00590 if ( $this->mTarget !== "" ) {
00591 $this->mTargetObj = Title::newFromURL( $this->mTarget );
00592 } else {
00593 $this->mTargetObj = null;
00594 }
00595 if( $this->mRestore || $this->mInvert ) {
00596 $timestamps = array();
00597 $this->mFileVersions = array();
00598 foreach( $_REQUEST as $key => $val ) {
00599 $matches = array();
00600 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
00601 array_push( $timestamps, $matches[1] );
00602 }
00603
00604 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
00605 $this->mFileVersions[] = intval( $matches[1] );
00606 }
00607 }
00608 rsort( $timestamps );
00609 $this->mTargetTimestamp = $timestamps;
00610 }
00611 }
00612
00613 function execute() {
00614 global $wgOut, $wgUser;
00615 if ( $this->mAllowed ) {
00616 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
00617 } else {
00618 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
00619 }
00620
00621 if( is_null( $this->mTargetObj ) ) {
00622 # Not all users can just browse every deleted page from the list
00623 if( $wgUser->isAllowed( 'browsearchive' ) ) {
00624 $this->showSearchForm();
00625
00626 # List undeletable articles
00627 if( $this->mSearchPrefix ) {
00628 $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
00629 $this->showList( $result );
00630 }
00631 } else {
00632 $wgOut->addWikiMsg( 'undelete-header' );
00633 }
00634 return;
00635 }
00636 if( $this->mTimestamp !== '' ) {
00637 return $this->showRevision( $this->mTimestamp );
00638 }
00639 if( $this->mFile !== null ) {
00640 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
00641
00642 if ( !$file->exists() ) {
00643 $wgOut->addWikiMsg( 'filedelete-nofile', $this->mFile );
00644 return;
00645 } else if( !$file->userCan( File::DELETED_FILE ) ) {
00646 if( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
00647 $wgOut->permissionRequired( 'suppressrevision' );
00648 } else {
00649 $wgOut->permissionRequired( 'deletedtext' );
00650 }
00651 return false;
00652 } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
00653 $this->showFileConfirmationForm( $this->mFile );
00654 return false;
00655 } else {
00656 return $this->showFile( $this->mFile );
00657 }
00658 }
00659 if( $this->mRestore && $this->mAction == "submit" ) {
00660 global $wgUploadMaintenance;
00661 if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
00662 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n", array( 'filedelete-maintenance' ) );
00663 return;
00664 }
00665 return $this->undelete();
00666 }
00667 if( $this->mInvert && $this->mAction == "submit" ) {
00668 return $this->showHistory( );
00669 }
00670 return $this->showHistory();
00671 }
00672
00673 function showSearchForm() {
00674 global $wgOut, $wgScript;
00675 $wgOut->addWikiMsg( 'undelete-header' );
00676
00677 $wgOut->addHTML(
00678 Xml::openElement( 'form', array(
00679 'method' => 'get',
00680 'action' => $wgScript ) ) .
00681 Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
00682 Xml::hidden( 'title',
00683 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
00684 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
00685 'prefix', 'prefix', 20,
00686 $this->mSearchPrefix ) . ' ' .
00687 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
00688 Xml::closeElement( 'fieldset' ) .
00689 Xml::closeElement( 'form' )
00690 );
00691 }
00692
00693
00694 private function showList( $result ) {
00695 global $wgLang, $wgContLang, $wgUser, $wgOut;
00696
00697 if( $result->numRows() == 0 ) {
00698 $wgOut->addWikiMsg( 'undelete-no-results' );
00699 return;
00700 }
00701
00702 $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
00703
00704 $sk = $wgUser->getSkin();
00705 $undelete = SpecialPage::getTitleFor( 'Undelete' );
00706 $wgOut->addHTML( "<ul>\n" );
00707 while( $row = $result->fetchObject() ) {
00708 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
00709 $link = $sk->linkKnown(
00710 $undelete,
00711 htmlspecialchars( $title->getPrefixedText() ),
00712 array(),
00713 array( 'target' => $title->getPrefixedText() )
00714 );
00715 $revs = wfMsgExt( 'undeleterevisions',
00716 array( 'parseinline' ),
00717 $wgLang->formatNum( $row->count ) );
00718 $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
00719 }
00720 $result->free();
00721 $wgOut->addHTML( "</ul>\n" );
00722
00723 return true;
00724 }
00725
00726 private function showRevision( $timestamp ) {
00727 global $wgLang, $wgUser, $wgOut;
00728 $self = SpecialPage::getTitleFor( 'Undelete' );
00729 $skin = $wgUser->getSkin();
00730
00731 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
00732
00733 $archive = new PageArchive( $this->mTargetObj );
00734 $rev = $archive->getRevision( $timestamp );
00735
00736 if( !$rev ) {
00737 $wgOut->addWikiMsg( 'undeleterevision-missing' );
00738 return;
00739 }
00740
00741 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
00742 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
00743 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
00744 return;
00745 } else {
00746 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
00747 $wgOut->addHTML( '<br />' );
00748
00749 }
00750 }
00751
00752 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
00753
00754 $link = $skin->linkKnown(
00755 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
00756 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
00757 );
00758
00759 if( $this->mDiff ) {
00760 $previousRev = $archive->getPreviousRevision( $timestamp );
00761 if( $previousRev ) {
00762 $this->showDiff( $previousRev, $rev );
00763 if( $wgUser->getOption( 'diffonly' ) ) {
00764 return;
00765 } else {
00766 $wgOut->addHTML( '<hr />' );
00767 }
00768 } else {
00769 $wgOut->addWikiMsg( 'undelete-nodiff' );
00770 }
00771 }
00772
00773
00774
00775 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
00776 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
00777 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
00778 $user = $skin->revUserTools( $rev );
00779
00780 if( $this->mPreview ) {
00781 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
00782 } else {
00783 $openDiv = '<div id="mw-undelete-revision">';
00784 }
00785
00786
00787 $canHide = $wgUser->isAllowed( 'deleterevision' );
00788 if( $this->mDiff ) {
00789 $revdlink = '';
00790 } else if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
00791 if( !$rev->userCan(Revision::DELETED_RESTRICTED ) ) {
00792 $revdlink = $skin->revDeleteLinkDisabled( $canHide );
00793 } else {
00794 $query = array(
00795 'type' => 'archive',
00796 'target' => $this->mTargetObj->getPrefixedDBkey(),
00797 'ids' => $rev->getTimestamp()
00798 );
00799 $revdlink = $skin->revDeleteLink( $query,
00800 $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
00801 }
00802 } else {
00803 $revdlink = '';
00804 }
00805
00806 $wgOut->addHTML( $openDiv . $revdlink . wfMsgWikiHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</div>' );
00807 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
00808
00809 if( $this->mPreview ) {
00810
00811 $popts = $wgOut->parserOptions();
00812 $popts->setEditSection( false );
00813 $wgOut->parserOptions( $popts );
00814 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
00815 }
00816
00817 $wgOut->addHTML(
00818 Xml::element( 'textarea', array(
00819 'readonly' => 'readonly',
00820 'cols' => intval( $wgUser->getOption( 'cols' ) ),
00821 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
00822 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
00823 Xml::openElement( 'div' ) .
00824 Xml::openElement( 'form', array(
00825 'method' => 'post',
00826 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
00827 Xml::element( 'input', array(
00828 'type' => 'hidden',
00829 'name' => 'target',
00830 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
00831 Xml::element( 'input', array(
00832 'type' => 'hidden',
00833 'name' => 'timestamp',
00834 'value' => $timestamp ) ) .
00835 Xml::element( 'input', array(
00836 'type' => 'hidden',
00837 'name' => 'wpEditToken',
00838 'value' => $wgUser->editToken() ) ) .
00839 Xml::element( 'input', array(
00840 'type' => 'submit',
00841 'name' => 'preview',
00842 'value' => wfMsg( 'showpreview' ) ) ) .
00843 Xml::element( 'input', array(
00844 'name' => 'diff',
00845 'type' => 'submit',
00846 'value' => wfMsg( 'showdiff' ) ) ) .
00847 Xml::closeElement( 'form' ) .
00848 Xml::closeElement( 'div' ) );
00849 }
00850
00858 function showDiff( $previousRev, $currentRev ) {
00859 global $wgOut;
00860
00861 $diffEngine = new DifferenceEngine();
00862 $diffEngine->showDiffStyle();
00863 $wgOut->addHTML(
00864 "<div>" .
00865 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
00866 "<col class='diff-marker' />" .
00867 "<col class='diff-content' />" .
00868 "<col class='diff-marker' />" .
00869 "<col class='diff-content' />" .
00870 "<tr>" .
00871 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
00872 $this->diffHeader( $previousRev, 'o' ) .
00873 "</td>\n" .
00874 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
00875 $this->diffHeader( $currentRev, 'n' ) .
00876 "</td>\n" .
00877 "</tr>" .
00878 $diffEngine->generateDiffBody(
00879 $previousRev->getText(), $currentRev->getText() ) .
00880 "</table>" .
00881 "</div>\n"
00882 );
00883 }
00884
00885 private function diffHeader( $rev, $prefix ) {
00886 global $wgUser, $wgLang;
00887 $sk = $wgUser->getSkin();
00888 $isDeleted = !( $rev->getId() && $rev->getTitle() );
00889 if( $isDeleted ) {
00891 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
00892 $targetQuery = array(
00893 'target' => $this->mTargetObj->getPrefixedText(),
00894 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
00895 );
00896 } else {
00898 $targetPage = $rev->getTitle();
00899 $targetQuery = array( 'oldid' => $rev->getId() );
00900 }
00901
00902 $canHide = $wgUser->isAllowed( 'deleterevision' );
00903 if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
00904 $del = ' ';
00905 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
00906 $del .= $sk->revDeleteLinkDisabled( $canHide );
00907 } else {
00908 $query = array(
00909 'type' => 'archive',
00910 'target' => $this->mTargetObj->getPrefixedDbkey(),
00911 'ids' => $rev->getTimestamp()
00912 );
00913 $del .= $sk->revDeleteLink( $query,
00914 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
00915 }
00916 } else {
00917 $del = '';
00918 }
00919 return
00920 '<div id="mw-diff-'.$prefix.'title1"><strong>' .
00921 $sk->link(
00922 $targetPage,
00923 wfMsgHtml(
00924 'revisionasof',
00925 htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
00926 htmlspecialchars( $wgLang->date( $rev->getTimestamp(), true ) ),
00927 htmlspecialchars( $wgLang->time( $rev->getTimestamp(), true ) )
00928 ),
00929 array(),
00930 $targetQuery
00931 ) .
00932 '</strong></div>' .
00933 '<div id="mw-diff-'.$prefix.'title2">' .
00934 $sk->revUserTools( $rev ) . '<br />' .
00935 '</div>' .
00936 '<div id="mw-diff-'.$prefix.'title3">' .
00937 $sk->revComment( $rev ) . $del . '<br />' .
00938 '</div>';
00939 }
00940
00944 private function showFileConfirmationForm( $key ) {
00945 global $wgOut, $wgUser, $wgLang;
00946 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
00947 $wgOut->addWikiMsg( 'undelete-show-file-confirm',
00948 $this->mTargetObj->getText(),
00949 $wgLang->date( $file->getTimestamp() ),
00950 $wgLang->time( $file->getTimestamp() ) );
00951 $wgOut->addHTML(
00952 Xml::openElement( 'form', array(
00953 'method' => 'POST',
00954 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
00955 'target=' . urlencode( $this->mTarget ) .
00956 '&file=' . urlencode( $key ) .
00957 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
00958 )
00959 ) .
00960 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
00961 '</form>'
00962 );
00963 }
00964
00968 private function showFile( $key ) {
00969 global $wgOut, $wgRequest;
00970 $wgOut->disable();
00971
00972 # We mustn't allow the output to be Squid cached, otherwise
00973 # if an admin previews a deleted image, and it's cached, then
00974 # a user without appropriate permissions can toddle off and
00975 # nab the image, and Squid will serve it
00976 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
00977 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
00978 $wgRequest->response()->header( 'Pragma: no-cache' );
00979
00980 global $IP;
00981 require_once( "$IP/includes/StreamFile.php" );
00982 $repo = RepoGroup::singleton()->getLocalRepo();
00983 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
00984 wfStreamFile( $path );
00985 }
00986
00987 private function showHistory( ) {
00988 global $wgLang, $wgUser, $wgOut;
00989
00990 $sk = $wgUser->getSkin();
00991 if( $this->mAllowed ) {
00992 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
00993 } else {
00994 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
00995 }
00996
00997 $wgOut->wrapWikiMsg( "<div class='mw-undelete-pagetitle'>\n$1</div>\n", array ( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() ) );
00998
00999 $archive = new PageArchive( $this->mTargetObj );
01000
01001
01002
01003
01004
01005
01006
01007 $wgOut->addHTML( '<div class="mw-undelete-history">' );
01008 if ( $this->mAllowed ) {
01009 $wgOut->addWikiMsg( "undeletehistory" );
01010 $wgOut->addWikiMsg( "undeleterevdel" );
01011 } else {
01012 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
01013 }
01014 $wgOut->addHTML( '</div>' );
01015
01016 # List all stored revisions
01017 $revisions = $archive->listRevisions();
01018 $files = $archive->listFiles();
01019
01020 $haveRevisions = $revisions && $revisions->numRows() > 0;
01021 $haveFiles = $files && $files->numRows() > 0;
01022
01023 # Batch existence check on user and talk pages
01024 if( $haveRevisions ) {
01025 $batch = new LinkBatch();
01026 while( $row = $revisions->fetchObject() ) {
01027 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
01028 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
01029 }
01030 $batch->execute();
01031 $revisions->seek( 0 );
01032 }
01033 if( $haveFiles ) {
01034 $batch = new LinkBatch();
01035 while( $row = $files->fetchObject() ) {
01036 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
01037 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
01038 }
01039 $batch->execute();
01040 $files->seek( 0 );
01041 }
01042
01043 if ( $this->mAllowed ) {
01044 $titleObj = SpecialPage::getTitleFor( "Undelete" );
01045 $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
01046 # Start the form here
01047 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
01048 $wgOut->addHTML( $top );
01049 }
01050
01051 # Show relevant lines from the deletion log:
01052 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
01053 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
01054 # Show relevant lines from the suppression log:
01055 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
01056 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
01057 LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
01058 }
01059
01060 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
01061 # Format the user-visible controls (comment field, submission button)
01062 # in a nice little table
01063 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
01064 $unsuppressBox =
01065 "<tr>
01066 <td> </td>
01067 <td class='mw-input'>" .
01068 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
01069 'mw-undelete-unsuppress', $this->mUnsuppress ).
01070 "</td>
01071 </tr>";
01072 } else {
01073 $unsuppressBox = "";
01074 }
01075 $table =
01076 Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
01077 Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
01078 "<tr>
01079 <td colspan='2' class='mw-undelete-extrahelp'>" .
01080 wfMsgWikiHtml( 'undeleteextrahelp' ) .
01081 "</td>
01082 </tr>
01083 <tr>
01084 <td class='mw-label'>" .
01085 Xml::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
01086 "</td>
01087 <td class='mw-input'>" .
01088 Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
01089 "</td>
01090 </tr>
01091 <tr>
01092 <td> </td>
01093 <td class='mw-submit'>" .
01094 Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
01095 Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) . ' ' .
01096 Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
01097 "</td>
01098 </tr>" .
01099 $unsuppressBox .
01100 Xml::closeElement( 'table' ) .
01101 Xml::closeElement( 'fieldset' );
01102
01103 $wgOut->addHTML( $table );
01104 }
01105
01106 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
01107
01108 if( $haveRevisions ) {
01109 # The page's stored (deleted) history:
01110 $wgOut->addHTML("<ul>");
01111 $target = urlencode( $this->mTarget );
01112 $remaining = $revisions->numRows();
01113 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
01114
01115 while( $row = $revisions->fetchObject() ) {
01116 $remaining--;
01117 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
01118 }
01119 $revisions->free();
01120 $wgOut->addHTML("</ul>");
01121 } else {
01122 $wgOut->addWikiMsg( "nohistory" );
01123 }
01124
01125 if( $haveFiles ) {
01126 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
01127 $wgOut->addHTML( "<ul>" );
01128 while( $row = $files->fetchObject() ) {
01129 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
01130 }
01131 $files->free();
01132 $wgOut->addHTML( "</ul>" );
01133 }
01134
01135 if ( $this->mAllowed ) {
01136 # Slip in the hidden controls here
01137 $misc = Xml::hidden( 'target', $this->mTarget );
01138 $misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
01139 $misc .= Xml::closeElement( 'form' );
01140 $wgOut->addHTML( $misc );
01141 }
01142
01143 return true;
01144 }
01145
01146 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
01147 global $wgUser, $wgLang;
01148
01149 $rev = Revision::newFromArchiveRow( $row,
01150 array( 'page' => $this->mTargetObj->getArticleId() ) );
01151 $stxt = '';
01152 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
01153
01154 if( $this->mAllowed ) {
01155 if( $this->mInvert ) {
01156 if( in_array( $ts, $this->mTargetTimestamp ) ) {
01157 $checkBox = Xml::check( "ts$ts");
01158 } else {
01159 $checkBox = Xml::check( "ts$ts", true );
01160 }
01161 } else {
01162 $checkBox = Xml::check( "ts$ts" );
01163 }
01164 } else {
01165 $checkBox = '';
01166 }
01167
01168 if( $this->mCanView ) {
01169 $titleObj = SpecialPage::getTitleFor( "Undelete" );
01170 # Last link
01171 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
01172 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
01173 $last = wfMsgHtml('diff');
01174 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
01175 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
01176 $last = $sk->linkKnown(
01177 $titleObj,
01178 wfMsgHtml('diff'),
01179 array(),
01180 array(
01181 'target' => $this->mTargetObj->getPrefixedText(),
01182 'timestamp' => $ts,
01183 'diff' => 'prev'
01184 )
01185 );
01186 } else {
01187 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
01188 $last = wfMsgHtml('diff');
01189 }
01190 } else {
01191 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
01192 $last = wfMsgHtml('diff');
01193 }
01194
01195 $userLink = $sk->revUserTools( $rev );
01196
01197 if( !is_null($size = $row->ar_len) ) {
01198 $stxt = $sk->formatRevisionSize( $size );
01199 }
01200
01201 $comment = $sk->revComment( $rev );
01202
01203 $canHide = $wgUser->isAllowed( 'deleterevision' );
01204 if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
01205 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
01206 $revdlink = $sk->revDeleteLinkDisabled( $canHide );
01207 } else {
01208 $query = array(
01209 'type' => 'archive',
01210 'target' => $this->mTargetObj->getPrefixedDBkey(),
01211 'ids' => $ts
01212 );
01213 $revdlink = $sk->revDeleteLink( $query,
01214 $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
01215 }
01216 } else {
01217 $revdlink = '';
01218 }
01219 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
01220 }
01221
01222 private function formatFileRow( $row, $sk ) {
01223 global $wgUser, $wgLang;
01224
01225 $file = ArchivedFile::newFromRow( $row );
01226
01227 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
01228 if( $this->mAllowed && $row->fa_storage_key ) {
01229 $checkBox = Xml::check( "fileid" . $row->fa_id );
01230 $key = urlencode( $row->fa_storage_key );
01231 $target = urlencode( $this->mTarget );
01232 $titleObj = SpecialPage::getTitleFor( "Undelete" );
01233 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
01234 } else {
01235 $checkBox = '';
01236 $pageLink = $wgLang->timeanddate( $ts, true );
01237 }
01238 $userLink = $this->getFileUser( $file, $sk );
01239 $data =
01240 wfMsg( 'widthheight',
01241 $wgLang->formatNum( $row->fa_width ),
01242 $wgLang->formatNum( $row->fa_height ) ) .
01243 ' (' .
01244 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
01245 ')';
01246 $data = htmlspecialchars( $data );
01247 $comment = $this->getFileComment( $file, $sk );
01248
01249 $canHide = $wgUser->isAllowed( 'deleterevision' );
01250 if( $canHide || ($file->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
01251 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
01252 $revdlink = $sk->revDeleteLinkDisabled( $canHide );
01253 } else {
01254 $query = array(
01255 'type' => 'filearchive',
01256 'target' => $this->mTargetObj->getPrefixedDBkey(),
01257 'ids' => $row->fa_id
01258 );
01259 $revdlink = $sk->revDeleteLink( $query,
01260 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
01261 }
01262 } else {
01263 $revdlink = '';
01264 }
01265 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
01266 }
01267
01272 function getPageLink( $rev, $titleObj, $ts, $sk ) {
01273 global $wgLang;
01274
01275 $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
01276
01277 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
01278 return '<span class="history-deleted">' . $time . '</span>';
01279 } else {
01280 $link = $sk->linkKnown(
01281 $titleObj,
01282 $time,
01283 array(),
01284 array(
01285 'target' => $this->mTargetObj->getPrefixedText(),
01286 'timestamp' => $ts
01287 )
01288 );
01289 if( $rev->isDeleted(Revision::DELETED_TEXT) )
01290 $link = '<span class="history-deleted">' . $link . '</span>';
01291 return $link;
01292 }
01293 }
01294
01299 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
01300 global $wgLang, $wgUser;
01301
01302 if( !$file->userCan(File::DELETED_FILE) ) {
01303 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
01304 } else {
01305 $link = $sk->linkKnown(
01306 $titleObj,
01307 $wgLang->timeanddate( $ts, true ),
01308 array(),
01309 array(
01310 'target' => $this->mTargetObj->getPrefixedText(),
01311 'file' => $key,
01312 'token' => $wgUser->editToken( $key )
01313 )
01314 );
01315 if( $file->isDeleted(File::DELETED_FILE) )
01316 $link = '<span class="history-deleted">' . $link . '</span>';
01317 return $link;
01318 }
01319 }
01320
01325 function getFileUser( $file, $sk ) {
01326 if( !$file->userCan(File::DELETED_USER) ) {
01327 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
01328 } else {
01329 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
01330 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
01331 if( $file->isDeleted(File::DELETED_USER) )
01332 $link = '<span class="history-deleted">' . $link . '</span>';
01333 return $link;
01334 }
01335 }
01336
01341 function getFileComment( $file, $sk ) {
01342 if( !$file->userCan(File::DELETED_COMMENT) ) {
01343 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
01344 } else {
01345 $link = $sk->commentBlock( $file->getRawDescription() );
01346 if( $file->isDeleted(File::DELETED_COMMENT) )
01347 $link = '<span class="history-deleted">' . $link . '</span>';
01348 return $link;
01349 }
01350 }
01351
01352 function undelete() {
01353 global $wgOut, $wgUser;
01354 if ( wfReadOnly() ) {
01355 $wgOut->readOnlyPage();
01356 return;
01357 }
01358 if( !is_null( $this->mTargetObj ) ) {
01359 $archive = new PageArchive( $this->mTargetObj );
01360 $ok = $archive->undelete(
01361 $this->mTargetTimestamp,
01362 $this->mComment,
01363 $this->mFileVersions,
01364 $this->mUnsuppress );
01365
01366 if( is_array($ok) ) {
01367 if ( $ok[1] )
01368 wfRunHooks( 'FileUndeleteComplete', array(
01369 $this->mTargetObj, $this->mFileVersions,
01370 $wgUser, $this->mComment) );
01371
01372 $skin = $wgUser->getSkin();
01373 $link = $skin->linkKnown( $this->mTargetObj );
01374 $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
01375 } else {
01376 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
01377 $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
01378 }
01379
01380
01381 $status = $archive->getFileStatus();
01382 if( $status && !$status->isGood() ) {
01383 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
01384 }
01385 } else {
01386 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
01387 }
01388 return false;
01389 }
01390 }