* (bug 7510) Update article counts etc on undelete
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
1 <?php
2
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and restore deleted content
6 *
7 * @package MediaWiki
8 * @subpackage Special pages
9 */
10
11 /**
12 *
13 */
14 function wfSpecialUndelete( $par ) {
15 global $wgRequest;
16
17 $form = new UndeleteForm( $wgRequest, $par );
18 $form->execute();
19 }
20
21 /**
22 *
23 * @package MediaWiki
24 * @subpackage SpecialPage
25 */
26 class PageArchive {
27 var $title;
28
29 function PageArchive( &$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. Can be called staticaly.
40 *
41 * @return ResultWrapper
42 */
43 /* static */ function listAllPages() {
44 $dbr =& wfGetDB( DB_SLAVE );
45 $archive = $dbr->tableName( 'archive' );
46
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";
49
50 return $dbr->resultObject( $dbr->query( $sql, 'PageArchive::listAllPages' ) );
51 }
52
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.
56 *
57 * @return ResultWrapper
58 */
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;
69 }
70
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.
75 *
76 * @return ResultWrapper
77 * @fixme Does this belong in Image for fuller encapsulation?
78 */
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;
99 }
100 return null;
101 }
102
103 /**
104 * Fetch (and decompress if necessary) the stored text for the deleted
105 * revision of the page with the given timestamp.
106 *
107 * @return string
108 */
109 function getRevisionText( $timestamp ) {
110 $dbr =& wfGetDB( DB_SLAVE );
111 $row = $dbr->selectRow( 'archive',
112 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
113 array( 'ar_namespace' => $this->title->getNamespace(),
114 'ar_title' => $this->title->getDbkey(),
115 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
116 __METHOD__ );
117 if( $row ) {
118 return $this->getTextFromRow( $row );
119 } else {
120 return null;
121 }
122 }
123
124 /**
125 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
126 */
127 function getTextFromRow( $row ) {
128 if( is_null( $row->ar_text_id ) ) {
129 // An old row from MediaWiki 1.4 or previous.
130 // Text is embedded in this row in classic compression format.
131 return Revision::getRevisionText( $row, "ar_" );
132 } else {
133 // New-style: keyed to the text storage backend.
134 $dbr =& wfGetDB( DB_SLAVE );
135 $text = $dbr->selectRow( 'text',
136 array( 'old_text', 'old_flags' ),
137 array( 'old_id' => $row->ar_text_id ),
138 __METHOD__ );
139 return Revision::getRevisionText( $text );
140 }
141 }
142
143
144 /**
145 * Fetch (and decompress if necessary) the stored text of the most
146 * recently edited deleted revision of the page.
147 *
148 * If there are no archived revisions for the page, returns NULL.
149 *
150 * @return string
151 */
152 function getLastRevisionText() {
153 $dbr =& wfGetDB( DB_SLAVE );
154 $row = $dbr->selectRow( 'archive',
155 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
156 array( 'ar_namespace' => $this->title->getNamespace(),
157 'ar_title' => $this->title->getDBkey() ),
158 'PageArchive::getLastRevisionText',
159 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
160 if( $row ) {
161 return $this->getTextFromRow( $row );
162 } else {
163 return NULL;
164 }
165 }
166
167 /**
168 * Quick check if any archived revisions are present for the page.
169 * @return bool
170 */
171 function isDeleted() {
172 $dbr =& wfGetDB( DB_SLAVE );
173 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
174 array( 'ar_namespace' => $this->title->getNamespace(),
175 'ar_title' => $this->title->getDBkey() ) );
176 return ($n > 0);
177 }
178
179 /**
180 * Restore the given (or all) text and file revisions for the page.
181 * Once restored, the items will be removed from the archive tables.
182 * The deletion log will be updated with an undeletion notice.
183 *
184 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
185 * @param string $comment
186 * @param array $fileVersions
187 *
188 * @return true on success.
189 */
190 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
191 // If both the set of text revisions and file revisions are empty,
192 // restore everything. Otherwise, just restore the requested items.
193 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
194
195 $restoreText = $restoreAll || !empty( $timestamps );
196 $restoreFiles = $restoreAll || !empty( $fileVersions );
197
198 if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
199 $img = new Image( $this->title );
200 $filesRestored = $img->restore( $fileVersions );
201 } else {
202 $filesRestored = 0;
203 }
204
205 if( $restoreText ) {
206 $textRestored = $this->undeleteRevisions( $timestamps );
207 } else {
208 $textRestored = 0;
209 }
210
211 // Touch the log!
212 global $wgContLang;
213 $log = new LogPage( 'delete' );
214
215 if( $textRestored && $filesRestored ) {
216 $reason = wfMsgForContent( 'undeletedrevisions-files',
217 $wgContLang->formatNum( $textRestored ),
218 $wgContLang->formatNum( $filesRestored ) );
219 } elseif( $textRestored ) {
220 $reason = wfMsgForContent( 'undeletedrevisions',
221 $wgContLang->formatNum( $textRestored ) );
222 } elseif( $filesRestored ) {
223 $reason = wfMsgForContent( 'undeletedfiles',
224 $wgContLang->formatNum( $filesRestored ) );
225 } else {
226 wfDebug( "Undelete: nothing undeleted...\n" );
227 return false;
228 }
229
230 if( trim( $comment ) != '' )
231 $reason .= ": {$comment}";
232 $log->addEntry( 'restore', $this->title, $reason );
233
234 return true;
235 }
236
237 /**
238 * This is the meaty bit -- restores archived revisions of the given page
239 * to the cur/old tables. If the page currently exists, all revisions will
240 * be stuffed into old, otherwise the most recent will go into cur.
241 *
242 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
243 * @param string $comment
244 * @param array $fileVersions
245 *
246 * @return int number of revisions restored
247 */
248 private function undeleteRevisions( $timestamps ) {
249 global $wgParser, $wgDBtype;
250
251 $restoreAll = empty( $timestamps );
252
253 $dbw =& wfGetDB( DB_MASTER );
254 extract( $dbw->tableNames( 'page', 'archive' ) );
255
256 # Does this page already exist? We'll have to update it...
257 $article = new Article( $this->title );
258 $options = ( $wgDBtype == 'postgres' )
259 ? '' // pg doesn't support this?
260 : 'FOR UPDATE';
261 $page = $dbw->selectRow( 'page',
262 array( 'page_id', 'page_latest' ),
263 array( 'page_namespace' => $this->title->getNamespace(),
264 'page_title' => $this->title->getDBkey() ),
265 __METHOD__,
266 $options );
267 if( $page ) {
268 # Page already exists. Import the history, and if necessary
269 # we'll update the latest revision field in the record.
270 $newid = 0;
271 $pageId = $page->page_id;
272 $previousRevId = $page->page_latest;
273 } else {
274 # Have to create a new article...
275 $newid = $article->insertOn( $dbw );
276 $pageId = $newid;
277 $previousRevId = 0;
278 }
279
280 if( $restoreAll ) {
281 $oldones = '1 = 1'; # All revisions...
282 } else {
283 $oldts = implode( ',',
284 array_map( array( &$dbw, 'addQuotes' ),
285 array_map( array( &$dbw, 'timestamp' ),
286 $timestamps ) ) );
287
288 $oldones = "ar_timestamp IN ( {$oldts} )";
289 }
290
291 /**
292 * Restore each revision...
293 */
294 $result = $dbw->select( 'archive',
295 /* fields */ array(
296 'ar_rev_id',
297 'ar_text',
298 'ar_comment',
299 'ar_user',
300 'ar_user_text',
301 'ar_timestamp',
302 'ar_minor_edit',
303 'ar_flags',
304 'ar_text_id' ),
305 /* WHERE */ array(
306 'ar_namespace' => $this->title->getNamespace(),
307 'ar_title' => $this->title->getDBkey(),
308 $oldones ),
309 __METHOD__,
310 /* options */ array(
311 'ORDER BY' => 'ar_timestamp' )
312 );
313 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
314 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
315 return false;
316 }
317
318 $revision = null;
319 $newRevId = $previousRevId;
320 $restored = 0;
321
322 while( $row = $dbw->fetchObject( $result ) ) {
323 if( $row->ar_text_id ) {
324 // Revision was deleted in 1.5+; text is in
325 // the regular text table, use the reference.
326 // Specify null here so the so the text is
327 // dereferenced for page length info if needed.
328 $revText = null;
329 } else {
330 // Revision was deleted in 1.4 or earlier.
331 // Text is squashed into the archive row, and
332 // a new text table entry will be created for it.
333 $revText = Revision::getRevisionText( $row, 'ar_' );
334 }
335 $revision = new Revision( array(
336 'page' => $pageId,
337 'id' => $row->ar_rev_id,
338 'text' => $revText,
339 'comment' => $row->ar_comment,
340 'user' => $row->ar_user,
341 'user_text' => $row->ar_user_text,
342 'timestamp' => $row->ar_timestamp,
343 'minor_edit' => $row->ar_minor_edit,
344 'text_id' => $row->ar_text_id,
345 ) );
346 $newRevId = $revision->insertOn( $dbw );
347 $restored++;
348 }
349
350 if( $revision ) {
351 # FIXME: Update latest if newer as well...
352 if( $newid ) {
353 // Attach the latest revision to the page...
354 $article->updateRevisionOn( $dbw, $revision, $previousRevId );
355
356 // Update site stats, link tables, etc
357 $article->createUpdates( $revision );
358 }
359
360 if( $newid ) {
361 Article::onArticleCreate( $this->title );
362 } else {
363 Article::onArticleEdit( $this->title );
364 }
365 } else {
366 # Something went terribly wrong!
367 }
368
369 # Now that it's safely stored, take it out of the archive
370 $dbw->delete( 'archive',
371 /* WHERE */ array(
372 'ar_namespace' => $this->title->getNamespace(),
373 'ar_title' => $this->title->getDBkey(),
374 $oldones ),
375 __METHOD__ );
376
377 return $restored;
378 }
379
380 }
381
382 /**
383 *
384 * @package MediaWiki
385 * @subpackage SpecialPage
386 */
387 class UndeleteForm {
388 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
389 var $mTargetTimestamp, $mAllowed, $mComment;
390
391 function UndeleteForm( &$request, $par = "" ) {
392 global $wgUser;
393 $this->mAction = $request->getVal( 'action' );
394 $this->mTarget = $request->getVal( 'target' );
395 $time = $request->getVal( 'timestamp' );
396 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
397 $this->mFile = $request->getVal( 'file' );
398
399 $posted = $request->wasPosted() &&
400 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
401 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
402 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
403 $this->mComment = $request->getText( 'wpComment' );
404
405 if( $par != "" ) {
406 $this->mTarget = $par;
407 }
408 if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
409 $this->mAllowed = true;
410 } else {
411 $this->mAllowed = false;
412 $this->mTimestamp = '';
413 $this->mRestore = false;
414 }
415 if ( $this->mTarget !== "" ) {
416 $this->mTargetObj = Title::newFromURL( $this->mTarget );
417 } else {
418 $this->mTargetObj = NULL;
419 }
420 if( $this->mRestore ) {
421 $timestamps = array();
422 $this->mFileVersions = array();
423 foreach( $_REQUEST as $key => $val ) {
424 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
425 array_push( $timestamps, $matches[1] );
426 }
427
428 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
429 $this->mFileVersions[] = intval( $matches[1] );
430 }
431 }
432 rsort( $timestamps );
433 $this->mTargetTimestamp = $timestamps;
434 }
435 }
436
437 function execute() {
438
439 if( is_null( $this->mTargetObj ) ) {
440 return $this->showList();
441 }
442 if( $this->mTimestamp !== '' ) {
443 return $this->showRevision( $this->mTimestamp );
444 }
445 if( $this->mFile !== null ) {
446 return $this->showFile( $this->mFile );
447 }
448 if( $this->mRestore && $this->mAction == "submit" ) {
449 return $this->undelete();
450 }
451 return $this->showHistory();
452 }
453
454 /* private */ function showList() {
455 global $wgLang, $wgContLang, $wgUser, $wgOut;
456
457 # List undeletable articles
458 $result = PageArchive::listAllPages();
459
460 if ( $this->mAllowed ) {
461 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
462 } else {
463 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
464 }
465 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
466
467 $sk = $wgUser->getSkin();
468 $undelete =& Title::makeTitle( NS_SPECIAL, 'Undelete' );
469 $wgOut->addHTML( "<ul>\n" );
470 while( $row = $result->fetchObject() ) {
471 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
472 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
473 $revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
474 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
475 }
476 $result->free();
477 $wgOut->addHTML( "</ul>\n" );
478
479 return true;
480 }
481
482 /* private */ function showRevision( $timestamp ) {
483 global $wgLang, $wgUser, $wgOut;
484
485 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
486
487 $archive = new PageArchive( $this->mTargetObj );
488 $text = $archive->getRevisionText( $timestamp );
489
490 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
491 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
492 $wgLang->date( $timestamp ) ) . ")\n" );
493
494 if( $this->mPreview ) {
495 $wgOut->addHtml( "<hr />\n" );
496 $wgOut->addWikiText( $text );
497 }
498
499 $self = Title::makeTitle( NS_SPECIAL, "Undelete" );
500
501 $wgOut->addHtml(
502 wfElement( 'textarea', array(
503 'readonly' => true,
504 'cols' => intval( $wgUser->getOption( 'cols' ) ),
505 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
506 $text . "\n" ) .
507 wfOpenElement( 'div' ) .
508 wfOpenElement( 'form', array(
509 'method' => 'post',
510 'action' => $self->getLocalURL( "action=submit" ) ) ) .
511 wfElement( 'input', array(
512 'type' => 'hidden',
513 'name' => 'target',
514 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
515 wfElement( 'input', array(
516 'type' => 'hidden',
517 'name' => 'timestamp',
518 'value' => $timestamp ) ) .
519 wfElement( 'input', array(
520 'type' => 'hidden',
521 'name' => 'wpEditToken',
522 'value' => $wgUser->editToken() ) ) .
523 wfElement( 'input', array(
524 'type' => 'hidden',
525 'name' => 'preview',
526 'value' => '1' ) ) .
527 wfElement( 'input', array(
528 'type' => 'submit',
529 'value' => wfMsg( 'showpreview' ) ) ) .
530 wfCloseElement( 'form' ) .
531 wfCloseElement( 'div' ) );
532 }
533
534 /**
535 * Show a deleted file version requested by the visitor.
536 */
537 function showFile( $key ) {
538 global $wgOut;
539 $wgOut->disable();
540
541 $store = FileStore::get( 'deleted' );
542 $store->stream( $key );
543 }
544
545 /* private */ function showHistory() {
546 global $wgLang, $wgUser, $wgOut;
547
548 $sk = $wgUser->getSkin();
549 if ( $this->mAllowed ) {
550 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
551 } else {
552 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
553 }
554
555 $archive = new PageArchive( $this->mTargetObj );
556 $text = $archive->getLastRevisionText();
557 /*
558 if( is_null( $text ) ) {
559 $wgOut->addWikiText( wfMsg( "nohistory" ) );
560 return;
561 }
562 */
563 if ( $this->mAllowed ) {
564 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
565 } else {
566 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
567 }
568
569 # List all stored revisions
570 $revisions = $archive->listRevisions();
571 $files = $archive->listFiles();
572
573 $haveRevisions = $revisions && $revisions->numRows() > 0;
574 $haveFiles = $files && $files->numRows() > 0;
575
576 # Batch existence check on user and talk pages
577 if( $haveRevisions ) {
578 $batch = new LinkBatch();
579 while( $row = $revisions->fetchObject() ) {
580 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
581 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
582 }
583 $batch->execute();
584 $revisions->seek( 0 );
585 }
586 if( $haveFiles ) {
587 $batch = new LinkBatch();
588 while( $row = $files->fetchObject() ) {
589 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
590 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
591 }
592 $batch->execute();
593 $files->seek( 0 );
594 }
595
596 if ( $this->mAllowed ) {
597 $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
598 $action = $titleObj->getLocalURL( "action=submit" );
599 # Start the form here
600 $top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
601 $wgOut->addHtml( $top );
602 }
603
604 # Show relevant lines from the deletion log:
605 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
606 $logViewer = new LogViewer(
607 new LogReader(
608 new FauxRequest(
609 array( 'page' => $this->mTargetObj->getPrefixedText(),
610 'type' => 'delete' ) ) ) );
611 $logViewer->showList( $wgOut );
612
613 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
614 # Format the user-visible controls (comment field, submission button)
615 # in a nice little table
616 $table = '<fieldset><table><tr>';
617 $table .= '<td colspan="2">' . wfMsgWikiHtml( 'undeleteextrahelp' ) . '</td></tr><tr>';
618 $table .= '<td align="right"><strong>' . wfMsgHtml( 'undeletecomment' ) . '</strong></td>';
619 $table .= '<td>' . wfInput( 'wpComment', 50, $this->mComment ) . '</td>';
620 $table .= '</tr><tr><td>&nbsp;</td><td>';
621 $table .= wfSubmitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore' ) );
622 $table .= wfElement( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ) ) );
623 $table .= '</td></tr></table></fieldset>';
624 $wgOut->addHtml( $table );
625 }
626
627 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
628
629 if( $haveRevisions ) {
630 # The page's stored (deleted) history:
631 $wgOut->addHTML("<ul>");
632 $target = urlencode( $this->mTarget );
633 while( $row = $revisions->fetchObject() ) {
634 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
635 if ( $this->mAllowed ) {
636 $checkBox = wfCheck( "ts$ts" );
637 $pageLink = $sk->makeKnownLinkObj( $titleObj,
638 $wgLang->timeanddate( $ts, true ),
639 "target=$target&timestamp=$ts" );
640 } else {
641 $checkBox = '';
642 $pageLink = $wgLang->timeanddate( $ts, true );
643 }
644 $userLink = $sk->userLink( $row->ar_user, $row->ar_user_text ) . $sk->userToolLinks( $row->ar_user, $row->ar_user_text );
645 $comment = $sk->commentBlock( $row->ar_comment );
646 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );
647
648 }
649 $revisions->free();
650 $wgOut->addHTML("</ul>");
651 } else {
652 $wgOut->addWikiText( wfMsg( "nohistory" ) );
653 }
654
655
656 if( $haveFiles ) {
657 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'imghistory' ) . "</h2>\n" );
658 $wgOut->addHtml( "<ul>" );
659 while( $row = $files->fetchObject() ) {
660 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
661 if ( $this->mAllowed && $row->fa_storage_key ) {
662 $checkBox = wfCheck( "fileid" . $row->fa_id );
663 $key = urlencode( $row->fa_storage_key );
664 $target = urlencode( $this->mTarget );
665 $pageLink = $sk->makeKnownLinkObj( $titleObj,
666 $wgLang->timeanddate( $ts, true ),
667 "target=$target&file=$key" );
668 } else {
669 $checkBox = '';
670 $pageLink = $wgLang->timeanddate( $ts, true );
671 }
672 $userLink = $sk->userLink( $row->fa_user, $row->fa_user_text ) . $sk->userToolLinks( $row->fa_user, $row->fa_user_text );
673 $data =
674 wfMsgHtml( 'widthheight',
675 $wgLang->formatNum( $row->fa_width ),
676 $wgLang->formatNum( $row->fa_height ) ) .
677 ' (' .
678 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
679 ')';
680 $comment = $sk->commentBlock( $row->fa_description );
681 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
682 }
683 $files->free();
684 $wgOut->addHTML( "</ul>" );
685 }
686
687 if ( $this->mAllowed ) {
688 # Slip in the hidden controls here
689 $misc = wfHidden( 'target', $this->mTarget );
690 $misc .= wfHidden( 'wpEditToken', $wgUser->editToken() );
691 $wgOut->addHtml( $misc . '</form>' );
692 }
693
694 return true;
695 }
696
697 function undelete() {
698 global $wgOut, $wgUser;
699 if( !is_null( $this->mTargetObj ) ) {
700 $archive = new PageArchive( $this->mTargetObj );
701 $ok = true;
702
703 $ok = $archive->undelete(
704 $this->mTargetTimestamp,
705 $this->mComment,
706 $this->mFileVersions );
707
708 if( $ok ) {
709 $skin =& $wgUser->getSkin();
710 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
711 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
712 return true;
713 }
714 }
715 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
716 return false;
717 }
718 }
719
720 ?>