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