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