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