War on wfElement() and friends. Call the Xml members directly, rather than using...
[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 '<fieldset>' .
683 Xml::element( 'legend', array(),
684 wfMsg( 'undelete-search-box' ) ) .
685 Xml::hidden( 'title',
686 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
687 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
688 'prefix', 'prefix', 20,
689 $this->mSearchPrefix ) .
690 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
691 '</fieldset>' .
692 '</form>' );
693 }
694
695 // Generic list of deleted pages
696 private function showList( $result ) {
697 global $wgLang, $wgContLang, $wgUser, $wgOut;
698
699 if( $result->numRows() == 0 ) {
700 $wgOut->addWikiMsg( 'undelete-no-results' );
701 return;
702 }
703
704 $wgOut->addWikiMsg( "undeletepagetext" );
705
706 $sk = $wgUser->getSkin();
707 $undelete = SpecialPage::getTitleFor( 'Undelete' );
708 $wgOut->addHTML( "<ul>\n" );
709 while( $row = $result->fetchObject() ) {
710 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
711 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ),
712 'target=' . $title->getPrefixedUrl() );
713 #$revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
714 $revs = wfMsgExt( 'undeleterevisions',
715 array( 'parseinline' ),
716 $wgLang->formatNum( $row->count ) );
717 $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
718 }
719 $result->free();
720 $wgOut->addHTML( "</ul>\n" );
721
722 return true;
723 }
724
725 private function showRevision( $timestamp ) {
726 global $wgLang, $wgUser, $wgOut;
727 $self = SpecialPage::getTitleFor( 'Undelete' );
728 $skin = $wgUser->getSkin();
729
730 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
731
732 $archive = new PageArchive( $this->mTargetObj );
733 $rev = $archive->getRevision( $timestamp );
734
735 if( !$rev ) {
736 $wgOut->addWikiMsg( 'undeleterevision-missing' );
737 return;
738 }
739
740 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
741 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
742 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
743 return;
744 } else {
745 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
746 $wgOut->addHTML( '<br/>' );
747 // and we are allowed to see...
748 }
749 }
750
751 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
752
753 $link = $skin->makeKnownLinkObj(
754 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
755 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
756 );
757
758 if( $this->mDiff ) {
759 $previousRev = $archive->getPreviousRevision( $timestamp );
760 if( $previousRev ) {
761 $this->showDiff( $previousRev, $rev );
762 if( $wgUser->getOption( 'diffonly' ) ) {
763 return;
764 } else {
765 $wgOut->addHTML( '<hr />' );
766 }
767 } else {
768 $wgOut->addHTML( wfMsgHtml( 'undelete-nodiff' ) );
769 }
770 }
771
772 // date and time are separate parameters to facilitate localisation.
773 // $time is kept for backward compat reasons.
774 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
775 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
776 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
777 $user = $skin->revUserTools( $rev );
778
779 $wgOut->addHTML( '<p>' . wfMsgHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</p>' );
780
781 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
782
783 if( $this->mPreview ) {
784 $wgOut->addHTML( "<hr />\n" );
785
786 //Hide [edit]s
787 $popts = $wgOut->parserOptions();
788 $popts->setEditSection( false );
789 $wgOut->parserOptions( $popts );
790 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
791 }
792
793 $wgOut->addHTML(
794 Xml::element( 'textarea', array(
795 'readonly' => 'readonly',
796 'cols' => intval( $wgUser->getOption( 'cols' ) ),
797 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
798 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
799 Xml::openElement( 'div' ) .
800 Xml::openElement( 'form', array(
801 'method' => 'post',
802 'action' => $self->getLocalURL( "action=submit" ) ) ) .
803 Xml::element( 'input', array(
804 'type' => 'hidden',
805 'name' => 'target',
806 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
807 Xml::element( 'input', array(
808 'type' => 'hidden',
809 'name' => 'timestamp',
810 'value' => $timestamp ) ) .
811 Xml::element( 'input', array(
812 'type' => 'hidden',
813 'name' => 'wpEditToken',
814 'value' => $wgUser->editToken() ) ) .
815 Xml::element( 'input', array(
816 'type' => 'submit',
817 'name' => 'preview',
818 'value' => wfMsg( 'showpreview' ) ) ) .
819 Xml::element( 'input', array(
820 'name' => 'diff',
821 'type' => 'submit',
822 'value' => wfMsg( 'showdiff' ) ) ) .
823 Xml::closeElement( 'form' ) .
824 Xml::closeElement( 'div' ) );
825 }
826
827 /**
828 * Build a diff display between this and the previous either deleted
829 * or non-deleted edit.
830 * @param Revision $previousRev
831 * @param Revision $currentRev
832 * @return string HTML
833 */
834 function showDiff( $previousRev, $currentRev ) {
835 global $wgOut, $wgUser;
836
837 $diffEngine = new DifferenceEngine();
838 $diffEngine->showDiffStyle();
839 $wgOut->addHTML(
840 "<div>" .
841 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
842 "<col class='diff-marker' />" .
843 "<col class='diff-content' />" .
844 "<col class='diff-marker' />" .
845 "<col class='diff-content' />" .
846 "<tr>" .
847 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
848 $this->diffHeader( $previousRev, 'o' ) .
849 "</td>\n" .
850 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
851 $this->diffHeader( $currentRev, 'n' ) .
852 "</td>\n" .
853 "</tr>" .
854 $diffEngine->generateDiffBody(
855 $previousRev->getText(), $currentRev->getText() ) .
856 "</table>" .
857 "</div>\n" );
858
859 }
860
861 private function diffHeader( $rev, $prefix ) {
862 global $wgUser, $wgLang, $wgLang;
863 $sk = $wgUser->getSkin();
864 $isDeleted = !( $rev->getId() && $rev->getTitle() );
865 if( $isDeleted ) {
866 /// @fixme $rev->getTitle() is null for deleted revs...?
867 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
868 $targetQuery = 'target=' .
869 $this->mTargetObj->getPrefixedUrl() .
870 '&timestamp=' .
871 wfTimestamp( TS_MW, $rev->getTimestamp() );
872 } else {
873 /// @fixme getId() may return non-zero for deleted revs...
874 $targetPage = $rev->getTitle();
875 $targetQuery = 'oldid=' . $rev->getId();
876 }
877 return
878 '<div id="mw-diff-'.$prefix.'title1"><strong>' .
879 $sk->makeLinkObj( $targetPage,
880 wfMsgHtml( 'revisionasof',
881 $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
882 $targetQuery ) .
883 ( $isDeleted ? ' ' . wfMsgHtml( 'deletedrev' ) : '' ) .
884 '</strong></div>' .
885 '<div id="mw-diff-'.$prefix.'title2">' .
886 $sk->revUserTools( $rev ) . '<br/>' .
887 '</div>' .
888 '<div id="mw-diff-'.$prefix.'title3">' .
889 $sk->revComment( $rev ) . '<br/>' .
890 '</div>';
891 }
892
893 /**
894 * Show a form confirming whether a tokenless user really wants to see a file
895 */
896 private function showFileConfirmationForm( $key ) {
897 global $wgOut, $wgUser, $wgLang;
898 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
899 $wgOut->addWikiMsg( 'undelete-show-file-confirm',
900 $this->mTargetObj->getText(),
901 $wgLang->date( $file->getTimestamp() ),
902 $wgLang->time( $file->getTimestamp() ) );
903 $wgOut->addHTML(
904 Xml::openElement( 'form', array(
905 'method' => 'POST',
906 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
907 'target=' . urlencode( $this->mTarget ) .
908 '&file=' . urlencode( $key ) .
909 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
910 )
911 ) .
912 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
913 '</form>'
914 );
915 }
916
917 /**
918 * Show a deleted file version requested by the visitor.
919 */
920 private function showFile( $key ) {
921 global $wgOut, $wgRequest;
922 $wgOut->disable();
923
924 # We mustn't allow the output to be Squid cached, otherwise
925 # if an admin previews a deleted image, and it's cached, then
926 # a user without appropriate permissions can toddle off and
927 # nab the image, and Squid will serve it
928 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
929 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
930 $wgRequest->response()->header( 'Pragma: no-cache' );
931
932 $store = FileStore::get( 'deleted' );
933 $store->stream( $key );
934 }
935
936 private function showHistory( ) {
937 global $wgLang, $wgUser, $wgOut;
938
939 $sk = $wgUser->getSkin();
940 if( $this->mAllowed ) {
941 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
942 } else {
943 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
944 }
945
946 $wgOut->addWikiText( wfMsgHtml( 'undeletepagetitle', $this->mTargetObj->getPrefixedText()) );
947
948 $archive = new PageArchive( $this->mTargetObj );
949 /*
950 $text = $archive->getLastRevisionText();
951 if( is_null( $text ) ) {
952 $wgOut->addWikiMsg( "nohistory" );
953 return;
954 }
955 */
956 if ( $this->mAllowed ) {
957 $wgOut->addWikiMsg( "undeletehistory" );
958 $wgOut->addWikiMsg( "undeleterevdel" );
959 } else {
960 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
961 }
962
963 # List all stored revisions
964 $revisions = $archive->listRevisions();
965 $files = $archive->listFiles();
966
967 $haveRevisions = $revisions && $revisions->numRows() > 0;
968 $haveFiles = $files && $files->numRows() > 0;
969
970 # Batch existence check on user and talk pages
971 if( $haveRevisions ) {
972 $batch = new LinkBatch();
973 while( $row = $revisions->fetchObject() ) {
974 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
975 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
976 }
977 $batch->execute();
978 $revisions->seek( 0 );
979 }
980 if( $haveFiles ) {
981 $batch = new LinkBatch();
982 while( $row = $files->fetchObject() ) {
983 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
984 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
985 }
986 $batch->execute();
987 $files->seek( 0 );
988 }
989
990 if ( $this->mAllowed ) {
991 $titleObj = SpecialPage::getTitleFor( "Undelete" );
992 $action = $titleObj->getLocalURL( "action=submit" );
993 # Start the form here
994 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
995 $wgOut->addHTML( $top );
996 }
997
998 # Show relevant lines from the deletion log:
999 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
1000 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
1001
1002 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
1003 # Format the user-visible controls (comment field, submission button)
1004 # in a nice little table
1005 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
1006 $unsuppressBox =
1007 "<tr>
1008 <td>&nbsp;</td>
1009 <td class='mw-input'>" .
1010 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
1011 'mw-undelete-unsuppress', $this->mUnsuppress ).
1012 "</td>
1013 </tr>";
1014 } else {
1015 $unsuppressBox = "";
1016 }
1017 $table =
1018 Xml::openElement( 'fieldset' ) .
1019 Xml::element( 'legend', null, 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 = new Revision( array(
1093 'page' => $this->mTargetObj->getArticleId(),
1094 'comment' => $row->ar_comment,
1095 'user' => $row->ar_user,
1096 'user_text' => $row->ar_user_text,
1097 'timestamp' => $row->ar_timestamp,
1098 'minor_edit' => $row->ar_minor_edit,
1099 'deleted' => $row->ar_deleted,
1100 'len' => $row->ar_len ) );
1101
1102 $stxt = '';
1103 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1104 if( $this->mAllowed ) {
1105 if( $this->mInvert){
1106 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1107 $checkBox = Xml::check( "ts$ts");
1108 } else {
1109 $checkBox = Xml::check( "ts$ts", true );
1110 }
1111 } else {
1112 $checkBox = Xml::check( "ts$ts" );
1113 }
1114 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1115 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1116 # Last link
1117 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1118 $last = wfMsgHtml('diff');
1119 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
1120 $last = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml('diff'),
1121 "target=" . $this->mTargetObj->getPrefixedUrl() . "&timestamp=$ts&diff=prev" );
1122 } else {
1123 $last = wfMsgHtml('diff');
1124 }
1125 } else {
1126 $checkBox = '';
1127 $pageLink = $wgLang->timeanddate( $ts, true );
1128 $last = wfMsgHtml('diff');
1129 }
1130 $userLink = $sk->revUserTools( $rev );
1131
1132 if(!is_null($size = $row->ar_len)) {
1133 $stxt = $sk->formatRevisionSize( $size );
1134 }
1135 $comment = $sk->revComment( $rev );
1136 $revdlink = '';
1137 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1138 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1139 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1140 // If revision was hidden from sysops
1141 $del = wfMsgHtml('rev-delundel');
1142 } else {
1143 $del = $sk->makeKnownLinkObj( $revdel,
1144 wfMsgHtml('rev-delundel'),
1145 'target=' . $this->mTargetObj->getPrefixedUrl() . "&artimestamp=$ts" );
1146 // Bolden oversighted content
1147 if( $rev->isDeleted( Revision::DELETED_RESTRICTED ) )
1148 $del = "<strong>$del</strong>";
1149 }
1150 $revdlink = "<tt>(<small>$del</small>)</tt>";
1151 }
1152
1153 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
1154 }
1155
1156 private function formatFileRow( $row, $sk ) {
1157 global $wgUser, $wgLang;
1158
1159 $file = ArchivedFile::newFromRow( $row );
1160
1161 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
1162 if( $this->mAllowed && $row->fa_storage_key ) {
1163 $checkBox = Xml::check( "fileid" . $row->fa_id );
1164 $key = urlencode( $row->fa_storage_key );
1165 $target = urlencode( $this->mTarget );
1166 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1167 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
1168 } else {
1169 $checkBox = '';
1170 $pageLink = $wgLang->timeanddate( $ts, true );
1171 }
1172 $userLink = $this->getFileUser( $file, $sk );
1173 $data =
1174 wfMsg( 'widthheight',
1175 $wgLang->formatNum( $row->fa_width ),
1176 $wgLang->formatNum( $row->fa_height ) ) .
1177 ' (' .
1178 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
1179 ')';
1180 $data = htmlspecialchars( $data );
1181 $comment = $this->getFileComment( $file, $sk );
1182 $revdlink = '';
1183 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1184 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1185 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
1186 // If revision was hidden from sysops
1187 $del = wfMsgHtml('rev-delundel');
1188 } else {
1189 $del = $sk->makeKnownLinkObj( $revdel,
1190 wfMsgHtml('rev-delundel'),
1191 'target=' . $this->mTargetObj->getPrefixedUrl() .
1192 '&fileid=' . $row->fa_id );
1193 // Bolden oversighted content
1194 if( $file->isDeleted( File::DELETED_RESTRICTED ) )
1195 $del = "<strong>$del</strong>";
1196 }
1197 $revdlink = "<tt>(<small>$del</small>)</tt>";
1198 }
1199 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1200 }
1201
1202 /**
1203 * Fetch revision text link if it's available to all users
1204 * @return string
1205 */
1206 function getPageLink( $rev, $titleObj, $ts, $sk ) {
1207 global $wgLang;
1208
1209 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
1210 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1211 } else {
1212 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1213 "target=".$this->mTargetObj->getPrefixedUrl()."&timestamp=$ts" );
1214 if( $rev->isDeleted(Revision::DELETED_TEXT) )
1215 $link = '<span class="history-deleted">' . $link . '</span>';
1216 return $link;
1217 }
1218 }
1219
1220 /**
1221 * Fetch image view link if it's available to all users
1222 * @return string
1223 */
1224 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1225 global $wgLang, $wgUser;
1226
1227 if( !$file->userCan(File::DELETED_FILE) ) {
1228 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1229 } else {
1230 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1231 "target=".$this->mTargetObj->getPrefixedUrl().
1232 "&file=$key" .
1233 "&token=" . urlencode( $wgUser->editToken( $key ) ) );
1234 if( $file->isDeleted(File::DELETED_FILE) )
1235 $link = '<span class="history-deleted">' . $link . '</span>';
1236 return $link;
1237 }
1238 }
1239
1240 /**
1241 * Fetch file's user id if it's available to this user
1242 * @return string
1243 */
1244 function getFileUser( $file, $sk ) {
1245 if( !$file->userCan(File::DELETED_USER) ) {
1246 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
1247 } else {
1248 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
1249 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1250 if( $file->isDeleted(File::DELETED_USER) )
1251 $link = '<span class="history-deleted">' . $link . '</span>';
1252 return $link;
1253 }
1254 }
1255
1256 /**
1257 * Fetch file upload comment if it's available to this user
1258 * @return string
1259 */
1260 function getFileComment( $file, $sk ) {
1261 if( !$file->userCan(File::DELETED_COMMENT) ) {
1262 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
1263 } else {
1264 $link = $sk->commentBlock( $file->getRawDescription() );
1265 if( $file->isDeleted(File::DELETED_COMMENT) )
1266 $link = '<span class="history-deleted">' . $link . '</span>';
1267 return $link;
1268 }
1269 }
1270
1271 function undelete() {
1272 global $wgOut, $wgUser;
1273 if ( wfReadOnly() ) {
1274 $wgOut->readOnlyPage();
1275 return;
1276 }
1277 if( !is_null( $this->mTargetObj ) ) {
1278 $archive = new PageArchive( $this->mTargetObj );
1279 $ok = $archive->undelete(
1280 $this->mTargetTimestamp,
1281 $this->mComment,
1282 $this->mFileVersions,
1283 $this->mUnsuppress );
1284
1285 if( is_array($ok) ) {
1286 if ( $ok[1] ) // Undeleted file count
1287 wfRunHooks( 'FileUndeleteComplete', array(
1288 $this->mTargetObj, $this->mFileVersions,
1289 $wgUser, $this->mComment) );
1290
1291 $skin = $wgUser->getSkin();
1292 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
1293 $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
1294 } else {
1295 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1296 $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
1297 }
1298
1299 // Show file deletion warnings and errors
1300 $status = $archive->getFileStatus();
1301 if( $status && !$status->isGood() ) {
1302 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1303 }
1304 } else {
1305 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1306 }
1307 return false;
1308 }
1309 }