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