Warn user if mod_security is present
[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 getTitle() {
330 return $this->title;
331 }
332
333 function getSqlComment() {
334 if ( $this->conds ) {
335 return 'history page filtered'; // potentially slow, see CR r58153
336 } else {
337 return 'history page unfiltered';
338 }
339 }
340
341 function getQueryInfo() {
342 $queryInfo = array(
343 'tables' => array( 'revision' ),
344 'fields' => Revision::selectFields(),
345 'conds' => array_merge(
346 array( 'rev_page' => $this->title->getArticleID() ),
347 $this->conds ),
348 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
349 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
350 );
351 ChangeTags::modifyDisplayQuery(
352 $queryInfo['tables'],
353 $queryInfo['fields'],
354 $queryInfo['conds'],
355 $queryInfo['join_conds'],
356 $queryInfo['options'],
357 $this->tagFilter
358 );
359 wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) );
360 return $queryInfo;
361 }
362
363 function getIndexField() {
364 return 'rev_timestamp';
365 }
366
367 function formatRow( $row ) {
368 if ( $this->lastRow ) {
369 $latest = ( $this->counter == 1 && $this->mIsFirst );
370 $firstInList = $this->counter == 1;
371 $this->counter++;
372 $s = $this->historyLine( $this->lastRow, $row,
373 $this->title->getNotificationTimestamp(), $latest, $firstInList );
374 } else {
375 $s = '';
376 }
377 $this->lastRow = $row;
378 return $s;
379 }
380
381 /**
382 * Creates begin of history list with a submit button
383 *
384 * @return string HTML output
385 */
386 function getStartBody() {
387 global $wgScript, $wgUser, $wgOut;
388 $this->lastRow = false;
389 $this->counter = 1;
390 $this->oldIdChecked = 0;
391
392 $wgOut->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
393 $s = Html::openElement( 'form', array( 'action' => $wgScript,
394 'id' => 'mw-history-compare' ) ) . "\n";
395 $s .= Html::hidden( 'title', $this->title->getPrefixedDbKey() ) . "\n";
396 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
397
398 $s .= '<div>' . $this->submitButton( wfMsg( 'compareselectedversions' ),
399 array( 'class' => 'historysubmit' ) ) . "\n";
400
401 $this->buttons = '<div>';
402 $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions' ),
403 array( 'class' => 'historysubmit' )
404 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' )
405 ) . "\n";
406
407 if ( $wgUser->isAllowed( 'deleterevision' ) ) {
408 $s .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
409 }
410 $this->buttons .= '</div>';
411 $s .= '</div><ul id="pagehistory">' . "\n";
412 return $s;
413 }
414
415 private function getRevisionButton( $name, $msg ) {
416 $this->preventClickjacking();
417 # Note bug #20966, <button> is non-standard in IE<8
418 $element = Html::element( 'button',
419 array(
420 'type' => 'submit',
421 'name' => $name,
422 'value' => '1',
423 'class' => "mw-history-$name-button mw-float-end",
424 ),
425 wfMsg( $msg )
426 ) . "\n";
427 $this->buttons .= $element;
428 return $element;
429 }
430
431 function getEndBody() {
432 if ( $this->lastRow ) {
433 $latest = $this->counter == 1 && $this->mIsFirst;
434 $firstInList = $this->counter == 1;
435 if ( $this->mIsBackwards ) {
436 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
437 if ( $this->mOffset == '' ) {
438 $next = null;
439 } else {
440 $next = 'unknown';
441 }
442 } else {
443 # The next row is the past-the-end row
444 $next = $this->mPastTheEndRow;
445 }
446 $this->counter++;
447 $s = $this->historyLine( $this->lastRow, $next,
448 $this->title->getNotificationTimestamp(), $latest, $firstInList );
449 } else {
450 $s = '';
451 }
452 $s .= "</ul>\n";
453 # Add second buttons only if there is more than one rev
454 if ( $this->getNumRows() > 2 ) {
455 $s .= $this->buttons;
456 }
457 $s .= '</form>';
458 return $s;
459 }
460
461 /**
462 * Creates a submit button
463 *
464 * @param $message String: text of the submit button, will be escaped
465 * @param $attributes Array: attributes
466 * @return String: HTML output for the submit button
467 */
468 function submitButton( $message, $attributes = array() ) {
469 # Disable submit button if history has 1 revision only
470 if ( $this->getNumRows() > 1 ) {
471 return Xml::submitButton( $message , $attributes );
472 } else {
473 return '';
474 }
475 }
476
477 /**
478 * Returns a row from the history printout.
479 *
480 * @todo document some more, and maybe clean up the code (some params redundant?)
481 *
482 * @param $row Object: the database row corresponding to the previous line.
483 * @param $next Mixed: the database row corresponding to the next line.
484 * @param $notificationtimestamp
485 * @param $latest Boolean: whether this row corresponds to the page's latest revision.
486 * @param $firstInList Boolean: whether this row corresponds to the first displayed on this history page.
487 * @return String: HTML output for the row
488 */
489 function historyLine( $row, $next, $notificationtimestamp = false,
490 $latest = false, $firstInList = false )
491 {
492 global $wgUser, $wgLang;
493 $rev = new Revision( $row );
494 $rev->setTitle( $this->title );
495
496 $curlink = $this->curLink( $rev, $latest );
497 $lastlink = $this->lastLink( $rev, $next );
498 $diffButtons = $this->diffButtons( $rev, $firstInList );
499 $histLinks = Html::rawElement(
500 'span',
501 array( 'class' => 'mw-history-histlinks' ),
502 '(' . $curlink . $this->historyPage->message['pipe-separator'] . $lastlink . ') '
503 );
504 $s = $histLinks . $diffButtons;
505
506 $link = $this->revLink( $rev );
507 $classes = array();
508
509 $del = '';
510 // Show checkboxes for each revision
511 if ( $wgUser->isAllowed( 'deleterevision' ) ) {
512 $this->preventClickjacking();
513 // If revision was hidden from sysops, disable the checkbox
514 if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
515 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
516 // Otherwise, enable the checkbox...
517 } else {
518 $del = Xml::check( 'showhiderevisions', false,
519 array( 'name' => 'ids[' . $rev->getId() . ']' ) );
520 }
521 // User can only view deleted revisions...
522 } elseif ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) {
523 // If revision was hidden from sysops, disable the link
524 if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
525 $cdel = $this->getSkin()->revDeleteLinkDisabled( false );
526 // Otherwise, show the link...
527 } else {
528 $query = array( 'type' => 'revision',
529 'target' => $this->title->getPrefixedDbkey(), 'ids' => $rev->getId() );
530 $del .= $this->getSkin()->revDeleteLink( $query,
531 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
532 }
533 }
534 if ( $del ) {
535 $s .= " $del ";
536 }
537
538 $dirmark = $wgLang->getDirMark();
539
540 $s .= " $link";
541 $s .= $dirmark;
542 $s .= " <span class='history-user'>" .
543 $this->getSkin()->revUserTools( $rev, true ) . "</span>";
544 $s .= $dirmark;
545
546 if ( $rev->isMinor() ) {
547 $s .= ' ' . ChangesList::flag( 'minor' );
548 }
549
550 if ( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
551 $s .= ' ' . $this->getSkin()->formatRevisionSize( $size );
552 }
553
554 $s .= $this->getSkin()->revComment( $rev, false, true );
555
556 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
557 $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
558 }
559
560 $tools = array();
561
562 # Rollback and undo links
563 if ( !is_null( $next ) && is_object( $next ) ) {
564 if ( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) {
565 $this->preventClickjacking();
566 $tools[] = '<span class="mw-rollback-link">' .
567 $this->getSkin()->buildRollbackLink( $rev ) . '</span>';
568 }
569
570 if ( $this->title->quickUserCan( 'edit' )
571 && !$rev->isDeleted( Revision::DELETED_TEXT )
572 && !$next->rev_deleted & Revision::DELETED_TEXT )
573 {
574 # Create undo tooltip for the first (=latest) line only
575 $undoTooltip = $latest
576 ? array( 'title' => wfMsg( 'tooltip-undo' ) )
577 : array();
578 $undolink = $this->getSkin()->link(
579 $this->title,
580 wfMsgHtml( 'editundo' ),
581 $undoTooltip,
582 array(
583 'action' => 'edit',
584 'undoafter' => $next->rev_id,
585 'undo' => $rev->getId()
586 ),
587 array( 'known', 'noclasses' )
588 );
589 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
590 }
591 }
592
593 if ( $tools ) {
594 $s .= ' (' . $wgLang->pipeList( $tools ) . ')';
595 }
596
597 # Tags
598 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' );
599 $classes = array_merge( $classes, $newClasses );
600 $s .= " $tagSummary";
601
602 wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s, &$classes ) );
603
604 $attribs = array();
605 if ( $classes ) {
606 $attribs['class'] = implode( ' ', $classes );
607 }
608
609 return Xml::tags( 'li', $attribs, $s ) . "\n";
610 }
611
612 /**
613 * Create a link to view this revision of the page
614 *
615 * @param $rev Revision
616 * @return String
617 */
618 function revLink( $rev ) {
619 global $wgLang;
620 $date = $wgLang->timeanddate( wfTimestamp( TS_MW, $rev->getTimestamp() ), true );
621 $date = htmlspecialchars( $date );
622 if ( $rev->userCan( Revision::DELETED_TEXT ) ) {
623 $link = $this->getSkin()->link(
624 $this->title,
625 $date,
626 array(),
627 array( 'oldid' => $rev->getId() ),
628 array( 'known', 'noclasses' )
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 $this->getSkin()->link(
652 $this->title,
653 $cur,
654 array(),
655 array(
656 'diff' => $this->title->getLatestRevID(),
657 'oldid' => $rev->getId()
658 ),
659 array( 'known', 'noclasses' )
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 $this->getSkin()->link(
681 $this->title,
682 $last,
683 array(),
684 array(
685 'diff' => $prevRev->getId(),
686 'oldid' => 'prev'
687 ),
688 array( 'known', 'noclasses' )
689 );
690 } elseif ( !$prevRev->userCan( Revision::DELETED_TEXT )
691 || !$nextRev->userCan( Revision::DELETED_TEXT ) )
692 {
693 return $last;
694 } else {
695 return $this->getSkin()->link(
696 $this->title,
697 $last,
698 array(),
699 array(
700 'diff' => $prevRev->getId(),
701 'oldid' => $next->rev_id
702 ),
703 array( 'known', 'noclasses' )
704 );
705 }
706 }
707
708 /**
709 * Create radio buttons for page history
710 *
711 * @param $rev Revision object
712 * @param $firstInList Boolean: is this version the first one?
713 *
714 * @return String: HTML output for the radio buttons
715 */
716 function diffButtons( $rev, $firstInList ) {
717 if ( $this->getNumRows() > 1 ) {
718 $id = $rev->getId();
719 $radio = array( 'type' => 'radio', 'value' => $id );
720 /** @todo: move title texts to javascript */
721 if ( $firstInList ) {
722 $first = Xml::element( 'input',
723 array_merge( $radio, array(
724 'style' => 'visibility:hidden',
725 'name' => 'oldid',
726 'id' => 'mw-oldid-null' ) )
727 );
728 $checkmark = array( 'checked' => 'checked' );
729 } else {
730 # Check visibility of old revisions
731 if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
732 $radio['disabled'] = 'disabled';
733 $checkmark = array(); // We will check the next possible one
734 } elseif ( !$this->oldIdChecked ) {
735 $checkmark = array( 'checked' => 'checked' );
736 $this->oldIdChecked = $id;
737 } else {
738 $checkmark = array();
739 }
740 $first = Xml::element( 'input',
741 array_merge( $radio, $checkmark, array(
742 'name' => 'oldid',
743 'id' => "mw-oldid-$id" ) ) );
744 $checkmark = array();
745 }
746 $second = Xml::element( 'input',
747 array_merge( $radio, $checkmark, array(
748 'name' => 'diff',
749 'id' => "mw-diff-$id" ) ) );
750 return $first . $second;
751 } else {
752 return '';
753 }
754 }
755
756 /**
757 * This is called if a write operation is possible from the generated HTML
758 */
759 function preventClickjacking( $enable = true ) {
760 $this->preventClickjacking = $enable;
761 }
762
763 /**
764 * Get the "prevent clickjacking" flag
765 */
766 function getPreventClickjacking() {
767 return $this->preventClickjacking;
768 }
769 }
770
771 /**
772 * Backwards-compatibility aliases
773 */
774 class PageHistory extends HistoryPage {}
775 class PageHistoryPager extends HistoryPager {}