In Special:RevisionDelete:
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
1 <?php
2
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and restore deleted content
6 *
7 * @file
8 * @ingroup SpecialPage
9 */
10
11 /**
12 * Constructor
13 */
14 function wfSpecialUndelete( $par ) {
15 global $wgRequest;
16
17 $form = new UndeleteForm( $wgRequest, $par );
18 $form->execute();
19 }
20
21 /**
22 * Used to show archived pages and eventually restore them.
23 * @ingroup SpecialPage
24 */
25 class PageArchive {
26 protected $title;
27 var $fileStatus;
28
29 function __construct( $title ) {
30 if( is_null( $title ) ) {
31 throw new MWException( 'Archiver() given a null title.');
32 }
33 $this->title = $title;
34 }
35
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.
40 *
41 * @return ResultWrapper
42 */
43 public static function listAllPages() {
44 $dbr = wfGetDB( DB_SLAVE );
45 return self::listPages( $dbr, '' );
46 }
47
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.
52 *
53 * @return ResultWrapper
54 */
55 public static function listPagesByPrefix( $prefix ) {
56 $dbr = wfGetDB( DB_SLAVE );
57
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 );
67 }
68 $conds = array(
69 'ar_namespace' => $ns,
70 "ar_title LIKE '$encPrefix%'",
71 );
72 return self::listPages( $dbr, $conds );
73 }
74
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'
83 ),
84 $condition,
85 __METHOD__,
86 array(
87 'GROUP BY' => 'ar_namespace,ar_title',
88 'ORDER BY' => 'ar_namespace,ar_title',
89 'LIMIT' => 100,
90 )
91 )
92 );
93 }
94
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.
98 *
99 * @return ResultWrapper
100 */
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;
111 }
112
113 /**
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.
117 *
118 * @return ResultWrapper
119 * @todo Does this belong in Image for fuller encapsulation?
120 */
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;
149 }
150 return null;
151 }
152
153 /**
154 * Fetch (and decompress if necessary) the stored text for the deleted
155 * revision of the page with the given timestamp.
156 *
157 * @return string
158 * @deprecated Use getRevision() for more flexible information
159 */
160 function getRevisionText( $timestamp ) {
161 $rev = $this->getRevision( $timestamp );
162 return $rev ? $rev->getText() : null;
163 }
164
165 /**
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
170 */
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;
194 }
195 }
196
197 /**
198 * Return the most-previous revision, either live or deleted, against
199 * the deleted revision given by timestamp.
200 *
201 * May produce unexpected results in case of history merges or other
202 * unusual time issues.
203 *
204 * @param string $timestamp
205 * @return Revision or null
206 */
207 function getPreviousRevision( $timestamp ) {
208 $dbr = wfGetDB( DB_SLAVE );
209
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;
222
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;
237
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;
247 }
248 }
249
250 /**
251 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
252 */
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 );
266 }
267 }
268
269
270 /**
271 * Fetch (and decompress if necessary) the stored text of the most
272 * recently edited deleted revision of the page.
273 *
274 * If there are no archived revisions for the page, returns NULL.
275 *
276 * @return string
277 */
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;
290 }
291 }
292
293 /**
294 * Quick check if any archived revisions are present for the page.
295 * @return bool
296 */
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);
303 }
304
305 /**
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.
309 *
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
314 *
315 * @return array(number of file revisions restored, number of image revisions restored, log message)
316 * on success, false on failure
317 */
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 );
322
323 $restoreText = $restoreAll || !empty( $timestamps );
324 $restoreFiles = $restoreAll || !empty( $fileVersions );
325
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;
332 }
333
334 if( $restoreText ) {
335 $textRestored = $this->undeleteRevisions( $timestamps, $unsuppress );
336 if($textRestored === false) // It must be one of UNDELETE_*
337 return false;
338 } else {
339 $textRestored = 0;
340 }
341
342 // Touch the log!
343 global $wgContLang;
344 $log = new LogPage( 'delete' );
345
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;
359 }
360
361 if( trim( $comment ) != '' )
362 $reason .= ": {$comment}";
363 $log->addEntry( 'restore', $this->title, $reason );
364
365 return array($textRestored, $filesRestored, $reason);
366 }
367
368 /**
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.
372 *
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
377 *
378 * @return mixed number of revisions restored or false on failure
379 */
380 private function undeleteRevisions( $timestamps, $unsuppress = false ) {
381 if ( wfReadOnly() )
382 return false;
383 $restoreAll = empty( $timestamps );
384
385 $dbw = wfGetDB( DB_MASTER );
386
387 # Does this page already exist? We'll have to update it...
388 $article = new Article( $this->title );
389 $options = 'FOR UPDATE';
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 );
396 if( $page ) {
397 $makepage = false;
398 # Page already exists. Import the history, and if necessary
399 # we'll update the latest revision field in the record.
400 $newid = 0;
401 $pageId = $page->page_id;
402 $previousRevId = $page->page_latest;
403 # Get the time span of this page
404 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
405 array( 'rev_id' => $previousRevId ),
406 __METHOD__ );
407 if( $previousTimestamp === false ) {
408 wfDebug( __METHOD__.": existing page refers to a page_latest that does not exist\n" );
409 return 0;
410 }
411 } else {
412 # Have to create a new article...
413 $makepage = true;
414 $previousRevId = 0;
415 $previousTimestamp = 0;
416 }
417
418 if( $restoreAll ) {
419 $oldones = '1 = 1'; # All revisions...
420 } else {
421 $oldts = implode( ',',
422 array_map( array( &$dbw, 'addQuotes' ),
423 array_map( array( &$dbw, 'timestamp' ),
424 $timestamps ) ) );
425
426 $oldones = "ar_timestamp IN ( {$oldts} )";
427 }
428
429 /**
430 * Select each archived revision...
431 */
432 $result = $dbw->select( 'archive',
433 /* fields */ array(
434 'ar_rev_id',
435 'ar_text',
436 'ar_comment',
437 'ar_user',
438 'ar_user_text',
439 'ar_timestamp',
440 'ar_minor_edit',
441 'ar_flags',
442 'ar_text_id',
443 'ar_deleted',
444 'ar_page_id',
445 'ar_len' ),
446 /* WHERE */ array(
447 'ar_namespace' => $this->title->getNamespace(),
448 'ar_title' => $this->title->getDBkey(),
449 $oldones ),
450 __METHOD__,
451 /* options */ array( 'ORDER BY' => 'ar_timestamp' )
452 );
453 $ret = $dbw->resultObject( $result );
454 $rev_count = $dbw->numRows( $result );
455
456 if( $makepage ) {
457 $newid = $article->insertOn( $dbw );
458 $pageId = $newid;
459 }
460
461 $revision = null;
462 $restored = 0;
463
464 while( $row = $ret->fetchObject() ) {
465 // Check for key dupes due to shitty archive integrity.
466 if( $row->ar_rev_id ) {
467 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
468 if( $exists ) continue; // don't throw DB errors
469 }
470
471 $revision = Revision::newFromArchiveRow( $row,
472 array(
473 'page' => $pageId,
474 'deleted' => $unsuppress ? 0 : $row->ar_deleted
475 ) );
476
477 $revision->insertOn( $dbw );
478 $restored++;
479
480 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
481 }
482 # Now that it's safely stored, take it out of the archive
483 $dbw->delete( 'archive',
484 /* WHERE */ array(
485 'ar_namespace' => $this->title->getNamespace(),
486 'ar_title' => $this->title->getDBkey(),
487 $oldones ),
488 __METHOD__ );
489
490 // Was anything restored at all?
491 if( $restored == 0 )
492 return 0;
493
494 if( $revision ) {
495 // Attach the latest revision to the page...
496 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
497 if( $newid || $wasnew ) {
498 // We don't handle well with top revision deleted
499 // FIXME: any sysop can unsuppress any revision by just undeleting it into a non-existent page!
500 if( $revision->getVisibility() ) {
501 $dbw->update( 'revision',
502 array( 'rev_deleted' => 0 ),
503 array( 'rev_id' => $revision->getId() ),
504 __METHOD__
505 );
506 $revision->mDeleted = 0; // Don't pollute the parser cache
507 }
508 // Update site stats, link tables, etc
509 $article->createUpdates( $revision );
510 }
511
512 if( $newid ) {
513 wfRunHooks( 'ArticleUndelete', array( &$this->title, true ) );
514 Article::onArticleCreate( $this->title );
515 } else {
516 wfRunHooks( 'ArticleUndelete', array( &$this->title, false ) );
517 Article::onArticleEdit( $this->title );
518 }
519
520 if( $this->title->getNamespace() == NS_FILE ) {
521 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
522 $update->doUpdate();
523 }
524 } else {
525 // Revision couldn't be created. This is very weird
526 return self::UNDELETE_UNKNOWNERR;
527 }
528
529 return $restored;
530 }
531
532 function getFileStatus() { return $this->fileStatus; }
533 }
534
535 /**
536 * The HTML form for Special:Undelete, which allows users with the appropriate
537 * permissions to view and restore deleted content.
538 * @ingroup SpecialPage
539 */
540 class UndeleteForm {
541 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
542 var $mTargetTimestamp, $mAllowed, $mComment, $mToken;
543
544 function UndeleteForm( $request, $par = "" ) {
545 global $wgUser;
546 $this->mAction = $request->getVal( 'action' );
547 $this->mTarget = $request->getVal( 'target' );
548 $this->mSearchPrefix = $request->getText( 'prefix' );
549 $time = $request->getVal( 'timestamp' );
550 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
551 $this->mFile = $request->getVal( 'file' );
552
553 $posted = $request->wasPosted() &&
554 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
555 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
556 $this->mInvert = $request->getCheck( 'invert' ) && $posted;
557 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
558 $this->mDiff = $request->getCheck( 'diff' );
559 $this->mComment = $request->getText( 'wpComment' );
560 $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
561 $this->mToken = $request->getVal( 'token' );
562
563 if( $par != "" ) {
564 $this->mTarget = $par;
565 }
566 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
567 $this->mAllowed = true;
568 } else {
569 $this->mAllowed = false;
570 $this->mTimestamp = '';
571 $this->mRestore = false;
572 }
573 if ( $this->mTarget !== "" ) {
574 $this->mTargetObj = Title::newFromURL( $this->mTarget );
575 } else {
576 $this->mTargetObj = NULL;
577 }
578 if( $this->mRestore || $this->mInvert ) {
579 $timestamps = array();
580 $this->mFileVersions = array();
581 foreach( $_REQUEST as $key => $val ) {
582 $matches = array();
583 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
584 array_push( $timestamps, $matches[1] );
585 }
586
587 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
588 $this->mFileVersions[] = intval( $matches[1] );
589 }
590 }
591 rsort( $timestamps );
592 $this->mTargetTimestamp = $timestamps;
593 }
594 }
595
596 function execute() {
597 global $wgOut, $wgUser;
598 if ( $this->mAllowed ) {
599 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
600 } else {
601 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
602 }
603
604 if( is_null( $this->mTargetObj ) ) {
605 # Not all users can just browse every deleted page from the list
606 if( $wgUser->isAllowed( 'browsearchive' ) ) {
607 $this->showSearchForm();
608
609 # List undeletable articles
610 if( $this->mSearchPrefix ) {
611 $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
612 $this->showList( $result );
613 }
614 } else {
615 $wgOut->addWikiMsg( 'undelete-header' );
616 }
617 return;
618 }
619 if( $this->mTimestamp !== '' ) {
620 return $this->showRevision( $this->mTimestamp );
621 }
622 if( $this->mFile !== null ) {
623 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
624 // Check if user is allowed to see this file
625 if( !$file->userCan( File::DELETED_FILE ) ) {
626 $wgOut->permissionRequired( 'suppressrevision' );
627 return false;
628 } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
629 $this->showFileConfirmationForm( $this->mFile );
630 return false;
631 } else {
632 return $this->showFile( $this->mFile );
633 }
634 }
635 if( $this->mRestore && $this->mAction == "submit" ) {
636 return $this->undelete();
637 }
638 if( $this->mInvert && $this->mAction == "submit" ) {
639 return $this->showHistory( );
640 }
641 return $this->showHistory();
642 }
643
644 function showSearchForm() {
645 global $wgOut, $wgScript;
646 $wgOut->addWikiMsg( 'undelete-header' );
647
648 $wgOut->addHTML(
649 Xml::openElement( 'form', array(
650 'method' => 'get',
651 'action' => $wgScript ) ) .
652 Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
653 Xml::hidden( 'title',
654 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
655 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
656 'prefix', 'prefix', 20,
657 $this->mSearchPrefix ) . ' ' .
658 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
659 Xml::closeElement( 'fieldset' ) .
660 Xml::closeElement( 'form' )
661 );
662 }
663
664 // Generic list of deleted pages
665 private function showList( $result ) {
666 global $wgLang, $wgContLang, $wgUser, $wgOut;
667
668 if( $result->numRows() == 0 ) {
669 $wgOut->addWikiMsg( 'undelete-no-results' );
670 return;
671 }
672
673 $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
674
675 $sk = $wgUser->getSkin();
676 $undelete = SpecialPage::getTitleFor( 'Undelete' );
677 $wgOut->addHTML( "<ul>\n" );
678 while( $row = $result->fetchObject() ) {
679 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
680 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ),
681 'target=' . $title->getPrefixedUrl() );
682 $revs = wfMsgExt( 'undeleterevisions',
683 array( 'parseinline' ),
684 $wgLang->formatNum( $row->count ) );
685 $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
686 }
687 $result->free();
688 $wgOut->addHTML( "</ul>\n" );
689
690 return true;
691 }
692
693 private function showRevision( $timestamp ) {
694 global $wgLang, $wgUser, $wgOut;
695 $self = SpecialPage::getTitleFor( 'Undelete' );
696 $skin = $wgUser->getSkin();
697
698 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
699
700 $archive = new PageArchive( $this->mTargetObj );
701 $rev = $archive->getRevision( $timestamp );
702
703 if( !$rev ) {
704 $wgOut->addWikiMsg( 'undeleterevision-missing' );
705 return;
706 }
707
708 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
709 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
710 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
711 return;
712 } else {
713 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
714 $wgOut->addHTML( '<br/>' );
715 // and we are allowed to see...
716 }
717 }
718
719 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
720
721 $link = $skin->makeKnownLinkObj(
722 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
723 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
724 );
725
726 if( $this->mDiff ) {
727 $previousRev = $archive->getPreviousRevision( $timestamp );
728 if( $previousRev ) {
729 $this->showDiff( $previousRev, $rev );
730 if( $wgUser->getOption( 'diffonly' ) ) {
731 return;
732 } else {
733 $wgOut->addHTML( '<hr />' );
734 }
735 } else {
736 $wgOut->addWikiMsg( 'undelete-nodiff' );
737 }
738 }
739
740 // date and time are separate parameters to facilitate localisation.
741 // $time is kept for backward compat reasons.
742 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
743 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
744 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
745 $user = $skin->revUserTools( $rev );
746
747 if( $this->mPreview ) {
748 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
749 } else {
750 $openDiv = '<div id="mw-undelete-revision">';
751 }
752
753 $wgOut->addHTML( $openDiv . wfMsgWikiHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</div>' );
754 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
755
756 if( $this->mPreview ) {
757 //Hide [edit]s
758 $popts = $wgOut->parserOptions();
759 $popts->setEditSection( false );
760 $wgOut->parserOptions( $popts );
761 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
762 }
763
764 $wgOut->addHTML(
765 Xml::element( 'textarea', array(
766 'readonly' => 'readonly',
767 'cols' => intval( $wgUser->getOption( 'cols' ) ),
768 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
769 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
770 Xml::openElement( 'div' ) .
771 Xml::openElement( 'form', array(
772 'method' => 'post',
773 'action' => $self->getLocalURL( "action=submit" ) ) ) .
774 Xml::element( 'input', array(
775 'type' => 'hidden',
776 'name' => 'target',
777 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
778 Xml::element( 'input', array(
779 'type' => 'hidden',
780 'name' => 'timestamp',
781 'value' => $timestamp ) ) .
782 Xml::element( 'input', array(
783 'type' => 'hidden',
784 'name' => 'wpEditToken',
785 'value' => $wgUser->editToken() ) ) .
786 Xml::element( 'input', array(
787 'type' => 'submit',
788 'name' => 'preview',
789 'value' => wfMsg( 'showpreview' ) ) ) .
790 Xml::element( 'input', array(
791 'name' => 'diff',
792 'type' => 'submit',
793 'value' => wfMsg( 'showdiff' ) ) ) .
794 Xml::closeElement( 'form' ) .
795 Xml::closeElement( 'div' ) );
796 }
797
798 /**
799 * Build a diff display between this and the previous either deleted
800 * or non-deleted edit.
801 * @param Revision $previousRev
802 * @param Revision $currentRev
803 * @return string HTML
804 */
805 function showDiff( $previousRev, $currentRev ) {
806 global $wgOut;
807
808 $diffEngine = new DifferenceEngine();
809 $diffEngine->showDiffStyle();
810 $wgOut->addHTML(
811 "<div>" .
812 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
813 "<col class='diff-marker' />" .
814 "<col class='diff-content' />" .
815 "<col class='diff-marker' />" .
816 "<col class='diff-content' />" .
817 "<tr>" .
818 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
819 $this->diffHeader( $previousRev, 'o' ) .
820 "</td>\n" .
821 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
822 $this->diffHeader( $currentRev, 'n' ) .
823 "</td>\n" .
824 "</tr>" .
825 $diffEngine->generateDiffBody(
826 $previousRev->getText(), $currentRev->getText() ) .
827 "</table>" .
828 "</div>\n" );
829
830 }
831
832 private function diffHeader( $rev, $prefix ) {
833 global $wgUser, $wgLang, $wgLang;
834 $sk = $wgUser->getSkin();
835 $isDeleted = !( $rev->getId() && $rev->getTitle() );
836 if( $isDeleted ) {
837 /// @fixme $rev->getTitle() is null for deleted revs...?
838 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
839 $targetQuery = array(
840 'target' => $this->mTargetObj->getPrefixedUrl(),
841 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
842 );
843 } else {
844 /// @fixme getId() may return non-zero for deleted revs...
845 $targetPage = $rev->getTitle();
846 $targetQuery = array( 'oldid' => $rev->getId() );
847 }
848 // Add show/hide link if available
849 if( $wgUser->isAllowed( 'deleterevision' ) ) {
850 // If revision was hidden from sysops
851 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
852 $del = ' ' . Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
853 '(' . wfMsgHtml('rev-delundel') . ')' );
854 // Otherwise, show the link...
855 } else {
856 $query = array(
857 'type' => 'archive',
858 'target' => $this->mTargetObj->getPrefixedDbkey(),
859 'ids' => $rev->getTimestamp() );
860 $del = ' ' . $sk->revDeleteLink( $query,
861 $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
862 }
863 } else {
864 $del = '';
865 }
866 return
867 '<div id="mw-diff-'.$prefix.'title1"><strong>' .
868 $sk->link(
869 $targetPage,
870 wfMsgHtml(
871 'revisionasof',
872 htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) )
873 ),
874 array(),
875 $targetQuery
876 ) .
877 '</strong></div>' .
878 '<div id="mw-diff-'.$prefix.'title2">' .
879 $sk->revUserTools( $rev ) . '<br/>' .
880 '</div>' .
881 '<div id="mw-diff-'.$prefix.'title3">' .
882 $sk->revComment( $rev ) . $del . '<br/>' .
883 '</div>';
884 }
885
886 /**
887 * Show a form confirming whether a tokenless user really wants to see a file
888 */
889 private function showFileConfirmationForm( $key ) {
890 global $wgOut, $wgUser, $wgLang;
891 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
892 $wgOut->addWikiMsg( 'undelete-show-file-confirm',
893 $this->mTargetObj->getText(),
894 $wgLang->date( $file->getTimestamp() ),
895 $wgLang->time( $file->getTimestamp() ) );
896 $wgOut->addHTML(
897 Xml::openElement( 'form', array(
898 'method' => 'POST',
899 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
900 'target=' . urlencode( $this->mTarget ) .
901 '&file=' . urlencode( $key ) .
902 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
903 )
904 ) .
905 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
906 '</form>'
907 );
908 }
909
910 /**
911 * Show a deleted file version requested by the visitor.
912 */
913 private function showFile( $key ) {
914 global $wgOut, $wgRequest;
915 $wgOut->disable();
916
917 # We mustn't allow the output to be Squid cached, otherwise
918 # if an admin previews a deleted image, and it's cached, then
919 # a user without appropriate permissions can toddle off and
920 # nab the image, and Squid will serve it
921 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
922 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
923 $wgRequest->response()->header( 'Pragma: no-cache' );
924
925 global $IP;
926 require_once( "$IP/includes/StreamFile.php" );
927 $repo = RepoGroup::singleton()->getLocalRepo();
928 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
929 wfStreamFile( $path );
930 }
931
932 private function showHistory( ) {
933 global $wgLang, $wgUser, $wgOut;
934
935 $sk = $wgUser->getSkin();
936 if( $this->mAllowed ) {
937 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
938 } else {
939 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
940 }
941
942 $wgOut->addWikiMsg( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() );
943
944 $archive = new PageArchive( $this->mTargetObj );
945 /*
946 $text = $archive->getLastRevisionText();
947 if( is_null( $text ) ) {
948 $wgOut->addWikiMsg( "nohistory" );
949 return;
950 }
951 */
952 if ( $this->mAllowed ) {
953 $wgOut->addWikiMsg( "undeletehistory" );
954 $wgOut->addWikiMsg( "undeleterevdel" );
955 } else {
956 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
957 }
958
959 # List all stored revisions
960 $revisions = $archive->listRevisions();
961 $files = $archive->listFiles();
962
963 $haveRevisions = $revisions && $revisions->numRows() > 0;
964 $haveFiles = $files && $files->numRows() > 0;
965
966 # Batch existence check on user and talk pages
967 if( $haveRevisions ) {
968 $batch = new LinkBatch();
969 while( $row = $revisions->fetchObject() ) {
970 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
971 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
972 }
973 $batch->execute();
974 $revisions->seek( 0 );
975 }
976 if( $haveFiles ) {
977 $batch = new LinkBatch();
978 while( $row = $files->fetchObject() ) {
979 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
980 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
981 }
982 $batch->execute();
983 $files->seek( 0 );
984 }
985
986 if ( $this->mAllowed ) {
987 $titleObj = SpecialPage::getTitleFor( "Undelete" );
988 $action = $titleObj->getLocalURL( "action=submit" );
989 # Start the form here
990 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
991 $wgOut->addHTML( $top );
992 }
993
994 # Show relevant lines from the deletion log:
995 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
996 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
997 # Show relevant lines from the suppression log:
998 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
999 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
1000 LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
1001 }
1002
1003 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
1004 # Format the user-visible controls (comment field, submission button)
1005 # in a nice little table
1006 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
1007 $unsuppressBox =
1008 "<tr>
1009 <td>&nbsp;</td>
1010 <td class='mw-input'>" .
1011 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
1012 'mw-undelete-unsuppress', $this->mUnsuppress ).
1013 "</td>
1014 </tr>";
1015 } else {
1016 $unsuppressBox = "";
1017 }
1018 $table =
1019 Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
1020 Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
1021 "<tr>
1022 <td colspan='2'>" .
1023 wfMsgWikiHtml( 'undeleteextrahelp' ) .
1024 "</td>
1025 </tr>
1026 <tr>
1027 <td class='mw-label'>" .
1028 Xml::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
1029 "</td>
1030 <td class='mw-input'>" .
1031 Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
1032 "</td>
1033 </tr>
1034 <tr>
1035 <td>&nbsp;</td>
1036 <td class='mw-submit'>" .
1037 Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
1038 Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) . ' ' .
1039 Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
1040 "</td>
1041 </tr>" .
1042 $unsuppressBox .
1043 Xml::closeElement( 'table' ) .
1044 Xml::closeElement( 'fieldset' );
1045
1046 $wgOut->addHTML( $table );
1047 }
1048
1049 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
1050
1051 if( $haveRevisions ) {
1052 # The page's stored (deleted) history:
1053 $wgOut->addHTML("<ul>");
1054 $target = urlencode( $this->mTarget );
1055 $remaining = $revisions->numRows();
1056 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
1057
1058 while( $row = $revisions->fetchObject() ) {
1059 $remaining--;
1060 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
1061 }
1062 $revisions->free();
1063 $wgOut->addHTML("</ul>");
1064 } else {
1065 $wgOut->addWikiMsg( "nohistory" );
1066 }
1067
1068 if( $haveFiles ) {
1069 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1070 $wgOut->addHTML( "<ul>" );
1071 while( $row = $files->fetchObject() ) {
1072 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
1073 }
1074 $files->free();
1075 $wgOut->addHTML( "</ul>" );
1076 }
1077
1078 if ( $this->mAllowed ) {
1079 # Slip in the hidden controls here
1080 $misc = Xml::hidden( 'target', $this->mTarget );
1081 $misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
1082 $misc .= Xml::closeElement( 'form' );
1083 $wgOut->addHTML( $misc );
1084 }
1085
1086 return true;
1087 }
1088
1089 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
1090 global $wgUser, $wgLang;
1091
1092 $rev = Revision::newFromArchiveRow( $row,
1093 array( 'page' => $this->mTargetObj->getArticleId() ) );
1094 $stxt = '';
1095 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1096 if( $this->mAllowed ) {
1097 if( $this->mInvert){
1098 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1099 $checkBox = Xml::check( "ts$ts");
1100 } else {
1101 $checkBox = Xml::check( "ts$ts", true );
1102 }
1103 } else {
1104 $checkBox = Xml::check( "ts$ts" );
1105 }
1106 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1107 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1108 # Last link
1109 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1110 $last = wfMsgHtml('diff');
1111 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
1112 $last = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml('diff'),
1113 "target=" . $this->mTargetObj->getPrefixedUrl() . "&timestamp=$ts&diff=prev" );
1114 } else {
1115 $last = wfMsgHtml('diff');
1116 }
1117 } else {
1118 $checkBox = '';
1119 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1120 $last = wfMsgHtml('diff');
1121 }
1122 $userLink = $sk->revUserTools( $rev );
1123
1124 if(!is_null($size = $row->ar_len)) {
1125 $stxt = $sk->formatRevisionSize( $size );
1126 }
1127 $comment = $sk->revComment( $rev );
1128 $revdlink = '';
1129 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1130 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1131 // If revision was hidden from sysops
1132 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
1133 '('.wfMsgHtml('rev-delundel').')' );
1134 } else {
1135 $query = array(
1136 'type' => 'archive',
1137 'target' => $this->mTargetObj->getPrefixedDBkey(),
1138 'ids' => $ts
1139 );
1140 $revdlink = $sk->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
1141 }
1142 }
1143
1144 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
1145 }
1146
1147 private function formatFileRow( $row, $sk ) {
1148 global $wgUser, $wgLang;
1149
1150 $file = ArchivedFile::newFromRow( $row );
1151
1152 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
1153 if( $this->mAllowed && $row->fa_storage_key ) {
1154 $checkBox = Xml::check( "fileid" . $row->fa_id );
1155 $key = urlencode( $row->fa_storage_key );
1156 $target = urlencode( $this->mTarget );
1157 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1158 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
1159 } else {
1160 $checkBox = '';
1161 $pageLink = $wgLang->timeanddate( $ts, true );
1162 }
1163 $userLink = $this->getFileUser( $file, $sk );
1164 $data =
1165 wfMsg( 'widthheight',
1166 $wgLang->formatNum( $row->fa_width ),
1167 $wgLang->formatNum( $row->fa_height ) ) .
1168 ' (' .
1169 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
1170 ')';
1171 $data = htmlspecialchars( $data );
1172 $comment = $this->getFileComment( $file, $sk );
1173 $revdlink = '';
1174 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1175 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
1176 // If revision was hidden from sysops
1177 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml('rev-delundel').')' );
1178 } else {
1179 $query = array(
1180 'type' => 'filearchive',
1181 'target' => $this->mTargetObj->getPrefixedDBkey(),
1182 'ids' => $row->fa_id
1183 );
1184 $revdlink = $sk->revDeleteLink( $query, $file->isDeleted( File::DELETED_RESTRICTED ) );
1185 }
1186 }
1187 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1188 }
1189
1190 /**
1191 * Fetch revision text link if it's available to all users
1192 * @return string
1193 */
1194 function getPageLink( $rev, $titleObj, $ts, $sk ) {
1195 global $wgLang;
1196
1197 $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1198
1199 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
1200 return '<span class="history-deleted">' . $time . '</span>';
1201 } else {
1202 $link = $sk->makeKnownLinkObj( $titleObj, $time,
1203 "target=".$this->mTargetObj->getPrefixedUrl()."&timestamp=$ts" );
1204 if( $rev->isDeleted(Revision::DELETED_TEXT) )
1205 $link = '<span class="history-deleted">' . $link . '</span>';
1206 return $link;
1207 }
1208 }
1209
1210 /**
1211 * Fetch image view link if it's available to all users
1212 * @return string
1213 */
1214 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1215 global $wgLang, $wgUser;
1216
1217 if( !$file->userCan(File::DELETED_FILE) ) {
1218 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1219 } else {
1220 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1221 "target=".$this->mTargetObj->getPrefixedUrl().
1222 "&file=$key" .
1223 "&token=" . urlencode( $wgUser->editToken( $key ) ) );
1224 if( $file->isDeleted(File::DELETED_FILE) )
1225 $link = '<span class="history-deleted">' . $link . '</span>';
1226 return $link;
1227 }
1228 }
1229
1230 /**
1231 * Fetch file's user id if it's available to this user
1232 * @return string
1233 */
1234 function getFileUser( $file, $sk ) {
1235 if( !$file->userCan(File::DELETED_USER) ) {
1236 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
1237 } else {
1238 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
1239 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1240 if( $file->isDeleted(File::DELETED_USER) )
1241 $link = '<span class="history-deleted">' . $link . '</span>';
1242 return $link;
1243 }
1244 }
1245
1246 /**
1247 * Fetch file upload comment if it's available to this user
1248 * @return string
1249 */
1250 function getFileComment( $file, $sk ) {
1251 if( !$file->userCan(File::DELETED_COMMENT) ) {
1252 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
1253 } else {
1254 $link = $sk->commentBlock( $file->getRawDescription() );
1255 if( $file->isDeleted(File::DELETED_COMMENT) )
1256 $link = '<span class="history-deleted">' . $link . '</span>';
1257 return $link;
1258 }
1259 }
1260
1261 function undelete() {
1262 global $wgOut, $wgUser;
1263 if ( wfReadOnly() ) {
1264 $wgOut->readOnlyPage();
1265 return;
1266 }
1267 if( !is_null( $this->mTargetObj ) ) {
1268 $archive = new PageArchive( $this->mTargetObj );
1269 $ok = $archive->undelete(
1270 $this->mTargetTimestamp,
1271 $this->mComment,
1272 $this->mFileVersions,
1273 $this->mUnsuppress );
1274
1275 if( is_array($ok) ) {
1276 if ( $ok[1] ) // Undeleted file count
1277 wfRunHooks( 'FileUndeleteComplete', array(
1278 $this->mTargetObj, $this->mFileVersions,
1279 $wgUser, $this->mComment) );
1280
1281 $skin = $wgUser->getSkin();
1282 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
1283 $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
1284 } else {
1285 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1286 $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
1287 }
1288
1289 // Show file deletion warnings and errors
1290 $status = $archive->getFileStatus();
1291 if( $status && !$status->isGood() ) {
1292 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1293 }
1294 } else {
1295 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1296 }
1297 return false;
1298 }
1299 }