Bloody hell, not another pretend feature
[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 * @deprecated Use getRevision() for more flexible information
109 */
110 function getRevisionText( $timestamp ) {
111 $rev = $this->getRevision( $timestamp );
112 return $rev ? $rev->getText() : null;
113 }
114
115 /**
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
120 */
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;
153 }
154 }
155
156 /**
157 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
158 */
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 );
172 }
173 }
174
175
176 /**
177 * Fetch (and decompress if necessary) the stored text of the most
178 * recently edited deleted revision of the page.
179 *
180 * If there are no archived revisions for the page, returns NULL.
181 *
182 * @return string
183 */
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;
196 }
197 }
198
199 /**
200 * Quick check if any archived revisions are present for the page.
201 * @return bool
202 */
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);
209 }
210
211 /**
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.
215 *
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
219 *
220 * @return true on success.
221 */
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 );
226
227 $restoreText = $restoreAll || !empty( $timestamps );
228 $restoreFiles = $restoreAll || !empty( $fileVersions );
229
230 if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
231 $img = new Image( $this->title );
232 $filesRestored = $img->restore( $fileVersions );
233 } else {
234 $filesRestored = 0;
235 }
236
237 if( $restoreText ) {
238 $textRestored = $this->undeleteRevisions( $timestamps );
239 } else {
240 $textRestored = 0;
241 }
242
243 // Touch the log!
244 global $wgContLang;
245 $log = new LogPage( 'delete' );
246
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;
260 }
261
262 if( trim( $comment ) != '' )
263 $reason .= ": {$comment}";
264 $log->addEntry( 'restore', $this->title, $reason );
265
266 return true;
267 }
268
269 /**
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.
273 *
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
277 *
278 * @return int number of revisions restored
279 */
280 private function undeleteRevisions( $timestamps ) {
281 global $wgParser, $wgDBtype;
282
283 $restoreAll = empty( $timestamps );
284
285 $dbw =& wfGetDB( DB_MASTER );
286 extract( $dbw->tableNames( 'page', 'archive' ) );
287
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;
310 }
311
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 ) ) );
319
320 $oldones = "ar_timestamp IN ( {$oldts} )";
321 }
322
323 /**
324 * Restore each revision...
325 */
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' )
344 );
345 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
346 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
347 return false;
348 }
349
350 $revision = null;
351 $newRevId = $previousRevId;
352 $restored = 0;
353
354 while( $row = $dbw->fetchObject( $result ) ) {
355 if( $row->ar_text_id ) {
356 // Revision was deleted in 1.5+; text is in
357 // the regular text table, use the reference.
358 // Specify null here so the so the text is
359 // dereferenced for page length info if needed.
360 $revText = null;
361 } else {
362 // Revision was deleted in 1.4 or earlier.
363 // Text is squashed into the archive row, and
364 // a new text table entry will be created for it.
365 $revText = Revision::getRevisionText( $row, 'ar_' );
366 }
367 $revision = new Revision( array(
368 'page' => $pageId,
369 'id' => $row->ar_rev_id,
370 'text' => $revText,
371 'comment' => $row->ar_comment,
372 'user' => $row->ar_user,
373 'user_text' => $row->ar_user_text,
374 'timestamp' => $row->ar_timestamp,
375 'minor_edit' => $row->ar_minor_edit,
376 'text_id' => $row->ar_text_id,
377 ) );
378 $newRevId = $revision->insertOn( $dbw );
379 $restored++;
380 }
381
382 if( $revision ) {
383 # FIXME: Update latest if newer as well...
384 if( $newid ) {
385 // Attach the latest revision to the page...
386 $article->updateRevisionOn( $dbw, $revision, $previousRevId );
387
388 // Update site stats, link tables, etc
389 $article->createUpdates( $revision );
390 }
391
392 if( $newid ) {
393 Article::onArticleCreate( $this->title );
394 } else {
395 Article::onArticleEdit( $this->title );
396 }
397 } else {
398 # Something went terribly wrong!
399 }
400
401 # Now that it's safely stored, take it out of the archive
402 $dbw->delete( 'archive',
403 /* WHERE */ array(
404 'ar_namespace' => $this->title->getNamespace(),
405 'ar_title' => $this->title->getDBkey(),
406 $oldones ),
407 __METHOD__ );
408
409 return $restored;
410 }
411
412 }
413
414 /**
415 *
416 * @package MediaWiki
417 * @subpackage SpecialPage
418 */
419 class UndeleteForm {
420 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
421 var $mTargetTimestamp, $mAllowed, $mComment;
422
423 function UndeleteForm( &$request, $par = "" ) {
424 global $wgUser;
425 $this->mAction = $request->getVal( 'action' );
426 $this->mTarget = $request->getVal( 'target' );
427 $time = $request->getVal( 'timestamp' );
428 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
429 $this->mFile = $request->getVal( 'file' );
430
431 $posted = $request->wasPosted() &&
432 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
433 $this->mRestore = $request->getCheck( 'restore' ) && $posted;
434 $this->mPreview = $request->getCheck( 'preview' ) && $posted;
435 $this->mComment = $request->getText( 'wpComment' );
436
437 if( $par != "" ) {
438 $this->mTarget = $par;
439 }
440 if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
441 $this->mAllowed = true;
442 } else {
443 $this->mAllowed = false;
444 $this->mTimestamp = '';
445 $this->mRestore = false;
446 }
447 if ( $this->mTarget !== "" ) {
448 $this->mTargetObj = Title::newFromURL( $this->mTarget );
449 } else {
450 $this->mTargetObj = NULL;
451 }
452 if( $this->mRestore ) {
453 $timestamps = array();
454 $this->mFileVersions = array();
455 foreach( $_REQUEST as $key => $val ) {
456 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
457 array_push( $timestamps, $matches[1] );
458 }
459
460 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
461 $this->mFileVersions[] = intval( $matches[1] );
462 }
463 }
464 rsort( $timestamps );
465 $this->mTargetTimestamp = $timestamps;
466 }
467 }
468
469 function execute() {
470
471 if( is_null( $this->mTargetObj ) ) {
472 return $this->showList();
473 }
474 if( $this->mTimestamp !== '' ) {
475 return $this->showRevision( $this->mTimestamp );
476 }
477 if( $this->mFile !== null ) {
478 return $this->showFile( $this->mFile );
479 }
480 if( $this->mRestore && $this->mAction == "submit" ) {
481 return $this->undelete();
482 }
483 return $this->showHistory();
484 }
485
486 /* private */ function showList() {
487 global $wgLang, $wgContLang, $wgUser, $wgOut;
488
489 # List undeletable articles
490 $result = PageArchive::listAllPages();
491
492 if ( $this->mAllowed ) {
493 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
494 } else {
495 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
496 }
497 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
498
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" );
507 }
508 $result->free();
509 $wgOut->addHTML( "</ul>\n" );
510
511 return true;
512 }
513
514 /* private */ function showRevision( $timestamp ) {
515 global $wgLang, $wgUser, $wgOut;
516
517 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
518
519 $archive = new PageArchive( $this->mTargetObj );
520 $rev = $archive->getRevision( $timestamp );
521
522 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
523 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
524 $wgLang->date( $timestamp ) ) . ")\n" );
525
526 if( !$rev ) {
527 $wgOut->addWikiText( wfMsg( 'undeleterevision-missing' ) );
528 return;
529 }
530
531 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
532
533 if( $this->mPreview ) {
534 $wgOut->addHtml( "<hr />\n" );
535 $wgOut->addWikiText( $rev->getText() );
536 }
537
538 $self = SpecialPage::getTitleFor( "Undelete" );
539
540 $wgOut->addHtml(
541 wfElement( 'textarea', array(
542 'readonly' => true,
543 'cols' => intval( $wgUser->getOption( 'cols' ) ),
544 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
545 $rev->getText() . "\n" ) .
546 wfOpenElement( 'div' ) .
547 wfOpenElement( 'form', array(
548 'method' => 'post',
549 'action' => $self->getLocalURL( "action=submit" ) ) ) .
550 wfElement( 'input', array(
551 'type' => 'hidden',
552 'name' => 'target',
553 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
554 wfElement( 'input', array(
555 'type' => 'hidden',
556 'name' => 'timestamp',
557 'value' => $timestamp ) ) .
558 wfElement( 'input', array(
559 'type' => 'hidden',
560 'name' => 'wpEditToken',
561 'value' => $wgUser->editToken() ) ) .
562 wfElement( 'input', array(
563 'type' => 'hidden',
564 'name' => 'preview',
565 'value' => '1' ) ) .
566 wfElement( 'input', array(
567 'type' => 'submit',
568 'value' => wfMsg( 'showpreview' ) ) ) .
569 wfCloseElement( 'form' ) .
570 wfCloseElement( 'div' ) );
571 }
572
573 /**
574 * Show a deleted file version requested by the visitor.
575 */
576 function showFile( $key ) {
577 global $wgOut;
578 $wgOut->disable();
579
580 $store = FileStore::get( 'deleted' );
581 $store->stream( $key );
582 }
583
584 /* private */ function showHistory() {
585 global $wgLang, $wgUser, $wgOut;
586
587 $sk = $wgUser->getSkin();
588 if ( $this->mAllowed ) {
589 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
590 } else {
591 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
592 }
593
594 $archive = new PageArchive( $this->mTargetObj );
595 $text = $archive->getLastRevisionText();
596 /*
597 if( is_null( $text ) ) {
598 $wgOut->addWikiText( wfMsg( "nohistory" ) );
599 return;
600 }
601 */
602 if ( $this->mAllowed ) {
603 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
604 } else {
605 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
606 }
607
608 # List all stored revisions
609 $revisions = $archive->listRevisions();
610 $files = $archive->listFiles();
611
612 $haveRevisions = $revisions && $revisions->numRows() > 0;
613 $haveFiles = $files && $files->numRows() > 0;
614
615 # Batch existence check on user and talk pages
616 if( $haveRevisions ) {
617 $batch = new LinkBatch();
618 while( $row = $revisions->fetchObject() ) {
619 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
620 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
621 }
622 $batch->execute();
623 $revisions->seek( 0 );
624 }
625 if( $haveFiles ) {
626 $batch = new LinkBatch();
627 while( $row = $files->fetchObject() ) {
628 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
629 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
630 }
631 $batch->execute();
632 $files->seek( 0 );
633 }
634
635 if ( $this->mAllowed ) {
636 $titleObj = SpecialPage::getTitleFor( "Undelete" );
637 $action = $titleObj->getLocalURL( "action=submit" );
638 # Start the form here
639 $top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
640 $wgOut->addHtml( $top );
641 }
642
643 # Show relevant lines from the deletion log:
644 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
645 $logViewer = new LogViewer(
646 new LogReader(
647 new FauxRequest(
648 array( 'page' => $this->mTargetObj->getPrefixedText(),
649 'type' => 'delete' ) ) ) );
650 $logViewer->showList( $wgOut );
651
652 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
653 # Format the user-visible controls (comment field, submission button)
654 # in a nice little table
655 $table = '<fieldset><table><tr>';
656 $table .= '<td colspan="2">' . wfMsgWikiHtml( 'undeleteextrahelp' ) . '</td></tr><tr>';
657 $table .= '<td align="right"><strong>' . wfMsgHtml( 'undeletecomment' ) . '</strong></td>';
658 $table .= '<td>' . wfInput( 'wpComment', 50, $this->mComment ) . '</td>';
659 $table .= '</tr><tr><td>&nbsp;</td><td>';
660 $table .= wfSubmitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore' ) );
661 $table .= wfElement( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ) ) );
662 $table .= '</td></tr></table></fieldset>';
663 $wgOut->addHtml( $table );
664 }
665
666 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
667
668 if( $haveRevisions ) {
669 # The page's stored (deleted) history:
670 $wgOut->addHTML("<ul>");
671 $target = urlencode( $this->mTarget );
672 while( $row = $revisions->fetchObject() ) {
673 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
674 if ( $this->mAllowed ) {
675 $checkBox = wfCheck( "ts$ts" );
676 $pageLink = $sk->makeKnownLinkObj( $titleObj,
677 $wgLang->timeanddate( $ts, true ),
678 "target=$target&timestamp=$ts" );
679 } else {
680 $checkBox = '';
681 $pageLink = $wgLang->timeanddate( $ts, true );
682 }
683 $userLink = $sk->userLink( $row->ar_user, $row->ar_user_text ) . $sk->userToolLinks( $row->ar_user, $row->ar_user_text );
684 $comment = $sk->commentBlock( $row->ar_comment );
685 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );
686
687 }
688 $revisions->free();
689 $wgOut->addHTML("</ul>");
690 } else {
691 $wgOut->addWikiText( wfMsg( "nohistory" ) );
692 }
693
694
695 if( $haveFiles ) {
696 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'imghistory' ) . "</h2>\n" );
697 $wgOut->addHtml( "<ul>" );
698 while( $row = $files->fetchObject() ) {
699 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
700 if ( $this->mAllowed && $row->fa_storage_key ) {
701 $checkBox = wfCheck( "fileid" . $row->fa_id );
702 $key = urlencode( $row->fa_storage_key );
703 $target = urlencode( $this->mTarget );
704 $pageLink = $sk->makeKnownLinkObj( $titleObj,
705 $wgLang->timeanddate( $ts, true ),
706 "target=$target&file=$key" );
707 } else {
708 $checkBox = '';
709 $pageLink = $wgLang->timeanddate( $ts, true );
710 }
711 $userLink = $sk->userLink( $row->fa_user, $row->fa_user_text ) . $sk->userToolLinks( $row->fa_user, $row->fa_user_text );
712 $data =
713 wfMsgHtml( 'widthheight',
714 $wgLang->formatNum( $row->fa_width ),
715 $wgLang->formatNum( $row->fa_height ) ) .
716 ' (' .
717 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
718 ')';
719 $comment = $sk->commentBlock( $row->fa_description );
720 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
721 }
722 $files->free();
723 $wgOut->addHTML( "</ul>" );
724 }
725
726 if ( $this->mAllowed ) {
727 # Slip in the hidden controls here
728 $misc = wfHidden( 'target', $this->mTarget );
729 $misc .= wfHidden( 'wpEditToken', $wgUser->editToken() );
730 $wgOut->addHtml( $misc . '</form>' );
731 }
732
733 return true;
734 }
735
736 function undelete() {
737 global $wgOut, $wgUser;
738 if( !is_null( $this->mTargetObj ) ) {
739 $archive = new PageArchive( $this->mTargetObj );
740 $ok = true;
741
742 $ok = $archive->undelete(
743 $this->mTargetTimestamp,
744 $this->mComment,
745 $this->mFileVersions );
746
747 if( $ok ) {
748 $skin =& $wgUser->getSkin();
749 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
750 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
751 return true;
752 }
753 }
754 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
755 return false;
756 }
757 }
758
759 ?>