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