addWikiMsg
[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_IMAGE ) {
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_IMAGE ) {
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(
465 'ORDER BY' => 'ar_timestamp' )
466 );
467 $ret = $dbw->resultObject( $result );
468
469 $rev_count = $dbw->numRows( $result );
470 if( $rev_count ) {
471 # We need to seek around as just using DESC in the ORDER BY
472 # would leave the revisions inserted in the wrong order
473 $first = $ret->fetchObject();
474 $ret->seek( $rev_count - 1 );
475 $last = $ret->fetchObject();
476 // We don't handle well changing the top revision's settings
477 if( !$unsuppress && $last->ar_deleted && $last->ar_timestamp > $previousTimestamp ) {
478 wfDebug( __METHOD__.": restoration would result in a deleted top revision\n" );
479 return false;
480 }
481 $ret->seek( 0 );
482 }
483
484 if( $makepage ) {
485 $newid = $article->insertOn( $dbw );
486 $pageId = $newid;
487 }
488
489 $revision = null;
490 $restored = 0;
491
492 while( $row = $ret->fetchObject() ) {
493 if( $row->ar_text_id ) {
494 // Revision was deleted in 1.5+; text is in
495 // the regular text table, use the reference.
496 // Specify null here so the so the text is
497 // dereferenced for page length info if needed.
498 $revText = null;
499 } else {
500 // Revision was deleted in 1.4 or earlier.
501 // Text is squashed into the archive row, and
502 // a new text table entry will be created for it.
503 $revText = Revision::getRevisionText( $row, 'ar_' );
504 }
505 // Check for key dupes due to shitty archive integrity.
506 if( $row->ar_rev_id ) {
507 $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
508 if( $exists ) continue; // don't throw DB errors
509 }
510
511 $revision = new Revision( array(
512 'page' => $pageId,
513 'id' => $row->ar_rev_id,
514 'text' => $revText,
515 'comment' => $row->ar_comment,
516 'user' => $row->ar_user,
517 'user_text' => $row->ar_user_text,
518 'timestamp' => $row->ar_timestamp,
519 'minor_edit' => $row->ar_minor_edit,
520 'text_id' => $row->ar_text_id,
521 'deleted' => $unsuppress ? 0 : $row->ar_deleted,
522 'len' => $row->ar_len
523 ) );
524 $revision->insertOn( $dbw );
525 $restored++;
526
527 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
528 }
529 # Now that it's safely stored, take it out of the archive
530 $dbw->delete( 'archive',
531 /* WHERE */ array(
532 'ar_namespace' => $this->title->getNamespace(),
533 'ar_title' => $this->title->getDBkey(),
534 $oldones ),
535 __METHOD__ );
536
537 // Was anything restored at all?
538 if( $restored == 0 )
539 return 0;
540
541 if( $revision ) {
542 // Attach the latest revision to the page...
543 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
544
545 if( $newid || $wasnew ) {
546 // Update site stats, link tables, etc
547 $article->createUpdates( $revision );
548 }
549
550 if( $newid ) {
551 wfRunHooks( 'ArticleUndelete', array( &$this->title, true ) );
552 Article::onArticleCreate( $this->title );
553 } else {
554 wfRunHooks( 'ArticleUndelete', array( &$this->title, false ) );
555 Article::onArticleEdit( $this->title );
556 }
557
558 if( $this->title->getNamespace() == NS_IMAGE ) {
559 $update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
560 $update->doUpdate();
561 }
562 } else {
563 // Revision couldn't be created. This is very weird
564 return self::UNDELETE_UNKNOWNERR;
565 }
566
567 return $restored;
568 }
569
570 function getFileStatus() { return $this->fileStatus; }
571 }
572
573 /**
574 * The HTML form for Special:Undelete, which allows users with the appropriate
575 * permissions to view and restore deleted content.
576 * @ingroup SpecialPage
577 */
578 class UndeleteForm {
579 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
580 var $mTargetTimestamp, $mAllowed, $mComment;
581
582 function UndeleteForm( $request, $par = "" ) {
583 global $wgUser;
584 $this->mAction = $request->getVal( 'action' );
585 $this->mTarget = $request->getVal( 'target' );
586 $this->mSearchPrefix = $request->getText( 'prefix' );
587 $time = $request->getVal( 'timestamp' );
588 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
589 $this->mFile = $request->getVal( 'file' );
590
591 $posted = $request->wasPosted() &&
592 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
593 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
594 $this->mInvert = $request->getCheck( 'invert' ) && $posted;
595 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
596 $this->mDiff = $request->getCheck( 'diff' );
597 $this->mComment = $request->getText( 'wpComment' );
598 $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
599
600 if( $par != "" ) {
601 $this->mTarget = $par;
602 }
603 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
604 $this->mAllowed = true;
605 } else {
606 $this->mAllowed = false;
607 $this->mTimestamp = '';
608 $this->mRestore = false;
609 }
610 if ( $this->mTarget !== "" ) {
611 $this->mTargetObj = Title::newFromURL( $this->mTarget );
612 } else {
613 $this->mTargetObj = NULL;
614 }
615 if( $this->mRestore || $this->mInvert ) {
616 $timestamps = array();
617 $this->mFileVersions = array();
618 foreach( $_REQUEST as $key => $val ) {
619 $matches = array();
620 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
621 array_push( $timestamps, $matches[1] );
622 }
623
624 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
625 $this->mFileVersions[] = intval( $matches[1] );
626 }
627 }
628 rsort( $timestamps );
629 $this->mTargetTimestamp = $timestamps;
630 }
631 }
632
633 function execute() {
634 global $wgOut, $wgUser;
635 if ( $this->mAllowed ) {
636 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
637 } else {
638 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
639 }
640
641 if( is_null( $this->mTargetObj ) ) {
642 # Not all users can just browse every deleted page from the list
643 if( $wgUser->isAllowed( 'browsearchive' ) ) {
644 $this->showSearchForm();
645
646 # List undeletable articles
647 if( $this->mSearchPrefix ) {
648 $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
649 $this->showList( $result );
650 }
651 } else {
652 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
653 }
654 return;
655 }
656 if( $this->mTimestamp !== '' ) {
657 return $this->showRevision( $this->mTimestamp );
658 }
659 if( $this->mFile !== null ) {
660 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
661 // Check if user is allowed to see this file
662 if( !$file->userCan( File::DELETED_FILE ) ) {
663 $wgOut->permissionRequired( 'suppressrevision' );
664 return false;
665 } else {
666 return $this->showFile( $this->mFile );
667 }
668 }
669 if( $this->mRestore && $this->mAction == "submit" ) {
670 return $this->undelete();
671 }
672 if( $this->mInvert && $this->mAction == "submit" ) {
673 return $this->showHistory( );
674 }
675 return $this->showHistory();
676 }
677
678 function showSearchForm() {
679 global $wgOut, $wgScript;
680 $wgOut->addWikiMsg( 'undelete-header' );
681
682 $wgOut->addHtml(
683 Xml::openElement( 'form', array(
684 'method' => 'get',
685 'action' => $wgScript ) ) .
686 '<fieldset>' .
687 Xml::element( 'legend', array(),
688 wfMsg( 'undelete-search-box' ) ) .
689 Xml::hidden( 'title',
690 SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
691 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
692 'prefix', 'prefix', 20,
693 $this->mSearchPrefix ) .
694 Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
695 '</fieldset>' .
696 '</form>' );
697 }
698
699 // Generic list of deleted pages
700 private function showList( $result ) {
701 global $wgLang, $wgContLang, $wgUser, $wgOut;
702
703 if( $result->numRows() == 0 ) {
704 $wgOut->addWikiMsg( 'undelete-no-results' );
705 return;
706 }
707
708 $wgOut->addWikiMsg( "undeletepagetext" );
709
710 $sk = $wgUser->getSkin();
711 $undelete = SpecialPage::getTitleFor( 'Undelete' );
712 $wgOut->addHTML( "<ul>\n" );
713 while( $row = $result->fetchObject() ) {
714 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
715 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ),
716 'target=' . $title->getPrefixedUrl() );
717 #$revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
718 $revs = wfMsgExt( 'undeleterevisions',
719 array( 'parseinline' ),
720 $wgLang->formatNum( $row->count ) );
721 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
722 }
723 $result->free();
724 $wgOut->addHTML( "</ul>\n" );
725
726 return true;
727 }
728
729 private function showRevision( $timestamp ) {
730 global $wgLang, $wgUser, $wgOut;
731 $self = SpecialPage::getTitleFor( 'Undelete' );
732 $skin = $wgUser->getSkin();
733
734 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
735
736 $archive = new PageArchive( $this->mTargetObj );
737 $rev = $archive->getRevision( $timestamp );
738
739 if( !$rev ) {
740 $wgOut->addWikiMsg( 'undeleterevision-missing' );
741 return;
742 }
743
744 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
745 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
746 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
747 return;
748 } else {
749 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
750 $wgOut->addHTML( '<br/>' );
751 // and we are allowed to see...
752 }
753 }
754
755 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
756
757 $link = $skin->makeKnownLinkObj(
758 SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
759 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
760 );
761
762 if( $this->mDiff ) {
763 $previousRev = $archive->getPreviousRevision( $timestamp );
764 if( $previousRev ) {
765 $this->showDiff( $previousRev, $rev );
766 if( $wgUser->getOption( 'diffonly' ) ) {
767 return;
768 } else {
769 $wgOut->addHtml( '<hr />' );
770 }
771 } else {
772 $wgOut->addHtml( wfMsgHtml( 'undelete-nodiff' ) );
773 }
774 }
775
776 // date and time are separate parameters to facilitate localisation.
777 // $time is kept for backward compat reasons.
778 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
779 $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
780 $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
781 $user = $skin->revUserTools( $rev );
782
783 $wgOut->addHtml( '<p>' . wfMsgHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</p>' );
784
785 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
786
787 if( $this->mPreview ) {
788 $wgOut->addHtml( "<hr />\n" );
789
790 //Hide [edit]s
791 $popts = $wgOut->parserOptions();
792 $popts->setEditSection( false );
793 $wgOut->parserOptions( $popts );
794 $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
795 }
796
797 $wgOut->addHtml(
798 wfElement( 'textarea', array(
799 'readonly' => 'readonly',
800 'cols' => intval( $wgUser->getOption( 'cols' ) ),
801 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
802 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
803 wfOpenElement( 'div' ) .
804 wfOpenElement( 'form', array(
805 'method' => 'post',
806 'action' => $self->getLocalURL( "action=submit" ) ) ) .
807 wfElement( 'input', array(
808 'type' => 'hidden',
809 'name' => 'target',
810 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
811 wfElement( 'input', array(
812 'type' => 'hidden',
813 'name' => 'timestamp',
814 'value' => $timestamp ) ) .
815 wfElement( 'input', array(
816 'type' => 'hidden',
817 'name' => 'wpEditToken',
818 'value' => $wgUser->editToken() ) ) .
819 wfElement( 'input', array(
820 'type' => 'submit',
821 'name' => 'preview',
822 'value' => wfMsg( 'showpreview' ) ) ) .
823 wfElement( 'input', array(
824 'name' => 'diff',
825 'type' => 'submit',
826 'value' => wfMsg( 'showdiff' ) ) ) .
827 wfCloseElement( 'form' ) .
828 wfCloseElement( 'div' ) );
829 }
830
831 /**
832 * Build a diff display between this and the previous either deleted
833 * or non-deleted edit.
834 * @param Revision $previousRev
835 * @param Revision $currentRev
836 * @return string HTML
837 */
838 function showDiff( $previousRev, $currentRev ) {
839 global $wgOut, $wgUser;
840
841 $diffEngine = new DifferenceEngine();
842 $diffEngine->showDiffStyle();
843 $wgOut->addHtml(
844 "<div>" .
845 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
846 "<col class='diff-marker' />" .
847 "<col class='diff-content' />" .
848 "<col class='diff-marker' />" .
849 "<col class='diff-content' />" .
850 "<tr>" .
851 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
852 $this->diffHeader( $previousRev ) .
853 "</td>" .
854 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
855 $this->diffHeader( $currentRev ) .
856 "</td>" .
857 "</tr>" .
858 $diffEngine->generateDiffBody(
859 $previousRev->getText(), $currentRev->getText() ) .
860 "</table>" .
861 "</div>\n" );
862
863 }
864
865 private function diffHeader( $rev ) {
866 global $wgUser, $wgLang, $wgLang;
867 $sk = $wgUser->getSkin();
868 $isDeleted = !( $rev->getId() && $rev->getTitle() );
869 if( $isDeleted ) {
870 /// @fixme $rev->getTitle() is null for deleted revs...?
871 $targetPage = SpecialPage::getTitleFor( 'Undelete' );
872 $targetQuery = 'target=' .
873 $this->mTargetObj->getPrefixedUrl() .
874 '&timestamp=' .
875 wfTimestamp( TS_MW, $rev->getTimestamp() );
876 } else {
877 /// @fixme getId() may return non-zero for deleted revs...
878 $targetPage = $rev->getTitle();
879 $targetQuery = 'oldid=' . $rev->getId();
880 }
881 return
882 '<div id="mw-diff-otitle1"><strong>' .
883 $sk->makeLinkObj( $targetPage,
884 wfMsgHtml( 'revisionasof',
885 $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
886 $targetQuery ) .
887 ( $isDeleted ? ' ' . wfMsgHtml( 'deletedrev' ) : '' ) .
888 '</strong></div>' .
889 '<div id="mw-diff-otitle2">' .
890 $sk->revUserTools( $rev ) . '<br/>' .
891 '</div>' .
892 '<div id="mw-diff-otitle3">' .
893 $sk->revComment( $rev ) . '<br/>' .
894 '</div>';
895 }
896
897 /**
898 * Show a deleted file version requested by the visitor.
899 */
900 private function showFile( $key ) {
901 global $wgOut, $wgRequest;
902 $wgOut->disable();
903
904 # We mustn't allow the output to be Squid cached, otherwise
905 # if an admin previews a deleted image, and it's cached, then
906 # a user without appropriate permissions can toddle off and
907 # nab the image, and Squid will serve it
908 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
909 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
910 $wgRequest->response()->header( 'Pragma: no-cache' );
911
912 $store = FileStore::get( 'deleted' );
913 $store->stream( $key );
914 }
915
916 private function showHistory( ) {
917 global $wgLang, $wgUser, $wgOut;
918
919 $sk = $wgUser->getSkin();
920 if( $this->mAllowed ) {
921 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
922 } else {
923 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
924 }
925
926 $wgOut->addWikiText( wfMsgHtml( 'undeletepagetitle', $this->mTargetObj->getPrefixedText()) );
927
928 $archive = new PageArchive( $this->mTargetObj );
929 /*
930 $text = $archive->getLastRevisionText();
931 if( is_null( $text ) ) {
932 $wgOut->addWikiMsg( "nohistory" );
933 return;
934 }
935 */
936 if ( $this->mAllowed ) {
937 $wgOut->addWikiMsg( "undeletehistory" );
938 $wgOut->addWikiMsg( "undeleterevdel" );
939 } else {
940 $wgOut->addWikiMsg( "undeletehistorynoadmin" );
941 }
942
943 # List all stored revisions
944 $revisions = $archive->listRevisions();
945 $files = $archive->listFiles();
946
947 $haveRevisions = $revisions && $revisions->numRows() > 0;
948 $haveFiles = $files && $files->numRows() > 0;
949
950 # Batch existence check on user and talk pages
951 if( $haveRevisions ) {
952 $batch = new LinkBatch();
953 while( $row = $revisions->fetchObject() ) {
954 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
955 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
956 }
957 $batch->execute();
958 $revisions->seek( 0 );
959 }
960 if( $haveFiles ) {
961 $batch = new LinkBatch();
962 while( $row = $files->fetchObject() ) {
963 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
964 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
965 }
966 $batch->execute();
967 $files->seek( 0 );
968 }
969
970 if ( $this->mAllowed ) {
971 $titleObj = SpecialPage::getTitleFor( "Undelete" );
972 $action = $titleObj->getLocalURL( "action=submit" );
973 # Start the form here
974 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
975 $wgOut->addHtml( $top );
976 }
977
978 # Show relevant lines from the deletion log:
979 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
980 LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
981
982 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
983 # Format the user-visible controls (comment field, submission button)
984 # in a nice little table
985 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
986 $unsuppressBox =
987 "<tr>
988 <td>&nbsp;</td>
989 <td class='mw-input'>" .
990 Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
991 'mw-undelete-unsuppress', $this->mUnsuppress ).
992 "</td>
993 </tr>";
994 } else {
995 $unsuppressBox = "";
996 }
997 $table =
998 Xml::openElement( 'fieldset' ) .
999 Xml::element( 'legend', null, wfMsg( 'undelete-fieldset-title' ) ).
1000 Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
1001 "<tr>
1002 <td colspan='2'>" .
1003 wfMsgWikiHtml( 'undeleteextrahelp' ) .
1004 "</td>
1005 </tr>
1006 <tr>
1007 <td class='mw-label'>" .
1008 Xml::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
1009 "</td>
1010 <td class='mw-input'>" .
1011 Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
1012 "</td>
1013 </tr>
1014 <tr>
1015 <td>&nbsp;</td>
1016 <td class='mw-submit'>" .
1017 Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) .
1018 Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) .
1019 Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
1020 "</td>
1021 </tr>" .
1022 $unsuppressBox .
1023 Xml::closeElement( 'table' ) .
1024 Xml::closeElement( 'fieldset' );
1025
1026 $wgOut->addHtml( $table );
1027 }
1028
1029 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
1030
1031 if( $haveRevisions ) {
1032 # The page's stored (deleted) history:
1033 $wgOut->addHTML("<ul>");
1034 $target = urlencode( $this->mTarget );
1035 $remaining = $revisions->numRows();
1036 $earliestLiveTime = $this->getEarliestTime( $this->mTargetObj );
1037
1038 while( $row = $revisions->fetchObject() ) {
1039 $remaining--;
1040 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
1041 }
1042 $revisions->free();
1043 $wgOut->addHTML("</ul>");
1044 } else {
1045 $wgOut->addWikiMsg( "nohistory" );
1046 }
1047
1048 if( $haveFiles ) {
1049 $wgOut->addHtml( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1050 $wgOut->addHtml( "<ul>" );
1051 while( $row = $files->fetchObject() ) {
1052 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
1053 }
1054 $files->free();
1055 $wgOut->addHTML( "</ul>" );
1056 }
1057
1058 if ( $this->mAllowed ) {
1059 # Slip in the hidden controls here
1060 $misc = Xml::hidden( 'target', $this->mTarget );
1061 $misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
1062 $misc .= Xml::closeElement( 'form' );
1063 $wgOut->addHtml( $misc );
1064 }
1065
1066 return true;
1067 }
1068
1069 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
1070 global $wgUser, $wgLang;
1071
1072 $rev = new Revision( array(
1073 'page' => $this->mTargetObj->getArticleId(),
1074 'comment' => $row->ar_comment,
1075 'user' => $row->ar_user,
1076 'user_text' => $row->ar_user_text,
1077 'timestamp' => $row->ar_timestamp,
1078 'minor_edit' => $row->ar_minor_edit,
1079 'deleted' => $row->ar_deleted,
1080 'len' => $row->ar_len ) );
1081
1082 $stxt = '';
1083 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1084 if( $this->mAllowed ) {
1085 if( $this->mInvert){
1086 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1087 $checkBox = Xml::check( "ts$ts");
1088 } else {
1089 $checkBox = Xml::check( "ts$ts", true );
1090 }
1091 } else {
1092 $checkBox = Xml::check( "ts$ts" );
1093 }
1094 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1095 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1096 # Last link
1097 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1098 $last = wfMsgHtml('diff');
1099 } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
1100 $last = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml('diff'),
1101 "target=" . $this->mTargetObj->getPrefixedUrl() . "&timestamp=$ts&diff=prev" );
1102 } else {
1103 $last = wfMsgHtml('diff');
1104 }
1105 } else {
1106 $checkBox = '';
1107 $pageLink = $wgLang->timeanddate( $ts, true );
1108 $last = wfMsgHtml('diff');
1109 }
1110 $userLink = $sk->revUserTools( $rev );
1111
1112 if(!is_null($size = $row->ar_len)) {
1113 $stxt = $sk->formatRevisionSize( $size );
1114 }
1115 $comment = $sk->revComment( $rev );
1116 $revdlink = '';
1117 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1118 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1119 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1120 // If revision was hidden from sysops
1121 $del = wfMsgHtml('rev-delundel');
1122 } else {
1123 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
1124 $del = $sk->makeKnownLinkObj( $revdel,
1125 wfMsgHtml('rev-delundel'),
1126 'target=' . $this->mTargetObj->getPrefixedUrl() . "&artimestamp=$ts" );
1127 // Bolden oversighted content
1128 if( $rev->isDeleted( Revision::DELETED_RESTRICTED ) )
1129 $del = "<strong>$del</strong>";
1130 }
1131 $revdlink = "<tt>(<small>$del</small>)</tt>";
1132 }
1133
1134 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
1135 }
1136
1137 private function formatFileRow( $row, $sk ) {
1138 global $wgUser, $wgLang;
1139
1140 $file = ArchivedFile::newFromRow( $row );
1141
1142 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
1143 if( $this->mAllowed && $row->fa_storage_key ) {
1144 $checkBox = Xml::check( "fileid" . $row->fa_id );
1145 $key = urlencode( $row->fa_storage_key );
1146 $target = urlencode( $this->mTarget );
1147 $titleObj = SpecialPage::getTitleFor( "Undelete" );
1148 $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
1149 } else {
1150 $checkBox = '';
1151 $pageLink = $wgLang->timeanddate( $ts, true );
1152 }
1153 $userLink = $this->getFileUser( $file, $sk );
1154 $data =
1155 wfMsg( 'widthheight',
1156 $wgLang->formatNum( $row->fa_width ),
1157 $wgLang->formatNum( $row->fa_height ) ) .
1158 ' (' .
1159 wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
1160 ')';
1161 $data = htmlspecialchars( $data );
1162 $comment = $this->getFileComment( $file, $sk );
1163 $revdlink = '';
1164 if( $wgUser->isAllowed( 'deleterevision' ) ) {
1165 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
1166 if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
1167 // If revision was hidden from sysops
1168 $del = wfMsgHtml('rev-delundel');
1169 } else {
1170 $del = $sk->makeKnownLinkObj( $revdel,
1171 wfMsgHtml('rev-delundel'),
1172 'target=' . $this->mTargetObj->getPrefixedUrl() .
1173 '&fileid=' . $row->fa_id );
1174 // Bolden oversighted content
1175 if( $file->isDeleted( File::DELETED_RESTRICTED ) )
1176 $del = "<strong>$del</strong>";
1177 }
1178 $revdlink = "<tt>(<small>$del</small>)</tt>";
1179 }
1180 return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
1181 }
1182
1183 private function getEarliestTime( $title ) {
1184 $dbr = wfGetDB( DB_SLAVE );
1185 if( $title->exists() ) {
1186 $min = $dbr->selectField( 'revision',
1187 'MIN(rev_timestamp)',
1188 array( 'rev_page' => $title->getArticleId() ),
1189 __METHOD__ );
1190 return wfTimestampOrNull( TS_MW, $min );
1191 }
1192 return null;
1193 }
1194
1195 /**
1196 * Fetch revision text link if it's available to all users
1197 * @return string
1198 */
1199 function getPageLink( $rev, $titleObj, $ts, $sk ) {
1200 global $wgLang;
1201
1202 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
1203 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1204 } else {
1205 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1206 "target=".$this->mTargetObj->getPrefixedUrl()."&timestamp=$ts" );
1207 if( $rev->isDeleted(Revision::DELETED_TEXT) )
1208 $link = '<span class="history-deleted">' . $link . '</span>';
1209 return $link;
1210 }
1211 }
1212
1213 /**
1214 * Fetch image view link if it's available to all users
1215 * @return string
1216 */
1217 function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1218 global $wgLang;
1219
1220 if( !$file->userCan(File::DELETED_FILE) ) {
1221 return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
1222 } else {
1223 $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
1224 "target=".$this->mTargetObj->getPrefixedUrl()."&file=$key" );
1225 if( $file->isDeleted(File::DELETED_FILE) )
1226 $link = '<span class="history-deleted">' . $link . '</span>';
1227 return $link;
1228 }
1229 }
1230
1231 /**
1232 * Fetch file's user id if it's available to this user
1233 * @return string
1234 */
1235 function getFileUser( $file, $sk ) {
1236 if( !$file->userCan(File::DELETED_USER) ) {
1237 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
1238 } else {
1239 $link = $sk->userLink( $file->getUser(), $file->getUserText() ) .
1240 $sk->userToolLinks( $file->getUser(), $file->getUserText() );
1241 if( $file->isDeleted(File::DELETED_USER) )
1242 $link = '<span class="history-deleted">' . $link . '</span>';
1243 return $link;
1244 }
1245 }
1246
1247 /**
1248 * Fetch file upload comment if it's available to this user
1249 * @return string
1250 */
1251 function getFileComment( $file, $sk ) {
1252 if( !$file->userCan(File::DELETED_COMMENT) ) {
1253 return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
1254 } else {
1255 $link = $sk->commentBlock( $file->getRawDescription() );
1256 if( $file->isDeleted(File::DELETED_COMMENT) )
1257 $link = '<span class="history-deleted">' . $link . '</span>';
1258 return $link;
1259 }
1260 }
1261
1262 function undelete() {
1263 global $wgOut, $wgUser;
1264 if ( wfReadOnly() ) {
1265 $wgOut->readOnlyPage();
1266 return;
1267 }
1268 if( !is_null( $this->mTargetObj ) ) {
1269 $archive = new PageArchive( $this->mTargetObj );
1270 $ok = $archive->undelete(
1271 $this->mTargetTimestamp,
1272 $this->mComment,
1273 $this->mFileVersions,
1274 $this->mUnsuppress );
1275
1276 if( is_array($ok) ) {
1277 if ( $ok[1] ) // Undeleted file count
1278 wfRunHooks( 'FileUndeleteComplete', array(
1279 $this->mTargetObj, $this->mFileVersions,
1280 $wgUser, $this->mComment) );
1281
1282 $skin = $wgUser->getSkin();
1283 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
1284 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
1285 } else {
1286 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1287 $wgOut->addHtml( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
1288 }
1289
1290 // Show file deletion warnings and errors
1291 $status = $archive->getFileStatus();
1292 if( $status && !$status->isGood() ) {
1293 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1294 }
1295 } else {
1296 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1297 }
1298 return false;
1299 }
1300 }