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