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