* (bug 8042) Make miser mode caching limits settable via $wgQueryCacheLimit
[mediawiki.git] / includes / SpecialUndelete.php
blobf152f64d6480025e0173d65029ea684df77452a6
1 <?php
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and restore deleted content
7 * @package MediaWiki
8 * @subpackage Special pages
9 */
11 /**
14 function wfSpecialUndelete( $par ) {
15 global $wgRequest;
17 $form = new UndeleteForm( $wgRequest, $par );
18 $form->execute();
21 /**
23 * @package MediaWiki
24 * @subpackage SpecialPage
26 class PageArchive {
27 var $title;
29 function PageArchive( &$title ) {
30 if( is_null( $title ) ) {
31 throw new MWException( 'Archiver() given a null title.');
33 $this->title =& $title;
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. Can be called staticaly.
41 * @return ResultWrapper
43 /* static */ function listAllPages() {
44 $dbr =& wfGetDB( DB_SLAVE );
45 $archive = $dbr->tableName( 'archive' );
47 $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM $archive " .
48 "GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title";
50 return $dbr->resultObject( $dbr->query( $sql, 'PageArchive::listAllPages' ) );
53 /**
54 * List the revisions of the given page. Returns result wrapper with
55 * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
57 * @return ResultWrapper
59 function listRevisions() {
60 $dbr =& wfGetDB( DB_SLAVE );
61 $res = $dbr->select( 'archive',
62 array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment' ),
63 array( 'ar_namespace' => $this->title->getNamespace(),
64 'ar_title' => $this->title->getDBkey() ),
65 'PageArchive::listRevisions',
66 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
67 $ret = $dbr->resultObject( $res );
68 return $ret;
71 /**
72 * List the deleted file revisions for this page, if it's a file page.
73 * Returns a result wrapper with various filearchive fields, or null
74 * if not a file page.
76 * @return ResultWrapper
77 * @fixme Does this belong in Image for fuller encapsulation?
79 function listFiles() {
80 if( $this->title->getNamespace() == NS_IMAGE ) {
81 $dbr =& wfGetDB( DB_SLAVE );
82 $res = $dbr->select( 'filearchive',
83 array(
84 'fa_id',
85 'fa_name',
86 'fa_storage_key',
87 'fa_size',
88 'fa_width',
89 'fa_height',
90 'fa_description',
91 'fa_user',
92 'fa_user_text',
93 'fa_timestamp' ),
94 array( 'fa_name' => $this->title->getDbKey() ),
95 __METHOD__,
96 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
97 $ret = $dbr->resultObject( $res );
98 return $ret;
100 return null;
104 * Fetch (and decompress if necessary) the stored text for the deleted
105 * revision of the page with the given timestamp.
107 * @return string
108 * @deprecated Use getRevision() for more flexible information
110 function getRevisionText( $timestamp ) {
111 $rev = $this->getRevision( $timestamp );
112 return $rev ? $rev->getText() : null;
116 * Return a Revision object containing data for the deleted revision.
117 * Note that the result *may* or *may not* have a null page ID.
118 * @param string $timestamp
119 * @return Revision
121 function getRevision( $timestamp ) {
122 $dbr =& wfGetDB( DB_SLAVE );
123 $row = $dbr->selectRow( 'archive',
124 array(
125 'ar_rev_id',
126 'ar_text',
127 'ar_comment',
128 'ar_user',
129 'ar_user_text',
130 'ar_timestamp',
131 'ar_minor_edit',
132 'ar_flags',
133 'ar_text_id' ),
134 array( 'ar_namespace' => $this->title->getNamespace(),
135 'ar_title' => $this->title->getDbkey(),
136 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
137 __METHOD__ );
138 if( $row ) {
139 return new Revision( array(
140 'page' => $this->title->getArticleId(),
141 'id' => $row->ar_rev_id,
142 'text' => ($row->ar_text_id
143 ? null
144 : Revision::getRevisionText( $row, 'ar_' ) ),
145 'comment' => $row->ar_comment,
146 'user' => $row->ar_user,
147 'user_text' => $row->ar_user_text,
148 'timestamp' => $row->ar_timestamp,
149 'minor_edit' => $row->ar_minor_edit,
150 'text_id' => $row->ar_text_id ) );
151 } else {
152 return null;
157 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
159 function getTextFromRow( $row ) {
160 if( is_null( $row->ar_text_id ) ) {
161 // An old row from MediaWiki 1.4 or previous.
162 // Text is embedded in this row in classic compression format.
163 return Revision::getRevisionText( $row, "ar_" );
164 } else {
165 // New-style: keyed to the text storage backend.
166 $dbr =& wfGetDB( DB_SLAVE );
167 $text = $dbr->selectRow( 'text',
168 array( 'old_text', 'old_flags' ),
169 array( 'old_id' => $row->ar_text_id ),
170 __METHOD__ );
171 return Revision::getRevisionText( $text );
177 * Fetch (and decompress if necessary) the stored text of the most
178 * recently edited deleted revision of the page.
180 * If there are no archived revisions for the page, returns NULL.
182 * @return string
184 function getLastRevisionText() {
185 $dbr =& wfGetDB( DB_SLAVE );
186 $row = $dbr->selectRow( 'archive',
187 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
188 array( 'ar_namespace' => $this->title->getNamespace(),
189 'ar_title' => $this->title->getDBkey() ),
190 'PageArchive::getLastRevisionText',
191 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
192 if( $row ) {
193 return $this->getTextFromRow( $row );
194 } else {
195 return NULL;
200 * Quick check if any archived revisions are present for the page.
201 * @return bool
203 function isDeleted() {
204 $dbr =& wfGetDB( DB_SLAVE );
205 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
206 array( 'ar_namespace' => $this->title->getNamespace(),
207 'ar_title' => $this->title->getDBkey() ) );
208 return ($n > 0);
212 * Restore the given (or all) text and file revisions for the page.
213 * Once restored, the items will be removed from the archive tables.
214 * The deletion log will be updated with an undeletion notice.
216 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
217 * @param string $comment
218 * @param array $fileVersions
220 * @return true on success.
222 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
223 // If both the set of text revisions and file revisions are empty,
224 // restore everything. Otherwise, just restore the requested items.
225 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
227 $restoreText = $restoreAll || !empty( $timestamps );
228 $restoreFiles = $restoreAll || !empty( $fileVersions );
230 if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
231 $img = new Image( $this->title );
232 $filesRestored = $img->restore( $fileVersions );
233 } else {
234 $filesRestored = 0;
237 if( $restoreText ) {
238 $textRestored = $this->undeleteRevisions( $timestamps );
239 } else {
240 $textRestored = 0;
243 // Touch the log!
244 global $wgContLang;
245 $log = new LogPage( 'delete' );
247 if( $textRestored && $filesRestored ) {
248 $reason = wfMsgForContent( 'undeletedrevisions-files',
249 $wgContLang->formatNum( $textRestored ),
250 $wgContLang->formatNum( $filesRestored ) );
251 } elseif( $textRestored ) {
252 $reason = wfMsgForContent( 'undeletedrevisions',
253 $wgContLang->formatNum( $textRestored ) );
254 } elseif( $filesRestored ) {
255 $reason = wfMsgForContent( 'undeletedfiles',
256 $wgContLang->formatNum( $filesRestored ) );
257 } else {
258 wfDebug( "Undelete: nothing undeleted...\n" );
259 return false;
262 if( trim( $comment ) != '' )
263 $reason .= ": {$comment}";
264 $log->addEntry( 'restore', $this->title, $reason );
266 return true;
270 * This is the meaty bit -- restores archived revisions of the given page
271 * to the cur/old tables. If the page currently exists, all revisions will
272 * be stuffed into old, otherwise the most recent will go into cur.
274 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
275 * @param string $comment
276 * @param array $fileVersions
278 * @return int number of revisions restored
280 private function undeleteRevisions( $timestamps ) {
281 global $wgDBtype;
283 $restoreAll = empty( $timestamps );
285 $dbw =& wfGetDB( DB_MASTER );
286 $page = $dbw->tableName( 'archive' );
288 # Does this page already exist? We'll have to update it...
289 $article = new Article( $this->title );
290 $options = ( $wgDBtype == 'postgres' )
291 ? '' // pg doesn't support this?
292 : 'FOR UPDATE';
293 $page = $dbw->selectRow( 'page',
294 array( 'page_id', 'page_latest' ),
295 array( 'page_namespace' => $this->title->getNamespace(),
296 'page_title' => $this->title->getDBkey() ),
297 __METHOD__,
298 $options );
299 if( $page ) {
300 # Page already exists. Import the history, and if necessary
301 # we'll update the latest revision field in the record.
302 $newid = 0;
303 $pageId = $page->page_id;
304 $previousRevId = $page->page_latest;
305 } else {
306 # Have to create a new article...
307 $newid = $article->insertOn( $dbw );
308 $pageId = $newid;
309 $previousRevId = 0;
312 if( $restoreAll ) {
313 $oldones = '1 = 1'; # All revisions...
314 } else {
315 $oldts = implode( ',',
316 array_map( array( &$dbw, 'addQuotes' ),
317 array_map( array( &$dbw, 'timestamp' ),
318 $timestamps ) ) );
320 $oldones = "ar_timestamp IN ( {$oldts} )";
324 * Restore each revision...
326 $result = $dbw->select( 'archive',
327 /* fields */ array(
328 'ar_rev_id',
329 'ar_text',
330 'ar_comment',
331 'ar_user',
332 'ar_user_text',
333 'ar_timestamp',
334 'ar_minor_edit',
335 'ar_flags',
336 'ar_text_id' ),
337 /* WHERE */ array(
338 'ar_namespace' => $this->title->getNamespace(),
339 'ar_title' => $this->title->getDBkey(),
340 $oldones ),
341 __METHOD__,
342 /* options */ array(
343 'ORDER BY' => 'ar_timestamp' )
345 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
346 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
347 return false;
350 $revision = null;
351 $restored = 0;
353 while( $row = $dbw->fetchObject( $result ) ) {
354 if( $row->ar_text_id ) {
355 // Revision was deleted in 1.5+; text is in
356 // the regular text table, use the reference.
357 // Specify null here so the so the text is
358 // dereferenced for page length info if needed.
359 $revText = null;
360 } else {
361 // Revision was deleted in 1.4 or earlier.
362 // Text is squashed into the archive row, and
363 // a new text table entry will be created for it.
364 $revText = Revision::getRevisionText( $row, 'ar_' );
366 $revision = new Revision( array(
367 'page' => $pageId,
368 'id' => $row->ar_rev_id,
369 'text' => $revText,
370 'comment' => $row->ar_comment,
371 'user' => $row->ar_user,
372 'user_text' => $row->ar_user_text,
373 'timestamp' => $row->ar_timestamp,
374 'minor_edit' => $row->ar_minor_edit,
375 'text_id' => $row->ar_text_id,
376 ) );
377 $revision->insertOn( $dbw );
378 $restored++;
381 if( $revision ) {
382 # FIXME: Update latest if newer as well...
383 if( $newid ) {
384 // Attach the latest revision to the page...
385 $article->updateRevisionOn( $dbw, $revision, $previousRevId );
387 // Update site stats, link tables, etc
388 $article->createUpdates( $revision );
391 if( $newid ) {
392 Article::onArticleCreate( $this->title );
393 } else {
394 Article::onArticleEdit( $this->title );
396 } else {
397 # Something went terribly wrong!
400 # Now that it's safely stored, take it out of the archive
401 $dbw->delete( 'archive',
402 /* WHERE */ array(
403 'ar_namespace' => $this->title->getNamespace(),
404 'ar_title' => $this->title->getDBkey(),
405 $oldones ),
406 __METHOD__ );
408 return $restored;
415 * @package MediaWiki
416 * @subpackage SpecialPage
418 class UndeleteForm {
419 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
420 var $mTargetTimestamp, $mAllowed, $mComment;
422 function UndeleteForm( &$request, $par = "" ) {
423 global $wgUser;
424 $this->mAction = $request->getVal( 'action' );
425 $this->mTarget = $request->getVal( 'target' );
426 $time = $request->getVal( 'timestamp' );
427 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
428 $this->mFile = $request->getVal( 'file' );
430 $posted = $request->wasPosted() &&
431 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
432 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
433 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
434 $this->mComment = $request->getText( 'wpComment' );
436 if( $par != "" ) {
437 $this->mTarget = $par;
439 if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
440 $this->mAllowed = true;
441 } else {
442 $this->mAllowed = false;
443 $this->mTimestamp = '';
444 $this->mRestore = false;
446 if ( $this->mTarget !== "" ) {
447 $this->mTargetObj = Title::newFromURL( $this->mTarget );
448 } else {
449 $this->mTargetObj = NULL;
451 if( $this->mRestore ) {
452 $timestamps = array();
453 $this->mFileVersions = array();
454 foreach( $_REQUEST as $key => $val ) {
455 $matches = array();
456 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
457 array_push( $timestamps, $matches[1] );
460 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
461 $this->mFileVersions[] = intval( $matches[1] );
464 rsort( $timestamps );
465 $this->mTargetTimestamp = $timestamps;
469 function execute() {
471 if( is_null( $this->mTargetObj ) ) {
472 return $this->showList();
474 if( $this->mTimestamp !== '' ) {
475 return $this->showRevision( $this->mTimestamp );
477 if( $this->mFile !== null ) {
478 return $this->showFile( $this->mFile );
480 if( $this->mRestore && $this->mAction == "submit" ) {
481 return $this->undelete();
483 return $this->showHistory();
486 /* private */ function showList() {
487 global $wgLang, $wgContLang, $wgUser, $wgOut;
489 # List undeletable articles
490 $result = PageArchive::listAllPages();
492 if ( $this->mAllowed ) {
493 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
494 } else {
495 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
497 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
499 $sk = $wgUser->getSkin();
500 $undelete = SpecialPage::getTitleFor( 'Undelete' );
501 $wgOut->addHTML( "<ul>\n" );
502 while( $row = $result->fetchObject() ) {
503 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
504 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
505 $revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
506 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
508 $result->free();
509 $wgOut->addHTML( "</ul>\n" );
511 return true;
514 /* private */ function showRevision( $timestamp ) {
515 global $wgLang, $wgUser, $wgOut;
517 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
519 $archive = new PageArchive( $this->mTargetObj );
520 $rev = $archive->getRevision( $timestamp );
522 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
523 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
524 $wgLang->date( $timestamp ) ) . ")\n" );
526 if( !$rev ) {
527 $wgOut->addWikiText( wfMsg( 'undeleterevision-missing' ) );
528 return;
531 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
533 if( $this->mPreview ) {
534 $wgOut->addHtml( "<hr />\n" );
535 $article = new Article ( $archive->title ); # OutputPage wants an Article obj
536 $wgOut->addPrimaryWikiText( $rev->getText(), $article, false );
539 $self = SpecialPage::getTitleFor( "Undelete" );
541 $wgOut->addHtml(
542 wfElement( 'textarea', array(
543 'readonly' => true,
544 'cols' => intval( $wgUser->getOption( 'cols' ) ),
545 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
546 $rev->getText() . "\n" ) .
547 wfOpenElement( 'div' ) .
548 wfOpenElement( 'form', array(
549 'method' => 'post',
550 'action' => $self->getLocalURL( "action=submit" ) ) ) .
551 wfElement( 'input', array(
552 'type' => 'hidden',
553 'name' => 'target',
554 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
555 wfElement( 'input', array(
556 'type' => 'hidden',
557 'name' => 'timestamp',
558 'value' => $timestamp ) ) .
559 wfElement( 'input', array(
560 'type' => 'hidden',
561 'name' => 'wpEditToken',
562 'value' => $wgUser->editToken() ) ) .
563 wfElement( 'input', array(
564 'type' => 'hidden',
565 'name' => 'preview',
566 'value' => '1' ) ) .
567 wfElement( 'input', array(
568 'type' => 'submit',
569 'value' => wfMsg( 'showpreview' ) ) ) .
570 wfCloseElement( 'form' ) .
571 wfCloseElement( 'div' ) );
575 * Show a deleted file version requested by the visitor.
577 function showFile( $key ) {
578 global $wgOut;
579 $wgOut->disable();
581 $store = FileStore::get( 'deleted' );
582 $store->stream( $key );
585 /* private */ function showHistory() {
586 global $wgLang, $wgUser, $wgOut;
588 $sk = $wgUser->getSkin();
589 if ( $this->mAllowed ) {
590 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
591 } else {
592 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
595 $archive = new PageArchive( $this->mTargetObj );
597 $text = $archive->getLastRevisionText();
598 if( is_null( $text ) ) {
599 $wgOut->addWikiText( wfMsg( "nohistory" ) );
600 return;
603 if ( $this->mAllowed ) {
604 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
605 } else {
606 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
609 # List all stored revisions
610 $revisions = $archive->listRevisions();
611 $files = $archive->listFiles();
613 $haveRevisions = $revisions && $revisions->numRows() > 0;
614 $haveFiles = $files && $files->numRows() > 0;
616 # Batch existence check on user and talk pages
617 if( $haveRevisions ) {
618 $batch = new LinkBatch();
619 while( $row = $revisions->fetchObject() ) {
620 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
621 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
623 $batch->execute();
624 $revisions->seek( 0 );
626 if( $haveFiles ) {
627 $batch = new LinkBatch();
628 while( $row = $files->fetchObject() ) {
629 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
630 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
632 $batch->execute();
633 $files->seek( 0 );
636 if ( $this->mAllowed ) {
637 $titleObj = SpecialPage::getTitleFor( "Undelete" );
638 $action = $titleObj->getLocalURL( "action=submit" );
639 # Start the form here
640 $top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
641 $wgOut->addHtml( $top );
644 # Show relevant lines from the deletion log:
645 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
646 $logViewer = new LogViewer(
647 new LogReader(
648 new FauxRequest(
649 array( 'page' => $this->mTargetObj->getPrefixedText(),
650 'type' => 'delete' ) ) ) );
651 $logViewer->showList( $wgOut );
653 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
654 # Format the user-visible controls (comment field, submission button)
655 # in a nice little table
656 $table = '<fieldset><table><tr>';
657 $table .= '<td colspan="2">' . wfMsgWikiHtml( 'undeleteextrahelp' ) . '</td></tr><tr>';
658 $table .= '<td align="right"><strong>' . wfMsgHtml( 'undeletecomment' ) . '</strong></td>';
659 $table .= '<td>' . wfInput( 'wpComment', 50, $this->mComment ) . '</td>';
660 $table .= '</tr><tr><td>&nbsp;</td><td>';
661 $table .= wfSubmitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore' ) );
662 $table .= wfElement( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ) ) );
663 $table .= '</td></tr></table></fieldset>';
664 $wgOut->addHtml( $table );
667 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
669 if( $haveRevisions ) {
670 # The page's stored (deleted) history:
671 $wgOut->addHTML("<ul>");
672 $target = urlencode( $this->mTarget );
673 while( $row = $revisions->fetchObject() ) {
674 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
675 if ( $this->mAllowed ) {
676 $checkBox = wfCheck( "ts$ts" );
677 $pageLink = $sk->makeKnownLinkObj( $titleObj,
678 $wgLang->timeanddate( $ts, true ),
679 "target=$target&timestamp=$ts" );
680 } else {
681 $checkBox = '';
682 $pageLink = $wgLang->timeanddate( $ts, true );
684 $userLink = $sk->userLink( $row->ar_user, $row->ar_user_text ) . $sk->userToolLinks( $row->ar_user, $row->ar_user_text );
685 $comment = $sk->commentBlock( $row->ar_comment );
686 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );
689 $revisions->free();
690 $wgOut->addHTML("</ul>");
691 } else {
692 $wgOut->addWikiText( wfMsg( "nohistory" ) );
696 if( $haveFiles ) {
697 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'imghistory' ) . "</h2>\n" );
698 $wgOut->addHtml( "<ul>" );
699 while( $row = $files->fetchObject() ) {
700 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
701 if ( $this->mAllowed && $row->fa_storage_key ) {
702 $checkBox = wfCheck( "fileid" . $row->fa_id );
703 $key = urlencode( $row->fa_storage_key );
704 $target = urlencode( $this->mTarget );
705 $pageLink = $sk->makeKnownLinkObj( $titleObj,
706 $wgLang->timeanddate( $ts, true ),
707 "target=$target&file=$key" );
708 } else {
709 $checkBox = '';
710 $pageLink = $wgLang->timeanddate( $ts, true );
712 $userLink = $sk->userLink( $row->fa_user, $row->fa_user_text ) . $sk->userToolLinks( $row->fa_user, $row->fa_user_text );
713 $data =
714 wfMsgHtml( 'widthheight',
715 $wgLang->formatNum( $row->fa_width ),
716 $wgLang->formatNum( $row->fa_height ) ) .
717 ' (' .
718 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
719 ')';
720 $comment = $sk->commentBlock( $row->fa_description );
721 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
723 $files->free();
724 $wgOut->addHTML( "</ul>" );
727 if ( $this->mAllowed ) {
728 # Slip in the hidden controls here
729 $misc = wfHidden( 'target', $this->mTarget );
730 $misc .= wfHidden( 'wpEditToken', $wgUser->editToken() );
731 $wgOut->addHtml( $misc . '</form>' );
734 return true;
737 function undelete() {
738 global $wgOut, $wgUser;
739 if( !is_null( $this->mTargetObj ) ) {
740 $archive = new PageArchive( $this->mTargetObj );
742 $ok = $archive->undelete(
743 $this->mTargetTimestamp,
744 $this->mComment,
745 $this->mFileVersions );
747 if( $ok ) {
748 $skin =& $wgUser->getSkin();
749 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
750 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
751 return true;
754 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
755 return false;