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