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