* (bug 6617) Validate timestamps on Special: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 # FIXME: update article count if changed...
354 $article->updateRevisionOn( $dbw, $revision, $previousRevId );
355
356 # Finally, clean up the link tables
357 $options = new ParserOptions;
358 $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options,
359 true, true, $newRevId );
360 $u = new LinksUpdate( $this->title, $parserOutput );
361 $u->doUpdate();
362
363 #TODO: SearchUpdate, etc.
364 }
365
366 if( $newid ) {
367 Article::onArticleCreate( $this->title );
368 } else {
369 Article::onArticleEdit( $this->title );
370 }
371 } else {
372 # Something went terribly wrong!
373 }
374
375 # Now that it's safely stored, take it out of the archive
376 $dbw->delete( 'archive',
377 /* WHERE */ array(
378 'ar_namespace' => $this->title->getNamespace(),
379 'ar_title' => $this->title->getDBkey(),
380 $oldones ),
381 __METHOD__ );
382
383 return $restored;
384 }
385
386 }
387
388 /**
389 *
390 * @package MediaWiki
391 * @subpackage SpecialPage
392 */
393 class UndeleteForm {
394 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
395 var $mTargetTimestamp, $mAllowed, $mComment;
396
397 function UndeleteForm( &$request, $par = "" ) {
398 global $wgUser;
399 $this->mAction = $request->getVal( 'action' );
400 $this->mTarget = $request->getVal( 'target' );
401 $time = $request->getVal( 'timestamp' );
402 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
403 $this->mFile = $request->getVal( 'file' );
404
405 $posted = $request->wasPosted() &&
406 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
407 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
408 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
409 $this->mComment = $request->getText( 'wpComment' );
410
411 if( $par != "" ) {
412 $this->mTarget = $par;
413 }
414 if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
415 $this->mAllowed = true;
416 } else {
417 $this->mAllowed = false;
418 $this->mTimestamp = '';
419 $this->mRestore = false;
420 }
421 if ( $this->mTarget !== "" ) {
422 $this->mTargetObj = Title::newFromURL( $this->mTarget );
423 } else {
424 $this->mTargetObj = NULL;
425 }
426 if( $this->mRestore ) {
427 $timestamps = array();
428 $this->mFileVersions = array();
429 foreach( $_REQUEST as $key => $val ) {
430 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
431 array_push( $timestamps, $matches[1] );
432 }
433
434 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
435 $this->mFileVersions[] = intval( $matches[1] );
436 }
437 }
438 rsort( $timestamps );
439 $this->mTargetTimestamp = $timestamps;
440 }
441 }
442
443 function execute() {
444
445 if( is_null( $this->mTargetObj ) ) {
446 return $this->showList();
447 }
448 if( $this->mTimestamp !== '' ) {
449 return $this->showRevision( $this->mTimestamp );
450 }
451 if( $this->mFile !== null ) {
452 return $this->showFile( $this->mFile );
453 }
454 if( $this->mRestore && $this->mAction == "submit" ) {
455 return $this->undelete();
456 }
457 return $this->showHistory();
458 }
459
460 /* private */ function showList() {
461 global $wgLang, $wgContLang, $wgUser, $wgOut;
462
463 # List undeletable articles
464 $result = PageArchive::listAllPages();
465
466 if ( $this->mAllowed ) {
467 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
468 } else {
469 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
470 }
471 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
472
473 $sk = $wgUser->getSkin();
474 $undelete =& Title::makeTitle( NS_SPECIAL, 'Undelete' );
475 $wgOut->addHTML( "<ul>\n" );
476 while( $row = $result->fetchObject() ) {
477 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
478 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
479 $revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
480 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
481 }
482 $result->free();
483 $wgOut->addHTML( "</ul>\n" );
484
485 return true;
486 }
487
488 /* private */ function showRevision( $timestamp ) {
489 global $wgLang, $wgUser, $wgOut;
490
491 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
492
493 $archive = new PageArchive( $this->mTargetObj );
494 $text = $archive->getRevisionText( $timestamp );
495
496 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
497 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
498 $wgLang->date( $timestamp ) ) . ")\n" );
499
500 if( $this->mPreview ) {
501 $wgOut->addHtml( "<hr />\n" );
502 $wgOut->addWikiText( $text );
503 }
504
505 $self = Title::makeTitle( NS_SPECIAL, "Undelete" );
506
507 $wgOut->addHtml(
508 wfElement( 'textarea', array(
509 'readonly' => true,
510 'cols' => intval( $wgUser->getOption( 'cols' ) ),
511 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
512 $text . "\n" ) .
513 wfOpenElement( 'div' ) .
514 wfOpenElement( 'form', array(
515 'method' => 'post',
516 'action' => $self->getLocalURL( "action=submit" ) ) ) .
517 wfElement( 'input', array(
518 'type' => 'hidden',
519 'name' => 'target',
520 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
521 wfElement( 'input', array(
522 'type' => 'hidden',
523 'name' => 'timestamp',
524 'value' => $timestamp ) ) .
525 wfElement( 'input', array(
526 'type' => 'hidden',
527 'name' => 'wpEditToken',
528 'value' => $wgUser->editToken() ) ) .
529 wfElement( 'input', array(
530 'type' => 'hidden',
531 'name' => 'preview',
532 'value' => '1' ) ) .
533 wfElement( 'input', array(
534 'type' => 'submit',
535 'value' => wfMsg( 'showpreview' ) ) ) .
536 wfCloseElement( 'form' ) .
537 wfCloseElement( 'div' ) );
538 }
539
540 /**
541 * Show a deleted file version requested by the visitor.
542 */
543 function showFile( $key ) {
544 global $wgOut;
545 $wgOut->disable();
546
547 $store = FileStore::get( 'deleted' );
548 $store->stream( $key );
549 }
550
551 /* private */ function showHistory() {
552 global $wgLang, $wgUser, $wgOut;
553
554 $sk = $wgUser->getSkin();
555 if ( $this->mAllowed ) {
556 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
557 } else {
558 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
559 }
560
561 $archive = new PageArchive( $this->mTargetObj );
562 $text = $archive->getLastRevisionText();
563 /*
564 if( is_null( $text ) ) {
565 $wgOut->addWikiText( wfMsg( "nohistory" ) );
566 return;
567 }
568 */
569 if ( $this->mAllowed ) {
570 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
571 } else {
572 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
573 }
574
575 # List all stored revisions
576 $revisions = $archive->listRevisions();
577 $files = $archive->listFiles();
578
579 $haveRevisions = $revisions && $revisions->numRows() > 0;
580 $haveFiles = $files && $files->numRows() > 0;
581
582 # Batch existence check on user and talk pages
583 if( $haveRevisions ) {
584 $batch = new LinkBatch();
585 while( $row = $revisions->fetchObject() ) {
586 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
587 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
588 }
589 $batch->execute();
590 $revisions->seek( 0 );
591 }
592 if( $haveFiles ) {
593 $batch = new LinkBatch();
594 while( $row = $files->fetchObject() ) {
595 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
596 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
597 }
598 $batch->execute();
599 $files->seek( 0 );
600 }
601
602 if ( $this->mAllowed ) {
603 $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
604 $action = $titleObj->getLocalURL( "action=submit" );
605 # Start the form here
606 $top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
607 $wgOut->addHtml( $top );
608 }
609
610 # Show relevant lines from the deletion log:
611 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
612 $logViewer = new LogViewer(
613 new LogReader(
614 new FauxRequest(
615 array( 'page' => $this->mTargetObj->getPrefixedText(),
616 'type' => 'delete' ) ) ) );
617 $logViewer->showList( $wgOut );
618
619 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
620 # Format the user-visible controls (comment field, submission button)
621 # in a nice little table
622 $table = '<fieldset><table><tr>';
623 $table .= '<td colspan="2">' . wfMsgWikiHtml( 'undeleteextrahelp' ) . '</td></tr><tr>';
624 $table .= '<td align="right"><strong>' . wfMsgHtml( 'undeletecomment' ) . '</strong></td>';
625 $table .= '<td>' . wfInput( 'wpComment', 50, $this->mComment ) . '</td>';
626 $table .= '</tr><tr><td>&nbsp;</td><td>';
627 $table .= wfSubmitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore' ) );
628 $table .= wfElement( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ) ) );
629 $table .= '</td></tr></table></fieldset>';
630 $wgOut->addHtml( $table );
631 }
632
633 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
634
635 if( $haveRevisions ) {
636 # The page's stored (deleted) history:
637 $wgOut->addHTML("<ul>");
638 $target = urlencode( $this->mTarget );
639 while( $row = $revisions->fetchObject() ) {
640 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
641 if ( $this->mAllowed ) {
642 $checkBox = wfCheck( "ts$ts" );
643 $pageLink = $sk->makeKnownLinkObj( $titleObj,
644 $wgLang->timeanddate( $ts, true ),
645 "target=$target&timestamp=$ts" );
646 } else {
647 $checkBox = '';
648 $pageLink = $wgLang->timeanddate( $ts, true );
649 }
650 $userLink = $sk->userLink( $row->ar_user, $row->ar_user_text ) . $sk->userToolLinks( $row->ar_user, $row->ar_user_text );
651 $comment = $sk->commentBlock( $row->ar_comment );
652 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );
653
654 }
655 $revisions->free();
656 $wgOut->addHTML("</ul>");
657 } else {
658 $wgOut->addWikiText( wfMsg( "nohistory" ) );
659 }
660
661
662 if( $haveFiles ) {
663 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'imghistory' ) . "</h2>\n" );
664 $wgOut->addHtml( "<ul>" );
665 while( $row = $files->fetchObject() ) {
666 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
667 if ( $this->mAllowed && $row->fa_storage_key ) {
668 $checkBox = wfCheck( "fileid" . $row->fa_id );
669 $key = urlencode( $row->fa_storage_key );
670 $target = urlencode( $this->mTarget );
671 $pageLink = $sk->makeKnownLinkObj( $titleObj,
672 $wgLang->timeanddate( $ts, true ),
673 "target=$target&file=$key" );
674 } else {
675 $checkBox = '';
676 $pageLink = $wgLang->timeanddate( $ts, true );
677 }
678 $userLink = $sk->userLink( $row->fa_user, $row->fa_user_text ) . $sk->userToolLinks( $row->fa_user, $row->fa_user_text );
679 $data =
680 wfMsgHtml( 'widthheight',
681 $wgLang->formatNum( $row->fa_width ),
682 $wgLang->formatNum( $row->fa_height ) ) .
683 ' (' .
684 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
685 ')';
686 $comment = $sk->commentBlock( $row->fa_description );
687 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
688 }
689 $files->free();
690 $wgOut->addHTML( "</ul>" );
691 }
692
693 if ( $this->mAllowed ) {
694 # Slip in the hidden controls here
695 $misc = wfHidden( 'target', $this->mTarget );
696 $misc .= wfHidden( 'wpEditToken', $wgUser->editToken() );
697 $wgOut->addHtml( $misc . '</form>' );
698 }
699
700 return true;
701 }
702
703 function undelete() {
704 global $wgOut, $wgUser;
705 if( !is_null( $this->mTargetObj ) ) {
706 $archive = new PageArchive( $this->mTargetObj );
707 $ok = true;
708
709 $ok = $archive->undelete(
710 $this->mTargetTimestamp,
711 $this->mComment,
712 $this->mFileVersions );
713
714 if( $ok ) {
715 $skin =& $wgUser->getSkin();
716 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
717 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
718 return true;
719 }
720 }
721 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
722 return false;
723 }
724 }
725
726 ?>