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