Localisation updates for core messages from translatewiki.net
[mediawiki.git] / includes / specials / SpecialUndelete.php
blob3ba7613f42dddd8bfd4082b609fc854653e7605d
1 <?php
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and restore deleted content
7 * @file
8 * @ingroup SpecialPage
9 */
11 /**
12 * Constructor
14 function wfSpecialUndelete( $par ) {
15 global $wgRequest;
17 $form = new UndeleteForm( $wgRequest, $par );
18 $form->execute();
21 /**
22 * Used to show archived pages and eventually restore them.
23 * @ingroup SpecialPage
25 class PageArchive {
26 protected $title;
27 var $fileStatus;
29 function __construct( $title ) {
30 if( is_null( $title ) ) {
31 throw new MWException( 'Archiver() given a null title.');
33 $this->title = $title;
36 /**
37 * List all deleted pages recorded in the archive table. Returns result
38 * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
39 * namespace/title.
41 * @return ResultWrapper
43 public static function listAllPages() {
44 $dbr = wfGetDB( DB_SLAVE );
45 return self::listPages( $dbr, '' );
48 /**
49 * List deleted pages recorded in the archive table matching the
50 * given title prefix.
51 * Returns result wrapper with (ar_namespace, ar_title, count) fields.
53 * @return ResultWrapper
55 public static function listPagesByPrefix( $prefix ) {
56 $dbr = wfGetDB( DB_SLAVE );
58 $title = Title::newFromText( $prefix );
59 if( $title ) {
60 $ns = $title->getNamespace();
61 $encPrefix = $dbr->escapeLike( $title->getDBkey() );
62 } else {
63 // Prolly won't work too good
64 // @todo handle bare namespace names cleanly?
65 $ns = 0;
66 $encPrefix = $dbr->escapeLike( $prefix );
68 $conds = array(
69 'ar_namespace' => $ns,
70 "ar_title LIKE '$encPrefix%'",
72 return self::listPages( $dbr, $conds );
75 protected static function listPages( $dbr, $condition ) {
76 return $dbr->resultObject(
77 $dbr->select(
78 array( 'archive' ),
79 array(
80 'ar_namespace',
81 'ar_title',
82 'COUNT(*) AS count'
84 $condition,
85 __METHOD__,
86 array(
87 'GROUP BY' => 'ar_namespace,ar_title',
88 'ORDER BY' => 'ar_namespace,ar_title',
89 'LIMIT' => 100,
95 /**
96 * List the revisions of the given page. Returns result wrapper with
97 * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
99 * @return ResultWrapper
101 function listRevisions() {
102 $dbr = wfGetDB( DB_SLAVE );
103 $res = $dbr->select( 'archive',
104 array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len', 'ar_deleted' ),
105 array( 'ar_namespace' => $this->title->getNamespace(),
106 'ar_title' => $this->title->getDBkey() ),
107 'PageArchive::listRevisions',
108 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
109 $ret = $dbr->resultObject( $res );
110 return $ret;
114 * List the deleted file revisions for this page, if it's a file page.
115 * Returns a result wrapper with various filearchive fields, or null
116 * if not a file page.
118 * @return ResultWrapper
119 * @todo Does this belong in Image for fuller encapsulation?
121 function listFiles() {
122 if( $this->title->getNamespace() == NS_FILE ) {
123 $dbr = wfGetDB( DB_SLAVE );
124 $res = $dbr->select( 'filearchive',
125 array(
126 'fa_id',
127 'fa_name',
128 'fa_archive_name',
129 'fa_storage_key',
130 'fa_storage_group',
131 'fa_size',
132 'fa_width',
133 'fa_height',
134 'fa_bits',
135 'fa_metadata',
136 'fa_media_type',
137 'fa_major_mime',
138 'fa_minor_mime',
139 'fa_description',
140 'fa_user',
141 'fa_user_text',
142 'fa_timestamp',
143 'fa_deleted' ),
144 array( 'fa_name' => $this->title->getDBkey() ),
145 __METHOD__,
146 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
147 $ret = $dbr->resultObject( $res );
148 return $ret;
150 return null;
154 * Fetch (and decompress if necessary) the stored text for the deleted
155 * revision of the page with the given timestamp.
157 * @return string
158 * @deprecated Use getRevision() for more flexible information
160 function getRevisionText( $timestamp ) {
161 $rev = $this->getRevision( $timestamp );
162 return $rev ? $rev->getText() : null;
166 * Return a Revision object containing data for the deleted revision.
167 * Note that the result *may* or *may not* have a null page ID.
168 * @param string $timestamp
169 * @return Revision
171 function getRevision( $timestamp ) {
172 $dbr = wfGetDB( DB_SLAVE );
173 $row = $dbr->selectRow( 'archive',
174 array(
175 'ar_rev_id',
176 'ar_text',
177 'ar_comment',
178 'ar_user',
179 'ar_user_text',
180 'ar_timestamp',
181 'ar_minor_edit',
182 'ar_flags',
183 'ar_text_id',
184 'ar_deleted',
185 'ar_len' ),
186 array( 'ar_namespace' => $this->title->getNamespace(),
187 'ar_title' => $this->title->getDBkey(),
188 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
189 __METHOD__ );
190 if( $row ) {
191 return Revision::newFromArchiveRow( $row, array( 'page' => $this->title->getArticleId() ) );
192 } else {
193 return null;
198 * Return the most-previous revision, either live or deleted, against
199 * the deleted revision given by timestamp.
201 * May produce unexpected results in case of history merges or other
202 * unusual time issues.
204 * @param string $timestamp
205 * @return Revision or null
207 function getPreviousRevision( $timestamp ) {
208 $dbr = wfGetDB( DB_SLAVE );
210 // Check the previous deleted revision...
211 $row = $dbr->selectRow( 'archive',
212 'ar_timestamp',
213 array( 'ar_namespace' => $this->title->getNamespace(),
214 'ar_title' => $this->title->getDBkey(),
215 'ar_timestamp < ' .
216 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
217 __METHOD__,
218 array(
219 'ORDER BY' => 'ar_timestamp DESC',
220 'LIMIT' => 1 ) );
221 $prevDeleted = $row ? wfTimestamp( TS_MW, $row->ar_timestamp ) : false;
223 $row = $dbr->selectRow( array( 'page', 'revision' ),
224 array( 'rev_id', 'rev_timestamp' ),
225 array(
226 'page_namespace' => $this->title->getNamespace(),
227 'page_title' => $this->title->getDBkey(),
228 'page_id = rev_page',
229 'rev_timestamp < ' .
230 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
231 __METHOD__,
232 array(
233 'ORDER BY' => 'rev_timestamp DESC',
234 'LIMIT' => 1 ) );
235 $prevLive = $row ? wfTimestamp( TS_MW, $row->rev_timestamp ) : false;
236 $prevLiveId = $row ? intval( $row->rev_id ) : null;
238 if( $prevLive && $prevLive > $prevDeleted ) {
239 // Most prior revision was live
240 return Revision::newFromId( $prevLiveId );
241 } elseif( $prevDeleted ) {
242 // Most prior revision was deleted
243 return $this->getRevision( $prevDeleted );
244 } else {
245 // No prior revision on this page.
246 return null;
251 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
253 function getTextFromRow( $row ) {
254 if( is_null( $row->ar_text_id ) ) {
255 // An old row from MediaWiki 1.4 or previous.
256 // Text is embedded in this row in classic compression format.
257 return Revision::getRevisionText( $row, "ar_" );
258 } else {
259 // New-style: keyed to the text storage backend.
260 $dbr = wfGetDB( DB_SLAVE );
261 $text = $dbr->selectRow( 'text',
262 array( 'old_text', 'old_flags' ),
263 array( 'old_id' => $row->ar_text_id ),
264 __METHOD__ );
265 return Revision::getRevisionText( $text );
271 * Fetch (and decompress if necessary) the stored text of the most
272 * recently edited deleted revision of the page.
274 * If there are no archived revisions for the page, returns NULL.
276 * @return string
278 function getLastRevisionText() {
279 $dbr = wfGetDB( DB_SLAVE );
280 $row = $dbr->selectRow( 'archive',
281 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
282 array( 'ar_namespace' => $this->title->getNamespace(),
283 'ar_title' => $this->title->getDBkey() ),
284 'PageArchive::getLastRevisionText',
285 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
286 if( $row ) {
287 return $this->getTextFromRow( $row );
288 } else {
289 return NULL;
294 * Quick check if any archived revisions are present for the page.
295 * @return bool
297 function isDeleted() {
298 $dbr = wfGetDB( DB_SLAVE );
299 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
300 array( 'ar_namespace' => $this->title->getNamespace(),
301 'ar_title' => $this->title->getDBkey() ) );
302 return ($n > 0);
306 * Restore the given (or all) text and file revisions for the page.
307 * Once restored, the items will be removed from the archive tables.
308 * The deletion log will be updated with an undeletion notice.
310 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
311 * @param string $comment
312 * @param array $fileVersions
313 * @param bool $unsuppress
315 * @return array(number of file revisions restored, number of image revisions restored, log message)
316 * on success, false on failure
318 function undelete( $timestamps, $comment = '', $fileVersions = array(), $unsuppress = false ) {
319 // If both the set of text revisions and file revisions are empty,
320 // restore everything. Otherwise, just restore the requested items.
321 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
323 $restoreText = $restoreAll || !empty( $timestamps );
324 $restoreFiles = $restoreAll || !empty( $fileVersions );
326 if( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
327 $img = wfLocalFile( $this->title );
328 $this->fileStatus = $img->restore( $fileVersions, $unsuppress );
329 $filesRestored = $this->fileStatus->successCount;
330 } else {
331 $filesRestored = 0;
334 if( $restoreText ) {
335 $textRestored = $this->undeleteRevisions( $timestamps, $unsuppress, $comment );
336 if($textRestored === false) // It must be one of UNDELETE_*
337 return false;
338 } else {
339 $textRestored = 0;
342 // Touch the log!
343 global $wgContLang;
344 $log = new LogPage( 'delete' );
346 if( $textRestored && $filesRestored ) {
347 $reason = wfMsgExt( 'undeletedrevisions-files', array( 'content', 'parsemag' ),
348 $wgContLang->formatNum( $textRestored ),
349 $wgContLang->formatNum( $filesRestored ) );
350 } elseif( $textRestored ) {
351 $reason = wfMsgExt( 'undeletedrevisions', array( 'content', 'parsemag' ),
352 $wgContLang->formatNum( $textRestored ) );
353 } elseif( $filesRestored ) {
354 $reason = wfMsgExt( 'undeletedfiles', array( 'content', 'parsemag' ),
355 $wgContLang->formatNum( $filesRestored ) );
356 } else {
357 wfDebug( "Undelete: nothing undeleted...\n" );
358 return false;
361 if( trim( $comment ) != '' )
362 $reason .= ": {$comment}";
363 $log->addEntry( 'restore', $this->title, $reason );
365 return array($textRestored, $filesRestored, $reason);
369 * This is the meaty bit -- restores archived revisions of the given page
370 * to the cur/old tables. If the page currently exists, all revisions will
371 * be stuffed into old, otherwise the most recent will go into cur.
373 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
374 * @param string $comment
375 * @param array $fileVersions
376 * @param bool $unsuppress, remove all ar_deleted/fa_deleted restrictions of seletected revs
378 * @return mixed number of revisions restored or false on failure
380 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
381 if ( wfReadOnly() )
382 return false;
383 $restoreAll = empty( $timestamps );
385 $dbw = wfGetDB( DB_MASTER );
387 # Does this page already exist? We'll have to update it...
388 $article = new Article( $this->title );
389 $options = 'FOR UPDATE'; // lock page
390 $page = $dbw->selectRow( 'page',
391 array( 'page_id', 'page_latest' ),
392 array( 'page_namespace' => $this->title->getNamespace(),
393 'page_title' => $this->title->getDBkey() ),
394 __METHOD__,
395 $options
397 if( $page ) {
398 $makepage = false;
399 # Page already exists. Import the history, and if necessary
400 # we'll update the latest revision field in the record.
401 $newid = 0;
402 $pageId = $page->page_id;
403 $previousRevId = $page->page_latest;
404 # Get the time span of this page
405 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
406 array( 'rev_id' => $previousRevId ),
407 __METHOD__ );
408 if( $previousTimestamp === false ) {
409 wfDebug( __METHOD__.": existing page refers to a page_latest that does not exist\n" );
410 return 0;
412 } else {
413 # Have to create a new article...
414 $makepage = true;
415 $previousRevId = 0;
416 $previousTimestamp = 0;
419 if( $restoreAll ) {
420 $oldones = '1 = 1'; # All revisions...
421 } else {
422 $oldts = implode( ',',
423 array_map( array( &$dbw, 'addQuotes' ),
424 array_map( array( &$dbw, 'timestamp' ),
425 $timestamps ) ) );
427 $oldones = "ar_timestamp IN ( {$oldts} )";
431 * Select each archived revision...
433 $result = $dbw->select( 'archive',
434 /* fields */ array(
435 'ar_rev_id',
436 'ar_text',
437 'ar_comment',
438 'ar_user',
439 'ar_user_text',
440 'ar_timestamp',
441 'ar_minor_edit',
442 'ar_flags',
443 'ar_text_id',
444 'ar_deleted',
445 'ar_page_id',
446 'ar_len' ),
447 /* WHERE */ array(
448 'ar_namespace' => $this->title->getNamespace(),
449 'ar_title' => $this->title->getDBkey(),
450 $oldones ),
451 __METHOD__,
452 /* options */ array( 'ORDER BY' => 'ar_timestamp' )
454 $ret = $dbw->resultObject( $result );
455 $rev_count = $dbw->numRows( $result );
456 if( !$rev_count ) {
457 wfDebug( __METHOD__.": no revisions to restore\n" );
458 return false; // ???
461 $ret->seek( $rev_count - 1 ); // move to last
462 $row = $ret->fetchObject(); // get newest archived rev
463 $ret->seek( 0 ); // move back
465 if( $makepage ) {
466 // Check the state of the newest to-be version...
467 if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
468 return false; // we can't leave the current revision like this!
470 // Safe to insert now...
471 $newid = $article->insertOn( $dbw );
472 $pageId = $newid;
473 } else {
474 // Check if a deleted revision will become the current revision...
475 if( $row->ar_timestamp > $previousTimestamp ) {
476 // Check the state of the newest to-be version...
477 if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
478 return false; // we can't leave the current revision like this!
483 $revision = null;
484 $restored = 0;
486 while( $row = $ret->fetchObject() ) {
487 // Check for key dupes due to shitty archive integrity.
488 if( $row->ar_rev_id ) {
489 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
490 if( $exists ) continue; // don't throw DB errors
492 // Insert one revision at a time...maintaining deletion status
493 // unless we are specifically removing all restrictions...
494 $revision = Revision::newFromArchiveRow( $row,
495 array(
496 'page' => $pageId,
497 'deleted' => $unsuppress ? 0 : $row->ar_deleted
498 ) );
500 $revision->insertOn( $dbw );
501 $restored++;
503 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
505 # Now that it's safely stored, take it out of the archive
506 $dbw->delete( 'archive',
507 /* WHERE */ array(
508 'ar_namespace' => $this->title->getNamespace(),
509 'ar_title' => $this->title->getDBkey(),
510 $oldones ),
511 __METHOD__ );
513 // Was anything restored at all?
514 if( $restored == 0 )
515 return 0;
517 if( $revision ) {
518 // Attach the latest revision to the page...
519 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
520 if( $newid || $wasnew ) {
521 // Update site stats, link tables, etc
522 $article->createUpdates( $revision );
525 if( $newid ) {
526 wfRunHooks( 'ArticleUndelete', array( &$this->title, true, $comment ) );
527 Article::onArticleCreate( $this->title );
528 } else {
529 wfRunHooks( 'ArticleUndelete', array( &$this->title, false, $comment ) );
530 Article::onArticleEdit( $this->title );
533 if( $this->title->getNamespace() == NS_FILE ) {
534 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
535 $update->doUpdate();
537 } else {
538 // Revision couldn't be created. This is very weird
539 return self::UNDELETE_UNKNOWNERR;
542 return $restored;
545 function getFileStatus() { return $this->fileStatus; }
549 * The HTML form for Special:Undelete, which allows users with the appropriate
550 * permissions to view and restore deleted content.
551 * @ingroup SpecialPage
553 class UndeleteForm {
554 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
555 var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken;
557 function UndeleteForm( $request, $par = "" ) {
558 global $wgUser;
559 $this->mAction = $request->getVal( 'action' );
560 $this->mTarget = $request->getVal( 'target' );
561 $this->mSearchPrefix = $request->getText( 'prefix' );
562 $time = $request->getVal( 'timestamp' );
563 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
564 $this->mFile = $request->getVal( 'file' );
566 $posted = $request->wasPosted() &&
567 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
568 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
569 $this->mInvert = $request->getCheck( 'invert' ) && $posted;
570 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
571 $this->mDiff = $request->getCheck( 'diff' );
572 $this->mComment = $request->getText( 'wpComment' );
573 $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
574 $this->mToken = $request->getVal( 'token' );
576 if( $par != "" ) {
577 $this->mTarget = $par;
579 if ( $wgUser->isAllowed( 'deletedcontent' ) && $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
580 $this->mAllowed = true; // user can restore
581 $this->mCanView = true; // user can view content
582 } elseif ( $wgUser->isAllowed( 'deletedcontent' ) ) {
583 $this->mAllowed = false; // user cannot restore
584 $this->mCanView = true; // user can view content
585 } else { // user can only view the list of revisions
586 $this->mAllowed = false;
587 $this->mCanView = false;
588 $this->mTimestamp = '';
589 $this->mRestore = false;
591 if ( $this->mTarget !== "" ) {
592 $this->mTargetObj = Title::newFromURL( $this->mTarget );
593 } else {
594 $this->mTargetObj = NULL;
596 if( $this->mRestore || $this->mInvert ) {
597 $timestamps = array();
598 $this->mFileVersions = array();
599 foreach( $_REQUEST as $key => $val ) {
600 $matches = array();
601 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
602 array_push( $timestamps, $matches[1] );
605 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
606 $this->mFileVersions[] = intval( $matches[1] );
609 rsort( $timestamps );
610 $this->mTargetTimestamp = $timestamps;
614 function execute() {
615 global $wgOut, $wgUser;
616 if ( $this->mAllowed ) {
617 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
618 } else {
619 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
622 if( is_null( $this->mTargetObj ) ) {
623 # Not all users can just browse every deleted page from the list
624 if( $wgUser->isAllowed( 'browsearchive' ) ) {
625 $this->showSearchForm();
627 # List undeletable articles
628 if( $this->mSearchPrefix ) {
629 $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
630 $this->showList( $result );
632 } else {
633 $wgOut->addWikiMsg( 'undelete-header' );
635 return;
637 if( $this->mTimestamp !== '' ) {
638 return $this->showRevision( $this->mTimestamp );
640 if( $this->mFile !== null ) {
641 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
642 // Check if user is allowed to see this file
643 if( !$file->userCan( File::DELETED_FILE ) ) {
644 $wgOut->permissionRequired( 'suppressrevision' );
645 return false;
646 } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
647 $this->showFileConfirmationForm( $this->mFile );
648 return false;
649 } else {
650 return $this->showFile( $this->mFile );
653 if( $this->mRestore && $this->mAction == "submit" ) {
654 global $wgUploadMaintenance;
655 if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
656 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n", array( 'filedelete-maintenance' ) );
657 return;
659 return $this->undelete();
661 if( $this->mInvert && $this->mAction == "submit" ) {
662 return $this->showHistory( );
664 return $this->showHistory();
667 function showSearchForm() {
668 global $wgOut, $wgScript;
669 $wgOut->addWikiMsg( 'undelete-header' );
671 $wgOut->addHTML(
672 Xml::openElement( 'form', array(
673 'method' => 'get',
674 'action' => $wgScript ) ) .
675 Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
676 Xml::hidden( 'title',
677 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
678 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
679 'prefix', 'prefix', 20,
680 $this->mSearchPrefix ) . ' ' .
681 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
682 Xml::closeElement( 'fieldset' ) .
683 Xml::closeElement( 'form' )
687 // Generic list of deleted pages
688 private function showList( $result ) {
689 global $wgLang, $wgContLang, $wgUser, $wgOut;
691 if( $result->numRows() == 0 ) {
692 $wgOut->addWikiMsg( 'undelete-no-results' );
693 return;
696 $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
698 $sk = $wgUser->getSkin();
699 $undelete = SpecialPage::getTitleFor( 'Undelete' );
700 $wgOut->addHTML( "<ul>\n" );
701 while( $row = $result->fetchObject() ) {
702 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
703 $link = $sk->linkKnown(
704 $undelete,
705 htmlspecialchars( $title->getPrefixedText() ),
706 array(),
707 array( 'target' => $title->getPrefixedText() )
709 $revs = wfMsgExt( 'undeleterevisions',
710 array( 'parseinline' ),
711 $wgLang->formatNum( $row->count ) );
712 $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
714 $result->free();
715 $wgOut->addHTML( "</ul>\n" );
717 return true;
720 private function showRevision( $timestamp ) {
721 global $wgLang, $wgUser, $wgOut;
722 $self = SpecialPage::getTitleFor( 'Undelete' );
723 $skin = $wgUser->getSkin();
725 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
727 $archive = new PageArchive( $this->mTargetObj );
728 $rev = $archive->getRevision( $timestamp );
730 if( !$rev ) {
731 $wgOut->addWikiMsg( 'undeleterevision-missing' );
732 return;
735 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
736 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
737 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
738 return;
739 } else {
740 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
741 $wgOut->addHTML( '<br/>' );
742 // and we are allowed to see...
746 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
748 $link = $skin->linkKnown(
749 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
750 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
753 if( $this->mDiff ) {
754 $previousRev = $archive->getPreviousRevision( $timestamp );
755 if( $previousRev ) {
756 $this->showDiff( $previousRev, $rev );
757 if( $wgUser->getOption( 'diffonly' ) ) {
758 return;
759 } else {
760 $wgOut->addHTML( '<hr />' );
762 } else {
763 $wgOut->addWikiMsg( 'undelete-nodiff' );
767 // date and time are separate parameters to facilitate localisation.
768 // $time is kept for backward compat reasons.
769 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
770 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
771 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
772 $user = $skin->revUserTools( $rev );
774 if( $this->mPreview ) {
775 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
776 } else {
777 $openDiv = '<div id="mw-undelete-revision">';
780 $revdlink = '';
781 // Diffs already have revision delete links
782 if( !$this->mDiff && $wgUser->isAllowed( 'deleterevision' ) ) {
783 if( !$rev->userCan(Revision::DELETED_RESTRICTED ) ) {
784 // If revision was hidden from sysops
785 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
786 '('.wfMsgHtml('rev-delundel').')' );
787 } else {
788 $query = array(
789 'type' => 'archive',
790 'target' => $this->mTargetObj->getPrefixedDBkey(),
791 'ids' => $rev->getTimestamp()
793 $revdlink = $skin->revDeleteLink( $query, $rev->isDeleted( File::DELETED_RESTRICTED ) );
797 $wgOut->addHTML( $openDiv . $revdlink . wfMsgWikiHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</div>' );
798 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
800 if( $this->mPreview ) {
801 //Hide [edit]s
802 $popts = $wgOut->parserOptions();
803 $popts->setEditSection( false );
804 $wgOut->parserOptions( $popts );
805 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
808 $wgOut->addHTML(
809 Xml::element( 'textarea', array(
810 'readonly' => 'readonly',
811 'cols' => intval( $wgUser->getOption( 'cols' ) ),
812 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
813 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
814 Xml::openElement( 'div' ) .
815 Xml::openElement( 'form', array(
816 'method' => 'post',
817 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
818 Xml::element( 'input', array(
819 'type' => 'hidden',
820 'name' => 'target',
821 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
822 Xml::element( 'input', array(
823 'type' => 'hidden',
824 'name' => 'timestamp',
825 'value' => $timestamp ) ) .
826 Xml::element( 'input', array(
827 'type' => 'hidden',
828 'name' => 'wpEditToken',
829 'value' => $wgUser->editToken() ) ) .
830 Xml::element( 'input', array(
831 'type' => 'submit',
832 'name' => 'preview',
833 'value' => wfMsg( 'showpreview' ) ) ) .
834 Xml::element( 'input', array(
835 'name' => 'diff',
836 'type' => 'submit',
837 'value' => wfMsg( 'showdiff' ) ) ) .
838 Xml::closeElement( 'form' ) .
839 Xml::closeElement( 'div' ) );
843 * Build a diff display between this and the previous either deleted
844 * or non-deleted edit.
845 * @param Revision $previousRev
846 * @param Revision $currentRev
847 * @return string HTML
849 function showDiff( $previousRev, $currentRev ) {
850 global $wgOut;
852 $diffEngine = new DifferenceEngine();
853 $diffEngine->showDiffStyle();
854 $wgOut->addHTML(
855 "<div>" .
856 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
857 "<col class='diff-marker' />" .
858 "<col class='diff-content' />" .
859 "<col class='diff-marker' />" .
860 "<col class='diff-content' />" .
861 "<tr>" .
862 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
863 $this->diffHeader( $previousRev, 'o' ) .
864 "</td>\n" .
865 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
866 $this->diffHeader( $currentRev, 'n' ) .
867 "</td>\n" .
868 "</tr>" .
869 $diffEngine->generateDiffBody(
870 $previousRev->getText(), $currentRev->getText() ) .
871 "</table>" .
872 "</div>\n"
876 private function diffHeader( $rev, $prefix ) {
877 global $wgUser, $wgLang, $wgLang;
878 $sk = $wgUser->getSkin();
879 $isDeleted = !( $rev->getId() && $rev->getTitle() );
880 if( $isDeleted ) {
881 /// @fixme $rev->getTitle() is null for deleted revs...?
882 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
883 $targetQuery = array(
884 'target' => $this->mTargetObj->getPrefixedText(),
885 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
887 } else {
888 /// @fixme getId() may return non-zero for deleted revs...
889 $targetPage = $rev->getTitle();
890 $targetQuery = array( 'oldid' => $rev->getId() );
892 // Add show/hide link if available
893 if( $wgUser->isAllowed( 'deleterevision' ) ) {
894 // If revision was hidden from sysops
895 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
896 $del = ' ' . Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
897 '(' . wfMsgHtml('rev-delundel') . ')' );
898 // Otherwise, show the link...
899 } else {
900 $query = array(
901 'type' => 'archive',
902 'target' => $this->mTargetObj->getPrefixedDbkey(),
903 'ids' => $rev->getTimestamp() );
904 $del = ' ' . $sk->revDeleteLink( $query,
905 $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
907 } else {
908 $del = '';
910 return
911 '<div id="mw-diff-'.$prefix.'title1"><strong>' .
912 $sk->link(
913 $targetPage,
914 wfMsgHtml(
915 'revisionasof',
916 htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
917 htmlspecialchars( $wgLang->date( $rev->getTimestamp(), true ) ),
918 htmlspecialchars( $wgLang->time( $rev->getTimestamp(), true ) )
920 array(),
921 $targetQuery
923 '</strong></div>' .
924 '<div id="mw-diff-'.$prefix.'title2">' .
925 $sk->revUserTools( $rev ) . '<br/>' .
926 '</div>' .
927 '<div id="mw-diff-'.$prefix.'title3">' .
928 $sk->revComment( $rev ) . $del . '<br/>' .
929 '</div>';
933 * Show a form confirming whether a tokenless user really wants to see a file
935 private function showFileConfirmationForm( $key ) {
936 global $wgOut, $wgUser, $wgLang;
937 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
938 $wgOut->addWikiMsg( 'undelete-show-file-confirm',
939 $this->mTargetObj->getText(),
940 $wgLang->date( $file->getTimestamp() ),
941 $wgLang->time( $file->getTimestamp() ) );
942 $wgOut->addHTML(
943 Xml::openElement( 'form', array(
944 'method' => 'POST',
945 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
946 'target=' . urlencode( $this->mTarget ) .
947 '&file=' . urlencode( $key ) .
948 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
951 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
952 '</form>'
957 * Show a deleted file version requested by the visitor.
959 private function showFile( $key ) {
960 global $wgOut, $wgRequest;
961 $wgOut->disable();
963 # We mustn't allow the output to be Squid cached, otherwise
964 # if an admin previews a deleted image, and it's cached, then
965 # a user without appropriate permissions can toddle off and
966 # nab the image, and Squid will serve it
967 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
968 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
969 $wgRequest->response()->header( 'Pragma: no-cache' );
971 global $IP;
972 require_once( "$IP/includes/StreamFile.php" );
973 $repo = RepoGroup::singleton()->getLocalRepo();
974 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
975 wfStreamFile( $path );
978 private function showHistory( ) {
979 global $wgLang, $wgUser, $wgOut;
981 $sk = $wgUser->getSkin();
982 if( $this->mAllowed ) {
983 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
984 } else {
985 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
988 $wgOut->wrapWikiMsg( "<div class='mw-undelete-pagetitle'>\n$1</div>\n", array ( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() ) );
990 $archive = new PageArchive( $this->mTargetObj );
992 $text = $archive->getLastRevisionText();
993 if( is_null( $text ) ) {
994 $wgOut->addWikiMsg( "nohistory" );
995 return;
998 $wgOut->addHTML( '<div class="mw-undelete-history">' );
999 if ( $this->mAllowed ) {
1000 $wgOut->addWikiMsg( "undeletehistory" );
1001 $wgOut->addWikiMsg( "undeleterevdel" );
1002 } else {
1003 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
1005 $wgOut->addHTML( '</div>' );
1007 # List all stored revisions
1008 $revisions = $archive->listRevisions();
1009 $files = $archive->listFiles();
1011 $haveRevisions = $revisions && $revisions->numRows() > 0;
1012 $haveFiles = $files && $files->numRows() > 0;
1014 # Batch existence check on user and talk pages
1015 if( $haveRevisions ) {
1016 $batch = new LinkBatch();
1017 while( $row = $revisions->fetchObject() ) {
1018 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
1019 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
1021 $batch->execute();
1022 $revisions->seek( 0 );
1024 if( $haveFiles ) {
1025 $batch = new LinkBatch();
1026 while( $row = $files->fetchObject() ) {
1027 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
1028 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
1030 $batch->execute();
1031 $files->seek( 0 );
1034 if ( $this->mAllowed ) {
1035 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1036 $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
1037 # Start the form here
1038 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
1039 $wgOut->addHTML( $top );
1042 # Show relevant lines from the deletion log:
1043 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
1044 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
1045 # Show relevant lines from the suppression log:
1046 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
1047 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
1048 LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
1051 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
1052 # Format the user-visible controls (comment field, submission button)
1053 # in a nice little table
1054 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
1055 $unsuppressBox =
1056 "<tr>
1057 <td>&nbsp;</td>
1058 <td class='mw-input'>" .
1059 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
1060 'mw-undelete-unsuppress', $this->mUnsuppress ).
1061 "</td>
1062 </tr>";
1063 } else {
1064 $unsuppressBox = "";
1066 $table =
1067 Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
1068 Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
1069 "<tr>
1070 <td colspan='2' class='mw-undelete-extrahelp'>" .
1071 wfMsgWikiHtml( 'undeleteextrahelp' ) .
1072 "</td>
1073 </tr>
1074 <tr>
1075 <td class='mw-label'>" .
1076 Xml::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
1077 "</td>
1078 <td class='mw-input'>" .
1079 Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
1080 "</td>
1081 </tr>
1082 <tr>
1083 <td>&nbsp;</td>
1084 <td class='mw-submit'>" .
1085 Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
1086 Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) . ' ' .
1087 Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
1088 "</td>
1089 </tr>" .
1090 $unsuppressBox .
1091 Xml::closeElement( 'table' ) .
1092 Xml::closeElement( 'fieldset' );
1094 $wgOut->addHTML( $table );
1097 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
1099 if( $haveRevisions ) {
1100 # The page's stored (deleted) history:
1101 $wgOut->addHTML("<ul>");
1102 $target = urlencode( $this->mTarget );
1103 $remaining = $revisions->numRows();
1104 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
1106 while( $row = $revisions->fetchObject() ) {
1107 $remaining--;
1108 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
1110 $revisions->free();
1111 $wgOut->addHTML("</ul>");
1112 } else {
1113 $wgOut->addWikiMsg( "nohistory" );
1116 if( $haveFiles ) {
1117 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1118 $wgOut->addHTML( "<ul>" );
1119 while( $row = $files->fetchObject() ) {
1120 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
1122 $files->free();
1123 $wgOut->addHTML( "</ul>" );
1126 if ( $this->mAllowed ) {
1127 # Slip in the hidden controls here
1128 $misc = Xml::hidden( 'target', $this->mTarget );
1129 $misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
1130 $misc .= Xml::closeElement( 'form' );
1131 $wgOut->addHTML( $misc );
1134 return true;
1137 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
1138 global $wgUser, $wgLang;
1140 $rev = Revision::newFromArchiveRow( $row,
1141 array( 'page' => $this->mTargetObj->getArticleId() ) );
1142 $stxt = '';
1143 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1144 // Build checkboxen...
1145 if( $this->mAllowed ) {
1146 if( $this->mInvert ) {
1147 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1148 $checkBox = Xml::check( "ts$ts");
1149 } else {
1150 $checkBox = Xml::check( "ts$ts", true );
1152 } else {
1153 $checkBox = Xml::check( "ts$ts" );
1155 } else {
1156 $checkBox = '';
1158 // Build page & diff links...
1159 if( $this->mCanView ) {
1160 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1161 # Last link
1162 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1163 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1164 $last = wfMsgHtml('diff');
1165 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
1166 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1167 $last = $sk->linkKnown(
1168 $titleObj,
1169 wfMsgHtml('diff'),
1170 array(),
1171 array(
1172 'target' => $this->mTargetObj->getPrefixedText(),
1173 'timestamp' => $ts,
1174 'diff' => 'prev'
1177 } else {
1178 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1179 $last = wfMsgHtml('diff');
1181 } else {
1182 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1183 $last = wfMsgHtml('diff');
1185 // User links
1186 $userLink = $sk->revUserTools( $rev );
1187 // Revision text size
1188 if( !is_null($size = $row->ar_len) ) {
1189 $stxt = $sk->formatRevisionSize( $size );
1191 // Edit summary
1192 $comment = $sk->revComment( $rev );
1193 // Show/hide link
1194 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1195 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1196 // If revision was hidden from sysops
1197 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
1198 '('.wfMsgHtml('rev-delundel').')' );
1199 } else {
1200 $query = array(
1201 'type' => 'archive',
1202 'target' => $this->mTargetObj->getPrefixedDBkey(),
1203 'ids' => $ts
1205 $revdlink = $sk->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
1207 } else {
1208 $revdlink = '';
1210 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
1213 private function formatFileRow( $row, $sk ) {
1214 global $wgUser, $wgLang;
1216 $file = ArchivedFile::newFromRow( $row );
1218 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
1219 if( $this->mAllowed && $row->fa_storage_key ) {
1220 $checkBox = Xml::check( "fileid" . $row->fa_id );
1221 $key = urlencode( $row->fa_storage_key );
1222 $target = urlencode( $this->mTarget );
1223 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1224 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
1225 } else {
1226 $checkBox = '';
1227 $pageLink = $wgLang->timeanddate( $ts, true );
1229 $userLink = $this->getFileUser( $file, $sk );
1230 $data =
1231 wfMsg( 'widthheight',
1232 $wgLang->formatNum( $row->fa_width ),
1233 $wgLang->formatNum( $row->fa_height ) ) .
1234 ' (' .
1235 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
1236 ')';
1237 $data = htmlspecialchars( $data );
1238 $comment = $this->getFileComment( $file, $sk );
1239 $revdlink = '';
1240 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1241 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
1242 // If revision was hidden from sysops
1243 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml('rev-delundel').')' );
1244 } else {
1245 $query = array(
1246 'type' => 'filearchive',
1247 'target' => $this->mTargetObj->getPrefixedDBkey(),
1248 'ids' => $row->fa_id
1250 $revdlink = $sk->revDeleteLink( $query, $file->isDeleted( File::DELETED_RESTRICTED ) );
1253 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1257 * Fetch revision text link if it's available to all users
1258 * @return string
1260 function getPageLink( $rev, $titleObj, $ts, $sk ) {
1261 global $wgLang;
1263 $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1265 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
1266 return '<span class="history-deleted">' . $time . '</span>';
1267 } else {
1268 $link = $sk->linkKnown(
1269 $titleObj,
1270 $time,
1271 array(),
1272 array(
1273 'target' => $this->mTargetObj->getPrefixedText(),
1274 'timestamp' => $ts
1277 if( $rev->isDeleted(Revision::DELETED_TEXT) )
1278 $link = '<span class="history-deleted">' . $link . '</span>';
1279 return $link;
1284 * Fetch image view link if it's available to all users
1285 * @return string
1287 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1288 global $wgLang, $wgUser;
1290 if( !$file->userCan(File::DELETED_FILE) ) {
1291 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1292 } else {
1293 $link = $sk->linkKnown(
1294 $titleObj,
1295 $wgLang->timeanddate( $ts, true ),
1296 array(),
1297 array(
1298 'target' => $this->mTargetObj->getPrefixedText(),
1299 'file' => $key,
1300 'token' => $wgUser->editToken( $key )
1303 if( $file->isDeleted(File::DELETED_FILE) )
1304 $link = '<span class="history-deleted">' . $link . '</span>';
1305 return $link;
1310 * Fetch file's user id if it's available to this user
1311 * @return string
1313 function getFileUser( $file, $sk ) {
1314 if( !$file->userCan(File::DELETED_USER) ) {
1315 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
1316 } else {
1317 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
1318 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1319 if( $file->isDeleted(File::DELETED_USER) )
1320 $link = '<span class="history-deleted">' . $link . '</span>';
1321 return $link;
1326 * Fetch file upload comment if it's available to this user
1327 * @return string
1329 function getFileComment( $file, $sk ) {
1330 if( !$file->userCan(File::DELETED_COMMENT) ) {
1331 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
1332 } else {
1333 $link = $sk->commentBlock( $file->getRawDescription() );
1334 if( $file->isDeleted(File::DELETED_COMMENT) )
1335 $link = '<span class="history-deleted">' . $link . '</span>';
1336 return $link;
1340 function undelete() {
1341 global $wgOut, $wgUser;
1342 if ( wfReadOnly() ) {
1343 $wgOut->readOnlyPage();
1344 return;
1346 if( !is_null( $this->mTargetObj ) ) {
1347 $archive = new PageArchive( $this->mTargetObj );
1348 $ok = $archive->undelete(
1349 $this->mTargetTimestamp,
1350 $this->mComment,
1351 $this->mFileVersions,
1352 $this->mUnsuppress );
1354 if( is_array($ok) ) {
1355 if ( $ok[1] ) // Undeleted file count
1356 wfRunHooks( 'FileUndeleteComplete', array(
1357 $this->mTargetObj, $this->mFileVersions,
1358 $wgUser, $this->mComment) );
1360 $skin = $wgUser->getSkin();
1361 $link = $skin->linkKnown( $this->mTargetObj );
1362 $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
1363 } else {
1364 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1365 $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
1368 // Show file deletion warnings and errors
1369 $status = $archive->getFileStatus();
1370 if( $status && !$status->isGood() ) {
1371 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1373 } else {
1374 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1376 return false;