Readd basic headers and <html>...</html> arround error contents that was removed...
[lhc/web/wiklou.git] / includes / actions / HistoryAction.php
1 <?php
2 /**
3 * Handles action=history.
4 * Split off from Article.php and Skin.php, 2003-12-22
5 *
6 * @file
7 */
8
9 /**
10 * This class handles printing the history page for an article. In order to
11 * be efficient, it uses timestamps rather than offsets for paging, to avoid
12 * costly LIMIT,offset queries.
13 */
14 class HistoryAction extends FormlessAction {
15 const DIR_PREV = 0;
16 const DIR_NEXT = 1;
17
18 public function getName() {
19 return 'history';
20 }
21
22 public function getRestriction() {
23 return 'read';
24 }
25
26 /**
27 * Get the Page object we are working on.
28 *
29 * @return Page
30 */
31 public function getArticle() {
32 return $this->page;
33 }
34
35 /**
36 * As we use the same small set of messages in various methods and that
37 * they are called often, we call them once and save them in $this->message
38 */
39 private function preCacheMessages() {
40 // Precache various messages
41 if ( !isset( $this->message ) ) {
42 $msgs = array( 'cur', 'last', 'pipe-separator' );
43 foreach ( $msgs as $msg ) {
44 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
45 }
46 }
47 }
48
49 /**
50 * Print the history page for an article.
51 * @return nothing
52 */
53 function onView() {
54 global $wgSquidMaxage, $wgScript;
55
56 $out = $this->getOutput();
57 $request = $this->getRequest();
58
59 // Allow client caching.
60 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
61 return; // Client cache fresh and headers sent, nothing more to do.
62 }
63
64 if ( $request->getFullRequestURL() == $this->getTitle()->getInternalURL( 'action=history' ) ) {
65 $out->setSquidMaxage( $wgSquidMaxage );
66 }
67
68 wfProfileIn( __METHOD__ );
69
70 $this->preCacheMessages();
71
72 // Setup page variables.
73 $out->setPageTitle( wfMsg( 'history-title', $this->getTitle()->getPrefixedText() ) );
74 $out->setRobotPolicy( 'noindex,nofollow' );
75 $out->setFeedAppendQuery( 'action=history' );
76 $out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) );
77
78 // Creation of a subtitle link pointing to [[Special:Log]]
79 $logPage = SpecialPage::getTitleFor( 'Log' );
80 $logLink = Linker::linkKnown(
81 $logPage,
82 wfMsgHtml( 'viewpagelogs' ),
83 array(),
84 array( 'page' => $this->getTitle()->getPrefixedText() )
85 );
86 $out->setSubtitle( $logLink );
87
88 // Handle atom/RSS feeds.
89 $feedType = $request->getVal( 'feed' );
90 if ( $feedType ) {
91 wfProfileOut( __METHOD__ );
92 return $this->feed( $feedType );
93 }
94
95 // Fail nicely if article doesn't exist.
96 if ( !$this->getTitle()->exists() ) {
97 $out->addWikiMsg( 'nohistory' );
98 # show deletion/move log if there is an entry
99 LogEventsList::showLogExtract(
100 $out,
101 array( 'delete', 'move' ),
102 $this->getTitle()->getPrefixedText(),
103 '',
104 array( 'lim' => 10,
105 'conds' => array( "log_action != 'revision'" ),
106 'showIfEmpty' => false,
107 'msgKey' => array( 'moveddeleted-notice' )
108 )
109 );
110 wfProfileOut( __METHOD__ );
111 return;
112 }
113
114 /**
115 * Add date selector to quickly get to a certain time
116 */
117 $year = $request->getInt( 'year' );
118 $month = $request->getInt( 'month' );
119 $tagFilter = $request->getVal( 'tagfilter' );
120 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
121
122 /**
123 * Option to show only revisions that have been (partially) hidden via RevisionDelete
124 */
125 if ( $request->getBool( 'deleted' ) ) {
126 $conds = array( "rev_deleted != '0'" );
127 } else {
128 $conds = array();
129 }
130 $checkDeleted = Xml::checkLabel( wfMsg( 'history-show-deleted' ),
131 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
132
133 // Add the general form
134 $action = htmlspecialchars( $wgScript );
135 $out->addHTML(
136 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
137 Xml::fieldset(
138 wfMsg( 'history-fieldset-title' ),
139 false,
140 array( 'id' => 'mw-history-search' )
141 ) .
142 Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" .
143 Html::hidden( 'action', 'history' ) . "\n" .
144 Xml::dateMenu( $year, $month ) . '&#160;' .
145 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
146 $checkDeleted .
147 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
148 '</fieldset></form>'
149 );
150
151 wfRunHooks( 'PageHistoryBeforeList', array( &$this->page ) );
152
153 // Create and output the list.
154 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
155 $out->addHTML(
156 $pager->getNavigationBar() .
157 $pager->getBody() .
158 $pager->getNavigationBar()
159 );
160 $out->preventClickjacking( $pager->getPreventClickjacking() );
161
162 wfProfileOut( __METHOD__ );
163 }
164
165 /**
166 * Fetch an array of revisions, specified by a given limit, offset and
167 * direction. This is now only used by the feeds. It was previously
168 * used by the main UI but that's now handled by the pager.
169 *
170 * @param $limit Integer: the limit number of revisions to get
171 * @param $offset Integer
172 * @param $direction Integer: either HistoryAction::DIR_PREV or HistoryAction::DIR_NEXT
173 * @return ResultWrapper
174 */
175 function fetchRevisions( $limit, $offset, $direction ) {
176 $dbr = wfGetDB( DB_SLAVE );
177
178 if ( $direction == self::DIR_PREV ) {
179 list( $dirs, $oper ) = array( "ASC", ">=" );
180 } else { /* $direction == self::DIR_NEXT */
181 list( $dirs, $oper ) = array( "DESC", "<=" );
182 }
183
184 if ( $offset ) {
185 $offsets = array( "rev_timestamp $oper '$offset'" );
186 } else {
187 $offsets = array();
188 }
189
190 $page_id = $this->getTitle()->getArticleID();
191
192 return $dbr->select( 'revision',
193 Revision::selectFields(),
194 array_merge( array( "rev_page=$page_id" ), $offsets ),
195 __METHOD__,
196 array( 'ORDER BY' => "rev_timestamp $dirs",
197 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit )
198 );
199 }
200
201 /**
202 * Output a subscription feed listing recent edits to this page.
203 *
204 * @param $type String: feed type
205 */
206 function feed( $type ) {
207 global $wgFeedClasses, $wgFeedLimit;
208 if ( !FeedUtils::checkFeedOutput( $type ) ) {
209 return;
210 }
211
212 $feed = new $wgFeedClasses[$type](
213 $this->getTitle()->getPrefixedText() . ' - ' .
214 wfMsgForContent( 'history-feed-title' ),
215 wfMsgForContent( 'history-feed-description' ),
216 $this->getTitle()->getFullUrl( 'action=history' )
217 );
218
219 // Get a limit on number of feed entries. Provide a sane default
220 // of 10 if none is defined (but limit to $wgFeedLimit max)
221 $limit = $this->getRequest()->getInt( 'limit', 10 );
222 if ( $limit > $wgFeedLimit || $limit < 1 ) {
223 $limit = 10;
224 }
225 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
226
227 // Generate feed elements enclosed between header and footer.
228 $feed->outHeader();
229 if ( $items->numRows() ) {
230 foreach ( $items as $row ) {
231 $feed->outItem( $this->feedItem( $row ) );
232 }
233 } else {
234 $feed->outItem( $this->feedEmpty() );
235 }
236 $feed->outFooter();
237 }
238
239 function feedEmpty() {
240 return new FeedItem(
241 wfMsgForContent( 'nohistory' ),
242 $this->getOutput()->parse( wfMsgForContent( 'history-feed-empty' ) ),
243 $this->getTitle()->getFullUrl(),
244 wfTimestamp( TS_MW ),
245 '',
246 $this->getTitle()->getTalkPage()->getFullUrl()
247 );
248 }
249
250 /**
251 * Generate a FeedItem object from a given revision table row
252 * Borrows Recent Changes' feed generation functions for formatting;
253 * includes a diff to the previous revision (if any).
254 *
255 * @param $row Object: database row
256 * @return FeedItem
257 */
258 function feedItem( $row ) {
259 $rev = new Revision( $row );
260 $titleObj = $this->getTitle();
261 $rev->setTitle( $titleObj );
262 $text = FeedUtils::formatDiffRow(
263 $titleObj,
264 $titleObj->getPreviousRevisionID( $rev->getId() ),
265 $rev->getId(),
266 $rev->getTimestamp(),
267 $rev->getComment()
268 );
269 if ( $rev->getComment() == '' ) {
270 global $wgContLang;
271 $title = wfMsgForContent( 'history-feed-item-nocomment',
272 $rev->getUserText(),
273 $wgContLang->timeanddate( $rev->getTimestamp() ),
274 $wgContLang->date( $rev->getTimestamp() ),
275 $wgContLang->time( $rev->getTimestamp() )
276 );
277 } else {
278 $title = $rev->getUserText() .
279 wfMsgForContent( 'colon-separator' ) .
280 FeedItem::stripComment( $rev->getComment() );
281 }
282 return new FeedItem(
283 $title,
284 $text,
285 $titleObj->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
286 $rev->getTimestamp(),
287 $rev->getUserText(),
288 $titleObj->getTalkPage()->getFullUrl()
289 );
290 }
291 }
292
293 /**
294 * @ingroup Pager
295 */
296 class HistoryPager extends ReverseChronologicalPager {
297 public $lastRow = false, $counter, $history, $buttons, $conds;
298 protected $oldIdChecked;
299 protected $preventClickjacking = false;
300
301 function __construct( $history, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
302 parent::__construct();
303 $this->history = $history;
304 $this->tagFilter = $tagFilter;
305 $this->getDateCond( $year, $month );
306 $this->conds = $conds;
307 }
308
309 // For hook compatibility...
310 function getArticle() {
311 return $this->history->getArticle();
312 }
313
314 function getSqlComment() {
315 if ( $this->conds ) {
316 return 'history page filtered'; // potentially slow, see CR r58153
317 } else {
318 return 'history page unfiltered';
319 }
320 }
321
322 function getQueryInfo() {
323 $queryInfo = array(
324 'tables' => array( 'revision' ),
325 'fields' => Revision::selectFields(),
326 'conds' => array_merge(
327 array( 'rev_page' => $this->getTitle()->getArticleID() ),
328 $this->conds ),
329 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
330 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
331 );
332 ChangeTags::modifyDisplayQuery(
333 $queryInfo['tables'],
334 $queryInfo['fields'],
335 $queryInfo['conds'],
336 $queryInfo['join_conds'],
337 $queryInfo['options'],
338 $this->tagFilter
339 );
340 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
341 return $queryInfo;
342 }
343
344 function getIndexField() {
345 return 'rev_timestamp';
346 }
347
348 function formatRow( $row ) {
349 if ( $this->lastRow ) {
350 $latest = ( $this->counter == 1 && $this->mIsFirst );
351 $firstInList = $this->counter == 1;
352 $this->counter++;
353 $s = $this->historyLine( $this->lastRow, $row,
354 $this->getTitle()->getNotificationTimestamp(), $latest, $firstInList );
355 } else {
356 $s = '';
357 }
358 $this->lastRow = $row;
359 return $s;
360 }
361
362 /**
363 * Creates begin of history list with a submit button
364 *
365 * @return string HTML output
366 */
367 function getStartBody() {
368 global $wgScript;
369 $this->lastRow = false;
370 $this->counter = 1;
371 $this->oldIdChecked = 0;
372
373 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
374 $s = Html::openElement( 'form', array( 'action' => $wgScript,
375 'id' => 'mw-history-compare' ) ) . "\n";
376 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . "\n";
377 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
378
379 $s .= '<div>' . $this->submitButton( wfMsg( 'compareselectedversions' ),
380 array( 'class' => 'historysubmit' ) ) . "\n";
381
382 $this->buttons = '<div>';
383 $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions' ),
384 array( 'class' => 'historysubmit' )
385 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
386 ) . "\n";
387
388 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
389 $s .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
390 }
391 $this->buttons .= '</div>';
392 $s .= '</div><ul id="pagehistory">' . "\n";
393 return $s;
394 }
395
396 private function getRevisionButton( $name, $msg ) {
397 $this->preventClickjacking();
398 # Note bug #20966, <button> is non-standard in IE<8
399 $element = Html::element( 'button',
400 array(
401 'type' => 'submit',
402 'name' => $name,
403 'value' => '1',
404 'class' => "mw-history-$name-button mw-float-end",
405 ),
406 wfMsg( $msg )
407 ) . "\n";
408 $this->buttons .= $element;
409 return $element;
410 }
411
412 function getEndBody() {
413 if ( $this->lastRow ) {
414 $latest = $this->counter == 1 && $this->mIsFirst;
415 $firstInList = $this->counter == 1;
416 if ( $this->mIsBackwards ) {
417 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
418 if ( $this->mOffset == '' ) {
419 $next = null;
420 } else {
421 $next = 'unknown';
422 }
423 } else {
424 # The next row is the past-the-end row
425 $next = $this->mPastTheEndRow;
426 }
427 $this->counter++;
428 $s = $this->historyLine( $this->lastRow, $next,
429 $this->getTitle()->getNotificationTimestamp(), $latest, $firstInList );
430 } else {
431 $s = '';
432 }
433 $s .= "</ul>\n";
434 # Add second buttons only if there is more than one rev
435 if ( $this->getNumRows() > 2 ) {
436 $s .= $this->buttons;
437 }
438 $s .= '</form>';
439 return $s;
440 }
441
442 /**
443 * Creates a submit button
444 *
445 * @param $message String: text of the submit button, will be escaped
446 * @param $attributes Array: attributes
447 * @return String: HTML output for the submit button
448 */
449 function submitButton( $message, $attributes = array() ) {
450 # Disable submit button if history has 1 revision only
451 if ( $this->getNumRows() > 1 ) {
452 return Xml::submitButton( $message , $attributes );
453 } else {
454 return '';
455 }
456 }
457
458 /**
459 * Returns a row from the history printout.
460 *
461 * @todo document some more, and maybe clean up the code (some params redundant?)
462 *
463 * @param $row Object: the database row corresponding to the previous line.
464 * @param $next Mixed: the database row corresponding to the next line.
465 * @param $notificationtimestamp
466 * @param $latest Boolean: whether this row corresponds to the page's latest revision.
467 * @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
468 * @return String: HTML output for the row
469 */
470 function historyLine( $row, $next, $notificationtimestamp = false,
471 $latest = false, $firstInList = false )
472 {
473 $rev = new Revision( $row );
474 $rev->setTitle( $this->getTitle() );
475
476 $curlink = $this->curLink( $rev, $latest );
477 $lastlink = $this->lastLink( $rev, $next );
478 $diffButtons = $this->diffButtons( $rev, $firstInList );
479 $histLinks = Html::rawElement(
480 'span',
481 array( 'class' => 'mw-history-histlinks' ),
482 '(' . $curlink . $this->history->message['pipe-separator'] . $lastlink . ') '
483 );
484 $s = $histLinks . $diffButtons;
485
486 $link = $this->revLink( $rev );
487 $classes = array();
488
489 $del = '';
490 // Show checkboxes for each revision
491 if ( $this->getUser()->isAllowed( 'deleterevision' ) ) {
492 $this->preventClickjacking();
493 // If revision was hidden from sysops, disable the checkbox
494 if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
495 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
496 // Otherwise, enable the checkbox...
497 } else {
498 $del = Xml::check( 'showhiderevisions', false,
499 array( 'name' => 'ids[' . $rev->getId() . ']' ) );
500 }
501 // User can only view deleted revisions...
502 } elseif ( $rev->getVisibility() && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
503 // If revision was hidden from sysops, disable the link
504 if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
505 $cdel = Linker::revDeleteLinkDisabled( false );
506 // Otherwise, show the link...
507 } else {
508 $query = array( 'type' => 'revision',
509 'target' => $this->getTitle()->getPrefixedDbkey(), 'ids' => $rev->getId() );
510 $del .= Linker::revDeleteLink( $query,
511 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
512 }
513 }
514 if ( $del ) {
515 $s .= " $del ";
516 }
517
518 $dirmark = $this->getLang()->getDirMark();
519
520 $s .= " $link";
521 $s .= $dirmark;
522 $s .= " <span class='history-user'>" .
523 Linker::revUserTools( $rev, true ) . "</span>";
524 $s .= $dirmark;
525
526 if ( $rev->isMinor() ) {
527 $s .= ' ' . ChangesList::flag( 'minor' );
528 }
529
530 if ( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
531 $s .= ' ' . Linker::formatRevisionSize( $size );
532 }
533
534 $s .= Linker::revComment( $rev, false, true );
535
536 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
537 $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
538 }
539
540 $tools = array();
541
542 # Rollback and undo links
543 if ( !is_null( $next ) && is_object( $next ) ) {
544 if ( $latest && $this->getTitle()->userCan( 'rollback' ) && $this->getTitle()->userCan( 'edit' ) ) {
545 $this->preventClickjacking();
546 $tools[] = '<span class="mw-rollback-link">' .
547 Linker::buildRollbackLink( $rev ) . '</span>';
548 }
549
550 if ( $this->getTitle()->quickUserCan( 'edit' )
551 && !$rev->isDeleted( Revision::DELETED_TEXT )
552 && !$next->rev_deleted & Revision::DELETED_TEXT )
553 {
554 # Create undo tooltip for the first (=latest) line only
555 $undoTooltip = $latest
556 ? array( 'title' => wfMsg( 'tooltip-undo' ) )
557 : array();
558 $undolink = Linker::linkKnown(
559 $this->getTitle(),
560 wfMsgHtml( 'editundo' ),
561 $undoTooltip,
562 array(
563 'action' => 'edit',
564 'undoafter' => $next->rev_id,
565 'undo' => $rev->getId()
566 )
567 );
568 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
569 }
570 }
571
572 if ( $tools ) {
573 $s .= ' (' . $this->getLang()->pipeList( $tools ) . ')';
574 }
575
576 # Tags
577 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
578 $classes = array_merge( $classes, $newClasses );
579 $s .= " $tagSummary";
580
581 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
582
583 $attribs = array();
584 if ( $classes ) {
585 $attribs['class'] = implode( ' ', $classes );
586 }
587
588 return Xml::tags( 'li', $attribs, $s ) . "\n";
589 }
590
591 /**
592 * Create a link to view this revision of the page
593 *
594 * @param $rev Revision
595 * @return String
596 */
597 function revLink( $rev ) {
598 $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true );
599 $date = htmlspecialchars( $date );
600 if ( $rev->userCan( Revision::DELETED_TEXT ) ) {
601 $link = Linker::linkKnown(
602 $this->getTitle(),
603 $date,
604 array(),
605 array( 'oldid' => $rev->getId() )
606 );
607 } else {
608 $link = $date;
609 }
610 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
611 $link = "<span class=\"history-deleted\">$link</span>";
612 }
613 return $link;
614 }
615
616 /**
617 * Create a diff-to-current link for this revision for this page
618 *
619 * @param $rev Revision
620 * @param $latest Boolean: this is the latest revision of the page?
621 * @return String
622 */
623 function curLink( $rev, $latest ) {
624 $cur = $this->history->message['cur'];
625 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
626 return $cur;
627 } else {
628 return Linker::linkKnown(
629 $this->getTitle(),
630 $cur,
631 array(),
632 array(
633 'diff' => $this->getTitle()->getLatestRevID(),
634 'oldid' => $rev->getId()
635 )
636 );
637 }
638 }
639
640 /**
641 * Create a diff-to-previous link for this revision for this page.
642 *
643 * @param $prevRev Revision: the previous revision
644 * @param $next Mixed: the newer revision
645 * @return String
646 */
647 function lastLink( $prevRev, $next ) {
648 $last = $this->history->message['last'];
649 # $next may either be a Row, null, or "unkown"
650 $nextRev = is_object( $next ) ? new Revision( $next ) : $next;
651 if ( is_null( $next ) ) {
652 # Probably no next row
653 return $last;
654 } elseif ( $next === 'unknown' ) {
655 # Next row probably exists but is unknown, use an oldid=prev link
656 return Linker::link(
657 $this->getTitle(),
658 $last,
659 array(),
660 array(
661 'diff' => $prevRev->getId(),
662 'oldid' => 'prev'
663 )
664 );
665 } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT )
666 || !$nextRev->userCan( Revision::DELETED_TEXT ) )
667 {
668 return $last;
669 } else {
670 return Linker::linkKnown(
671 $this->getTitle(),
672 $last,
673 array(),
674 array(
675 'diff' => $prevRev->getId(),
676 'oldid' => $next->rev_id
677 )
678 );
679 }
680 }
681
682 /**
683 * Create radio buttons for page history
684 *
685 * @param $rev Revision object
686 * @param $firstInList Boolean: is this version the first one?
687 *
688 * @return String: HTML output for the radio buttons
689 */
690 function diffButtons( $rev, $firstInList ) {
691 if ( $this->getNumRows() > 1 ) {
692 $id = $rev->getId();
693 $radio = array( 'type' => 'radio', 'value' => $id );
694 /** @todo: move title texts to javascript */
695 if ( $firstInList ) {
696 $first = Xml::element( 'input',
697 array_merge( $radio, array(
698 'style' => 'visibility:hidden',
699 'name' => 'oldid',
700 'id' => 'mw-oldid-null' ) )
701 );
702 $checkmark = array( 'checked' => 'checked' );
703 } else {
704 # Check visibility of old revisions
705 if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
706 $radio['disabled'] = 'disabled';
707 $checkmark = array(); // We will check the next possible one
708 } elseif ( !$this->oldIdChecked ) {
709 $checkmark = array( 'checked' => 'checked' );
710 $this->oldIdChecked = $id;
711 } else {
712 $checkmark = array();
713 }
714 $first = Xml::element( 'input',
715 array_merge( $radio, $checkmark, array(
716 'name' => 'oldid',
717 'id' => "mw-oldid-$id" ) ) );
718 $checkmark = array();
719 }
720 $second = Xml::element( 'input',
721 array_merge( $radio, $checkmark, array(
722 'name' => 'diff',
723 'id' => "mw-diff-$id" ) ) );
724 return $first . $second;
725 } else {
726 return '';
727 }
728 }
729
730 /**
731 * This is called if a write operation is possible from the generated HTML
732 */
733 function preventClickjacking( $enable = true ) {
734 $this->preventClickjacking = $enable;
735 }
736
737 /**
738 * Get the "prevent clickjacking" flag
739 */
740 function getPreventClickjacking() {
741 return $this->preventClickjacking;
742 }
743 }
744
745 /**
746 * Backwards-compatibility aliases
747 */
748 class HistoryPage extends HistoryAction {
749 public function __construct( Page $article ) { # Just to make it public
750 parent::__construct( $article );
751 }
752
753 public function history() {
754 $this->onView();
755 }
756 }