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