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