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