9793b302b265af715d211c408d0137bc29e54c68
[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 $wgDBtype;
282
283 $restoreAll = empty( $timestamps );
284
285 $dbw =& wfGetDB( DB_MASTER );
286 $page = $dbw->tableName( '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 $matches = array();
457 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
458 array_push( $timestamps, $matches[1] );
459 }
460
461 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
462 $this->mFileVersions[] = intval( $matches[1] );
463 }
464 }
465 rsort( $timestamps );
466 $this->mTargetTimestamp = $timestamps;
467 }
468 }
469
470 function execute() {
471
472 if( is_null( $this->mTargetObj ) ) {
473 return $this->showList();
474 }
475 if( $this->mTimestamp !== '' ) {
476 return $this->showRevision( $this->mTimestamp );
477 }
478 if( $this->mFile !== null ) {
479 return $this->showFile( $this->mFile );
480 }
481 if( $this->mRestore && $this->mAction == "submit" ) {
482 return $this->undelete();
483 }
484 return $this->showHistory();
485 }
486
487 /* private */ function showList() {
488 global $wgLang, $wgContLang, $wgUser, $wgOut;
489
490 # List undeletable articles
491 $result = PageArchive::listAllPages();
492
493 if ( $this->mAllowed ) {
494 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
495 } else {
496 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
497 }
498 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
499
500 $sk = $wgUser->getSkin();
501 $undelete =& SpecialPage::getTitleFor( 'Undelete' );
502 $wgOut->addHTML( "<ul>\n" );
503 while( $row = $result->fetchObject() ) {
504 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
505 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
506 $revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
507 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
508 }
509 $result->free();
510 $wgOut->addHTML( "</ul>\n" );
511
512 return true;
513 }
514
515 /* private */ function showRevision( $timestamp ) {
516 global $wgLang, $wgUser, $wgOut;
517
518 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
519
520 $archive = new PageArchive( $this->mTargetObj );
521 $rev = $archive->getRevision( $timestamp );
522
523 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
524 $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
525 $wgLang->date( $timestamp ) ) . ")\n" );
526
527 if( !$rev ) {
528 $wgOut->addWikiText( wfMsg( 'undeleterevision-missing' ) );
529 return;
530 }
531
532 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
533
534 if( $this->mPreview ) {
535 $wgOut->addHtml( "<hr />\n" );
536 $article = new Article ( $archive->title ); # OutputPage wants an Article obj
537 $wgOut->addPrimaryWikiText( $rev->getText(), $article, false );
538 }
539
540 $self = SpecialPage::getTitleFor( "Undelete" );
541
542 $wgOut->addHtml(
543 wfElement( 'textarea', array(
544 'readonly' => true,
545 'cols' => intval( $wgUser->getOption( 'cols' ) ),
546 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
547 $rev->getText() . "\n" ) .
548 wfOpenElement( 'div' ) .
549 wfOpenElement( 'form', array(
550 'method' => 'post',
551 'action' => $self->getLocalURL( "action=submit" ) ) ) .
552 wfElement( 'input', array(
553 'type' => 'hidden',
554 'name' => 'target',
555 'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
556 wfElement( 'input', array(
557 'type' => 'hidden',
558 'name' => 'timestamp',
559 'value' => $timestamp ) ) .
560 wfElement( 'input', array(
561 'type' => 'hidden',
562 'name' => 'wpEditToken',
563 'value' => $wgUser->editToken() ) ) .
564 wfElement( 'input', array(
565 'type' => 'hidden',
566 'name' => 'preview',
567 'value' => '1' ) ) .
568 wfElement( 'input', array(
569 'type' => 'submit',
570 'value' => wfMsg( 'showpreview' ) ) ) .
571 wfCloseElement( 'form' ) .
572 wfCloseElement( 'div' ) );
573 }
574
575 /**
576 * Show a deleted file version requested by the visitor.
577 */
578 function showFile( $key ) {
579 global $wgOut;
580 $wgOut->disable();
581
582 $store = FileStore::get( 'deleted' );
583 $store->stream( $key );
584 }
585
586 /* private */ function showHistory() {
587 global $wgLang, $wgUser, $wgOut;
588
589 $sk = $wgUser->getSkin();
590 if ( $this->mAllowed ) {
591 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
592 } else {
593 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
594 }
595
596 $archive = new PageArchive( $this->mTargetObj );
597 $text = $archive->getLastRevisionText();
598 /*
599 if( is_null( $text ) ) {
600 $wgOut->addWikiText( wfMsg( "nohistory" ) );
601 return;
602 }
603 */
604 if ( $this->mAllowed ) {
605 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
606 } else {
607 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
608 }
609
610 # List all stored revisions
611 $revisions = $archive->listRevisions();
612 $files = $archive->listFiles();
613
614 $haveRevisions = $revisions && $revisions->numRows() > 0;
615 $haveFiles = $files && $files->numRows() > 0;
616
617 # Batch existence check on user and talk pages
618 if( $haveRevisions ) {
619 $batch = new LinkBatch();
620 while( $row = $revisions->fetchObject() ) {
621 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->ar_user_text ) );
622 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ar_user_text ) );
623 }
624 $batch->execute();
625 $revisions->seek( 0 );
626 }
627 if( $haveFiles ) {
628 $batch = new LinkBatch();
629 while( $row = $files->fetchObject() ) {
630 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->fa_user_text ) );
631 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->fa_user_text ) );
632 }
633 $batch->execute();
634 $files->seek( 0 );
635 }
636
637 if ( $this->mAllowed ) {
638 $titleObj = SpecialPage::getTitleFor( "Undelete" );
639 $action = $titleObj->getLocalURL( "action=submit" );
640 # Start the form here
641 $top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
642 $wgOut->addHtml( $top );
643 }
644
645 # Show relevant lines from the deletion log:
646 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
647 $logViewer = new LogViewer(
648 new LogReader(
649 new FauxRequest(
650 array( 'page' => $this->mTargetObj->getPrefixedText(),
651 'type' => 'delete' ) ) ) );
652 $logViewer->showList( $wgOut );
653
654 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
655 # Format the user-visible controls (comment field, submission button)
656 # in a nice little table
657 $table = '<fieldset><table><tr>';
658 $table .= '<td colspan="2">' . wfMsgWikiHtml( 'undeleteextrahelp' ) . '</td></tr><tr>';
659 $table .= '<td align="right"><strong>' . wfMsgHtml( 'undeletecomment' ) . '</strong></td>';
660 $table .= '<td>' . wfInput( 'wpComment', 50, $this->mComment ) . '</td>';
661 $table .= '</tr><tr><td>&nbsp;</td><td>';
662 $table .= wfSubmitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore' ) );
663 $table .= wfElement( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ) ) );
664 $table .= '</td></tr></table></fieldset>';
665 $wgOut->addHtml( $table );
666 }
667
668 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
669
670 if( $haveRevisions ) {
671 # The page's stored (deleted) history:
672 $wgOut->addHTML("<ul>");
673 $target = urlencode( $this->mTarget );
674 while( $row = $revisions->fetchObject() ) {
675 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
676 if ( $this->mAllowed ) {
677 $checkBox = wfCheck( "ts$ts" );
678 $pageLink = $sk->makeKnownLinkObj( $titleObj,
679 $wgLang->timeanddate( $ts, true ),
680 "target=$target&timestamp=$ts" );
681 } else {
682 $checkBox = '';
683 $pageLink = $wgLang->timeanddate( $ts, true );
684 }
685 $userLink = $sk->userLink( $row->ar_user, $row->ar_user_text ) . $sk->userToolLinks( $row->ar_user, $row->ar_user_text );
686 $comment = $sk->commentBlock( $row->ar_comment );
687 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );
688
689 }
690 $revisions->free();
691 $wgOut->addHTML("</ul>");
692 } else {
693 $wgOut->addWikiText( wfMsg( "nohistory" ) );
694 }
695
696
697 if( $haveFiles ) {
698 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'imghistory' ) . "</h2>\n" );
699 $wgOut->addHtml( "<ul>" );
700 while( $row = $files->fetchObject() ) {
701 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
702 if ( $this->mAllowed && $row->fa_storage_key ) {
703 $checkBox = wfCheck( "fileid" . $row->fa_id );
704 $key = urlencode( $row->fa_storage_key );
705 $target = urlencode( $this->mTarget );
706 $pageLink = $sk->makeKnownLinkObj( $titleObj,
707 $wgLang->timeanddate( $ts, true ),
708 "target=$target&file=$key" );
709 } else {
710 $checkBox = '';
711 $pageLink = $wgLang->timeanddate( $ts, true );
712 }
713 $userLink = $sk->userLink( $row->fa_user, $row->fa_user_text ) . $sk->userToolLinks( $row->fa_user, $row->fa_user_text );
714 $data =
715 wfMsgHtml( 'widthheight',
716 $wgLang->formatNum( $row->fa_width ),
717 $wgLang->formatNum( $row->fa_height ) ) .
718 ' (' .
719 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
720 ')';
721 $comment = $sk->commentBlock( $row->fa_description );
722 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
723 }
724 $files->free();
725 $wgOut->addHTML( "</ul>" );
726 }
727
728 if ( $this->mAllowed ) {
729 # Slip in the hidden controls here
730 $misc = wfHidden( 'target', $this->mTarget );
731 $misc .= wfHidden( 'wpEditToken', $wgUser->editToken() );
732 $wgOut->addHtml( $misc . '</form>' );
733 }
734
735 return true;
736 }
737
738 function undelete() {
739 global $wgOut, $wgUser;
740 if( !is_null( $this->mTargetObj ) ) {
741 $archive = new PageArchive( $this->mTargetObj );
742 $ok = true;
743
744 $ok = $archive->undelete(
745 $this->mTargetTimestamp,
746 $this->mComment,
747 $this->mFileVersions );
748
749 if( $ok ) {
750 $skin =& $wgUser->getSkin();
751 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
752 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
753 return true;
754 }
755 }
756 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
757 return false;
758 }
759 }
760
761 ?>