* Removed duplicate revdelete links
[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, $comment );
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, $comment = '' ) {
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'; // 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
396 );
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;
411 }
412 } else {
413 # Have to create a new article...
414 $makepage = true;
415 $previousRevId = 0;
416 $previousTimestamp = 0;
417 }
418
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 ) ) );
426
427 $oldones = "ar_timestamp IN ( {$oldts} )";
428 }
429
430 /**
431 * Select each archived revision...
432 */
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' )
453 );
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; // ???
459 }
460
461 $ret->seek( $rev_count - 1 ); // move to last
462 $row = $ret->fetchObject(); // get newest archived rev
463 $ret->seek( 0 ); // move back
464
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!
469 }
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!
479 }
480 }
481 }
482
483 $revision = null;
484 $restored = 0;
485
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
491 }
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 ) );
499
500 $revision->insertOn( $dbw );
501 $restored++;
502
503 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
504 }
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__ );
512
513 // Was anything restored at all?
514 if( $restored == 0 )
515 return 0;
516
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 );
523 }
524
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 );
531 }
532
533 if( $this->title->getNamespace() == NS_FILE ) {
534 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
535 $update->doUpdate();
536 }
537 } else {
538 // Revision couldn't be created. This is very weird
539 return self::UNDELETE_UNKNOWNERR;
540 }
541
542 return $restored;
543 }
544
545 function getFileStatus() { return $this->fileStatus; }
546 }
547
548 /**
549 * The HTML form for Special:Undelete, which allows users with the appropriate
550 * permissions to view and restore deleted content.
551 * @ingroup SpecialPage
552 */
553 class UndeleteForm {
554 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
555 var $mTargetTimestamp, $mAllowed, $mComment, $mToken;
556
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' );
565
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' );
575
576 if( $par != "" ) {
577 $this->mTarget = $par;
578 }
579 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
580 $this->mAllowed = true;
581 } else {
582 $this->mAllowed = false;
583 $this->mTimestamp = '';
584 $this->mRestore = false;
585 }
586 if ( $this->mTarget !== "" ) {
587 $this->mTargetObj = Title::newFromURL( $this->mTarget );
588 } else {
589 $this->mTargetObj = NULL;
590 }
591 if( $this->mRestore || $this->mInvert ) {
592 $timestamps = array();
593 $this->mFileVersions = array();
594 foreach( $_REQUEST as $key => $val ) {
595 $matches = array();
596 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
597 array_push( $timestamps, $matches[1] );
598 }
599
600 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
601 $this->mFileVersions[] = intval( $matches[1] );
602 }
603 }
604 rsort( $timestamps );
605 $this->mTargetTimestamp = $timestamps;
606 }
607 }
608
609 function execute() {
610 global $wgOut, $wgUser;
611 if ( $this->mAllowed ) {
612 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
613 } else {
614 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
615 }
616
617 if( is_null( $this->mTargetObj ) ) {
618 # Not all users can just browse every deleted page from the list
619 if( $wgUser->isAllowed( 'browsearchive' ) ) {
620 $this->showSearchForm();
621
622 # List undeletable articles
623 if( $this->mSearchPrefix ) {
624 $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
625 $this->showList( $result );
626 }
627 } else {
628 $wgOut->addWikiMsg( 'undelete-header' );
629 }
630 return;
631 }
632 if( $this->mTimestamp !== '' ) {
633 return $this->showRevision( $this->mTimestamp );
634 }
635 if( $this->mFile !== null ) {
636 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
637 // Check if user is allowed to see this file
638 if( !$file->userCan( File::DELETED_FILE ) ) {
639 $wgOut->permissionRequired( 'suppressrevision' );
640 return false;
641 } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
642 $this->showFileConfirmationForm( $this->mFile );
643 return false;
644 } else {
645 return $this->showFile( $this->mFile );
646 }
647 }
648 if( $this->mRestore && $this->mAction == "submit" ) {
649 global $wgUploadMaintenance;
650 if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
651 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n", array( 'filedelete-maintenance' ) );
652 return;
653 }
654 return $this->undelete();
655 }
656 if( $this->mInvert && $this->mAction == "submit" ) {
657 return $this->showHistory( );
658 }
659 return $this->showHistory();
660 }
661
662 function showSearchForm() {
663 global $wgOut, $wgScript;
664 $wgOut->addWikiMsg( 'undelete-header' );
665
666 $wgOut->addHTML(
667 Xml::openElement( 'form', array(
668 'method' => 'get',
669 'action' => $wgScript ) ) .
670 Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
671 Xml::hidden( 'title',
672 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
673 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
674 'prefix', 'prefix', 20,
675 $this->mSearchPrefix ) . ' ' .
676 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
677 Xml::closeElement( 'fieldset' ) .
678 Xml::closeElement( 'form' )
679 );
680 }
681
682 // Generic list of deleted pages
683 private function showList( $result ) {
684 global $wgLang, $wgContLang, $wgUser, $wgOut;
685
686 if( $result->numRows() == 0 ) {
687 $wgOut->addWikiMsg( 'undelete-no-results' );
688 return;
689 }
690
691 $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
692
693 $sk = $wgUser->getSkin();
694 $undelete = SpecialPage::getTitleFor( 'Undelete' );
695 $wgOut->addHTML( "<ul>\n" );
696 while( $row = $result->fetchObject() ) {
697 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
698 $link = $sk->linkKnown(
699 $undelete,
700 htmlspecialchars( $title->getPrefixedText() ),
701 array(),
702 array( 'target' => $title->getPrefixedText() )
703 );
704 $revs = wfMsgExt( 'undeleterevisions',
705 array( 'parseinline' ),
706 $wgLang->formatNum( $row->count ) );
707 $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
708 }
709 $result->free();
710 $wgOut->addHTML( "</ul>\n" );
711
712 return true;
713 }
714
715 private function showRevision( $timestamp ) {
716 global $wgLang, $wgUser, $wgOut;
717 $self = SpecialPage::getTitleFor( 'Undelete' );
718 $skin = $wgUser->getSkin();
719
720 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
721
722 $archive = new PageArchive( $this->mTargetObj );
723 $rev = $archive->getRevision( $timestamp );
724
725 if( !$rev ) {
726 $wgOut->addWikiMsg( 'undeleterevision-missing' );
727 return;
728 }
729
730 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
731 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
732 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
733 return;
734 } else {
735 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
736 $wgOut->addHTML( '<br/>' );
737 // and we are allowed to see...
738 }
739 }
740
741 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
742
743 $link = $skin->linkKnown(
744 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
745 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
746 );
747
748 if( $this->mDiff ) {
749 $previousRev = $archive->getPreviousRevision( $timestamp );
750 if( $previousRev ) {
751 $this->showDiff( $previousRev, $rev );
752 if( $wgUser->getOption( 'diffonly' ) ) {
753 return;
754 } else {
755 $wgOut->addHTML( '<hr />' );
756 }
757 } else {
758 $wgOut->addWikiMsg( 'undelete-nodiff' );
759 }
760 }
761
762 // date and time are separate parameters to facilitate localisation.
763 // $time is kept for backward compat reasons.
764 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
765 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
766 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
767 $user = $skin->revUserTools( $rev );
768
769 if( $this->mPreview ) {
770 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
771 } else {
772 $openDiv = '<div id="mw-undelete-revision">';
773 }
774
775 $revdlink = '';
776 // Diffs already have revision delete links
777 if( !$this->mDiff && $wgUser->isAllowed( 'deleterevision' ) ) {
778 if( !$rev->userCan(Revision::DELETED_RESTRICTED ) ) {
779 // If revision was hidden from sysops
780 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
781 '('.wfMsgHtml('rev-delundel').')' );
782 } else {
783 $query = array(
784 'type' => 'archive',
785 'target' => $this->mTargetObj->getPrefixedDBkey(),
786 'ids' => $rev->getTimestamp()
787 );
788 $revdlink = $skin->revDeleteLink( $query, $rev->isDeleted( File::DELETED_RESTRICTED ) );
789 }
790 }
791
792 $wgOut->addHTML( $openDiv . $revdlink . wfMsgWikiHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</div>' );
793 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
794
795 if( $this->mPreview ) {
796 //Hide [edit]s
797 $popts = $wgOut->parserOptions();
798 $popts->setEditSection( false );
799 $wgOut->parserOptions( $popts );
800 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
801 }
802
803 $wgOut->addHTML(
804 Xml::element( 'textarea', array(
805 'readonly' => 'readonly',
806 'cols' => intval( $wgUser->getOption( 'cols' ) ),
807 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
808 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
809 Xml::openElement( 'div' ) .
810 Xml::openElement( 'form', array(
811 'method' => 'post',
812 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
813 Xml::element( 'input', array(
814 'type' => 'hidden',
815 'name' => 'target',
816 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
817 Xml::element( 'input', array(
818 'type' => 'hidden',
819 'name' => 'timestamp',
820 'value' => $timestamp ) ) .
821 Xml::element( 'input', array(
822 'type' => 'hidden',
823 'name' => 'wpEditToken',
824 'value' => $wgUser->editToken() ) ) .
825 Xml::element( 'input', array(
826 'type' => 'submit',
827 'name' => 'preview',
828 'value' => wfMsg( 'showpreview' ) ) ) .
829 Xml::element( 'input', array(
830 'name' => 'diff',
831 'type' => 'submit',
832 'value' => wfMsg( 'showdiff' ) ) ) .
833 Xml::closeElement( 'form' ) .
834 Xml::closeElement( 'div' ) );
835 }
836
837 /**
838 * Build a diff display between this and the previous either deleted
839 * or non-deleted edit.
840 * @param Revision $previousRev
841 * @param Revision $currentRev
842 * @return string HTML
843 */
844 function showDiff( $previousRev, $currentRev ) {
845 global $wgOut;
846
847 $diffEngine = new DifferenceEngine();
848 $diffEngine->showDiffStyle();
849 $wgOut->addHTML(
850 "<div>" .
851 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
852 "<col class='diff-marker' />" .
853 "<col class='diff-content' />" .
854 "<col class='diff-marker' />" .
855 "<col class='diff-content' />" .
856 "<tr>" .
857 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
858 $this->diffHeader( $previousRev, 'o' ) .
859 "</td>\n" .
860 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
861 $this->diffHeader( $currentRev, 'n' ) .
862 "</td>\n" .
863 "</tr>" .
864 $diffEngine->generateDiffBody(
865 $previousRev->getText(), $currentRev->getText() ) .
866 "</table>" .
867 "</div>\n"
868 );
869 }
870
871 private function diffHeader( $rev, $prefix ) {
872 global $wgUser, $wgLang, $wgLang;
873 $sk = $wgUser->getSkin();
874 $isDeleted = !( $rev->getId() && $rev->getTitle() );
875 if( $isDeleted ) {
876 /// @fixme $rev->getTitle() is null for deleted revs...?
877 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
878 $targetQuery = array(
879 'target' => $this->mTargetObj->getPrefixedText(),
880 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
881 );
882 } else {
883 /// @fixme getId() may return non-zero for deleted revs...
884 $targetPage = $rev->getTitle();
885 $targetQuery = array( 'oldid' => $rev->getId() );
886 }
887 // Add show/hide link if available
888 if( $wgUser->isAllowed( 'deleterevision' ) ) {
889 // If revision was hidden from sysops
890 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
891 $del = ' ' . Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
892 '(' . wfMsgHtml('rev-delundel') . ')' );
893 // Otherwise, show the link...
894 } else {
895 $query = array(
896 'type' => 'archive',
897 'target' => $this->mTargetObj->getPrefixedDbkey(),
898 'ids' => $rev->getTimestamp() );
899 $del = ' ' . $sk->revDeleteLink( $query,
900 $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
901 }
902 } else {
903 $del = '';
904 }
905 return
906 '<div id="mw-diff-'.$prefix.'title1"><strong>' .
907 $sk->link(
908 $targetPage,
909 wfMsgHtml(
910 'revisionasof',
911 htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
912 htmlspecialchars( $wgLang->date( $rev->getTimestamp(), true ) ),
913 htmlspecialchars( $wgLang->time( $rev->getTimestamp(), true ) )
914 ),
915 array(),
916 $targetQuery
917 ) .
918 '</strong></div>' .
919 '<div id="mw-diff-'.$prefix.'title2">' .
920 $sk->revUserTools( $rev ) . '<br/>' .
921 '</div>' .
922 '<div id="mw-diff-'.$prefix.'title3">' .
923 $sk->revComment( $rev ) . $del . '<br/>' .
924 '</div>';
925 }
926
927 /**
928 * Show a form confirming whether a tokenless user really wants to see a file
929 */
930 private function showFileConfirmationForm( $key ) {
931 global $wgOut, $wgUser, $wgLang;
932 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
933 $wgOut->addWikiMsg( 'undelete-show-file-confirm',
934 $this->mTargetObj->getText(),
935 $wgLang->date( $file->getTimestamp() ),
936 $wgLang->time( $file->getTimestamp() ) );
937 $wgOut->addHTML(
938 Xml::openElement( 'form', array(
939 'method' => 'POST',
940 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
941 'target=' . urlencode( $this->mTarget ) .
942 '&file=' . urlencode( $key ) .
943 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
944 )
945 ) .
946 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
947 '</form>'
948 );
949 }
950
951 /**
952 * Show a deleted file version requested by the visitor.
953 */
954 private function showFile( $key ) {
955 global $wgOut, $wgRequest;
956 $wgOut->disable();
957
958 # We mustn't allow the output to be Squid cached, otherwise
959 # if an admin previews a deleted image, and it's cached, then
960 # a user without appropriate permissions can toddle off and
961 # nab the image, and Squid will serve it
962 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
963 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
964 $wgRequest->response()->header( 'Pragma: no-cache' );
965
966 global $IP;
967 require_once( "$IP/includes/StreamFile.php" );
968 $repo = RepoGroup::singleton()->getLocalRepo();
969 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
970 wfStreamFile( $path );
971 }
972
973 private function showHistory( ) {
974 global $wgLang, $wgUser, $wgOut;
975
976 $sk = $wgUser->getSkin();
977 if( $this->mAllowed ) {
978 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
979 } else {
980 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
981 }
982
983 $wgOut->wrapWikiMsg( "<div class='mw-undelete-pagetitle'>\n$1</div>\n", array ( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() ) );
984
985 $archive = new PageArchive( $this->mTargetObj );
986 /*
987 $text = $archive->getLastRevisionText();
988 if( is_null( $text ) ) {
989 $wgOut->addWikiMsg( "nohistory" );
990 return;
991 }
992 */
993 $wgOut->addHTML( '<div class="mw-undelete-history">' );
994 if ( $this->mAllowed ) {
995 $wgOut->addWikiMsg( "undeletehistory" );
996 $wgOut->addWikiMsg( "undeleterevdel" );
997 } else {
998 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
999 }
1000 $wgOut->addHTML( '</div>' );
1001
1002 # List all stored revisions
1003 $revisions = $archive->listRevisions();
1004 $files = $archive->listFiles();
1005
1006 $haveRevisions = $revisions && $revisions->numRows() > 0;
1007 $haveFiles = $files && $files->numRows() > 0;
1008
1009 # Batch existence check on user and talk pages
1010 if( $haveRevisions ) {
1011 $batch = new LinkBatch();
1012 while( $row = $revisions->fetchObject() ) {
1013 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
1014 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
1015 }
1016 $batch->execute();
1017 $revisions->seek( 0 );
1018 }
1019 if( $haveFiles ) {
1020 $batch = new LinkBatch();
1021 while( $row = $files->fetchObject() ) {
1022 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
1023 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
1024 }
1025 $batch->execute();
1026 $files->seek( 0 );
1027 }
1028
1029 if ( $this->mAllowed ) {
1030 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1031 $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
1032 # Start the form here
1033 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
1034 $wgOut->addHTML( $top );
1035 }
1036
1037 # Show relevant lines from the deletion log:
1038 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
1039 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
1040 # Show relevant lines from the suppression log:
1041 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
1042 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
1043 LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
1044 }
1045
1046 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
1047 # Format the user-visible controls (comment field, submission button)
1048 # in a nice little table
1049 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
1050 $unsuppressBox =
1051 "<tr>
1052 <td>&nbsp;</td>
1053 <td class='mw-input'>" .
1054 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
1055 'mw-undelete-unsuppress', $this->mUnsuppress ).
1056 "</td>
1057 </tr>";
1058 } else {
1059 $unsuppressBox = "";
1060 }
1061 $table =
1062 Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
1063 Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
1064 "<tr>
1065 <td colspan='2' class='mw-undelete-extrahelp'>" .
1066 wfMsgWikiHtml( 'undeleteextrahelp' ) .
1067 "</td>
1068 </tr>
1069 <tr>
1070 <td class='mw-label'>" .
1071 Xml::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
1072 "</td>
1073 <td class='mw-input'>" .
1074 Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
1075 "</td>
1076 </tr>
1077 <tr>
1078 <td>&nbsp;</td>
1079 <td class='mw-submit'>" .
1080 Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
1081 Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) . ' ' .
1082 Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
1083 "</td>
1084 </tr>" .
1085 $unsuppressBox .
1086 Xml::closeElement( 'table' ) .
1087 Xml::closeElement( 'fieldset' );
1088
1089 $wgOut->addHTML( $table );
1090 }
1091
1092 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
1093
1094 if( $haveRevisions ) {
1095 # The page's stored (deleted) history:
1096 $wgOut->addHTML("<ul>");
1097 $target = urlencode( $this->mTarget );
1098 $remaining = $revisions->numRows();
1099 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
1100
1101 while( $row = $revisions->fetchObject() ) {
1102 $remaining--;
1103 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
1104 }
1105 $revisions->free();
1106 $wgOut->addHTML("</ul>");
1107 } else {
1108 $wgOut->addWikiMsg( "nohistory" );
1109 }
1110
1111 if( $haveFiles ) {
1112 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1113 $wgOut->addHTML( "<ul>" );
1114 while( $row = $files->fetchObject() ) {
1115 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
1116 }
1117 $files->free();
1118 $wgOut->addHTML( "</ul>" );
1119 }
1120
1121 if ( $this->mAllowed ) {
1122 # Slip in the hidden controls here
1123 $misc = Xml::hidden( 'target', $this->mTarget );
1124 $misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
1125 $misc .= Xml::closeElement( 'form' );
1126 $wgOut->addHTML( $misc );
1127 }
1128
1129 return true;
1130 }
1131
1132 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
1133 global $wgUser, $wgLang;
1134
1135 $rev = Revision::newFromArchiveRow( $row,
1136 array( 'page' => $this->mTargetObj->getArticleId() ) );
1137 $stxt = '';
1138 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1139 if( $this->mAllowed ) {
1140 if( $this->mInvert){
1141 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1142 $checkBox = Xml::check( "ts$ts");
1143 } else {
1144 $checkBox = Xml::check( "ts$ts", true );
1145 }
1146 } else {
1147 $checkBox = Xml::check( "ts$ts" );
1148 }
1149 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1150 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1151 # Last link
1152 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1153 $last = wfMsgHtml('diff');
1154 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
1155 $last = $sk->linkKnown(
1156 $titleObj,
1157 wfMsgHtml('diff'),
1158 array(),
1159 array(
1160 'target' => $this->mTargetObj->getPrefixedText(),
1161 'timestamp' => $ts,
1162 'diff' => 'prev'
1163 )
1164 );
1165 } else {
1166 $last = wfMsgHtml('diff');
1167 }
1168 } else {
1169 $checkBox = '';
1170 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1171 $last = wfMsgHtml('diff');
1172 }
1173 $userLink = $sk->revUserTools( $rev );
1174
1175 if(!is_null($size = $row->ar_len)) {
1176 $stxt = $sk->formatRevisionSize( $size );
1177 }
1178 $comment = $sk->revComment( $rev );
1179 $revdlink = '';
1180 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1181 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1182 // If revision was hidden from sysops
1183 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
1184 '('.wfMsgHtml('rev-delundel').')' );
1185 } else {
1186 $query = array(
1187 'type' => 'archive',
1188 'target' => $this->mTargetObj->getPrefixedDBkey(),
1189 'ids' => $ts
1190 );
1191 $revdlink = $sk->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
1192 }
1193 }
1194
1195 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
1196 }
1197
1198 private function formatFileRow( $row, $sk ) {
1199 global $wgUser, $wgLang;
1200
1201 $file = ArchivedFile::newFromRow( $row );
1202
1203 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
1204 if( $this->mAllowed && $row->fa_storage_key ) {
1205 $checkBox = Xml::check( "fileid" . $row->fa_id );
1206 $key = urlencode( $row->fa_storage_key );
1207 $target = urlencode( $this->mTarget );
1208 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1209 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
1210 } else {
1211 $checkBox = '';
1212 $pageLink = $wgLang->timeanddate( $ts, true );
1213 }
1214 $userLink = $this->getFileUser( $file, $sk );
1215 $data =
1216 wfMsg( 'widthheight',
1217 $wgLang->formatNum( $row->fa_width ),
1218 $wgLang->formatNum( $row->fa_height ) ) .
1219 ' (' .
1220 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
1221 ')';
1222 $data = htmlspecialchars( $data );
1223 $comment = $this->getFileComment( $file, $sk );
1224 $revdlink = '';
1225 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1226 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
1227 // If revision was hidden from sysops
1228 $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml('rev-delundel').')' );
1229 } else {
1230 $query = array(
1231 'type' => 'filearchive',
1232 'target' => $this->mTargetObj->getPrefixedDBkey(),
1233 'ids' => $row->fa_id
1234 );
1235 $revdlink = $sk->revDeleteLink( $query, $file->isDeleted( File::DELETED_RESTRICTED ) );
1236 }
1237 }
1238 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1239 }
1240
1241 /**
1242 * Fetch revision text link if it's available to all users
1243 * @return string
1244 */
1245 function getPageLink( $rev, $titleObj, $ts, $sk ) {
1246 global $wgLang;
1247
1248 $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1249
1250 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
1251 return '<span class="history-deleted">' . $time . '</span>';
1252 } else {
1253 $link = $sk->linkKnown(
1254 $titleObj,
1255 $time,
1256 array(),
1257 array(
1258 'target' => $this->mTargetObj->getPrefixedText(),
1259 'timestamp' => $ts
1260 )
1261 );
1262 if( $rev->isDeleted(Revision::DELETED_TEXT) )
1263 $link = '<span class="history-deleted">' . $link . '</span>';
1264 return $link;
1265 }
1266 }
1267
1268 /**
1269 * Fetch image view link if it's available to all users
1270 * @return string
1271 */
1272 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1273 global $wgLang, $wgUser;
1274
1275 if( !$file->userCan(File::DELETED_FILE) ) {
1276 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1277 } else {
1278 $link = $sk->linkKnown(
1279 $titleObj,
1280 $wgLang->timeanddate( $ts, true ),
1281 array(),
1282 array(
1283 'target' => $this->mTargetObj->getPrefixedText(),
1284 'file' => $key,
1285 'token' => $wgUser->editToken( $key )
1286 )
1287 );
1288 if( $file->isDeleted(File::DELETED_FILE) )
1289 $link = '<span class="history-deleted">' . $link . '</span>';
1290 return $link;
1291 }
1292 }
1293
1294 /**
1295 * Fetch file's user id if it's available to this user
1296 * @return string
1297 */
1298 function getFileUser( $file, $sk ) {
1299 if( !$file->userCan(File::DELETED_USER) ) {
1300 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
1301 } else {
1302 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
1303 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1304 if( $file->isDeleted(File::DELETED_USER) )
1305 $link = '<span class="history-deleted">' . $link . '</span>';
1306 return $link;
1307 }
1308 }
1309
1310 /**
1311 * Fetch file upload comment if it's available to this user
1312 * @return string
1313 */
1314 function getFileComment( $file, $sk ) {
1315 if( !$file->userCan(File::DELETED_COMMENT) ) {
1316 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
1317 } else {
1318 $link = $sk->commentBlock( $file->getRawDescription() );
1319 if( $file->isDeleted(File::DELETED_COMMENT) )
1320 $link = '<span class="history-deleted">' . $link . '</span>';
1321 return $link;
1322 }
1323 }
1324
1325 function undelete() {
1326 global $wgOut, $wgUser;
1327 if ( wfReadOnly() ) {
1328 $wgOut->readOnlyPage();
1329 return;
1330 }
1331 if( !is_null( $this->mTargetObj ) ) {
1332 $archive = new PageArchive( $this->mTargetObj );
1333 $ok = $archive->undelete(
1334 $this->mTargetTimestamp,
1335 $this->mComment,
1336 $this->mFileVersions,
1337 $this->mUnsuppress );
1338
1339 if( is_array($ok) ) {
1340 if ( $ok[1] ) // Undeleted file count
1341 wfRunHooks( 'FileUndeleteComplete', array(
1342 $this->mTargetObj, $this->mFileVersions,
1343 $wgUser, $this->mComment) );
1344
1345 $skin = $wgUser->getSkin();
1346 $link = $skin->linkKnown( $this->mTargetObj );
1347 $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
1348 } else {
1349 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1350 $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
1351 }
1352
1353 // Show file deletion warnings and errors
1354 $status = $archive->getFileStatus();
1355 if( $status && !$status->isGood() ) {
1356 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1357 }
1358 } else {
1359 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1360 }
1361 return false;
1362 }
1363 }