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