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