Remove wf* function usage from FSFileBackend
[mediawiki.git] / includes / actions / HistoryAction.php
blobf3ef3b3cb6aba979579dd23e8af1631d354dd739
1 <?php
2 /**
3 * Page history
5 * Split off from Article.php and Skin.php, 2003-12-22
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @ingroup Actions
26 /**
27 * This class handles printing the history page for an article. In order to
28 * be efficient, it uses timestamps rather than offsets for paging, to avoid
29 * costly LIMIT,offset queries.
31 * Construct it by passing in an Article, and call $h->history() to print the
32 * history.
34 * @ingroup Actions
36 class HistoryAction extends FormlessAction {
37 const DIR_PREV = 0;
38 const DIR_NEXT = 1;
40 /** @var array Array of message keys and strings */
41 public $message;
43 public function getName() {
44 return 'history';
47 public function requiresWrite() {
48 return false;
51 public function requiresUnblock() {
52 return false;
55 protected function getPageTitle() {
56 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
59 protected function getDescription() {
60 // Creation of a subtitle link pointing to [[Special:Log]]
61 return Linker::linkKnown(
62 SpecialPage::getTitleFor( 'Log' ),
63 $this->msg( 'viewpagelogs' )->escaped(),
64 [],
65 [ 'page' => $this->getTitle()->getPrefixedText() ]
69 /**
70 * @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
72 public function getArticle() {
73 return $this->page;
76 /**
77 * As we use the same small set of messages in various methods and that
78 * they are called often, we call them once and save them in $this->message
80 private function preCacheMessages() {
81 // Precache various messages
82 if ( !isset( $this->message ) ) {
83 $msgs = [ 'cur', 'last', 'pipe-separator' ];
84 foreach ( $msgs as $msg ) {
85 $this->message[$msg] = $this->msg( $msg )->escaped();
90 /**
91 * Print the history page for an article.
93 function onView() {
94 $out = $this->getOutput();
95 $request = $this->getRequest();
97 /**
98 * Allow client caching.
100 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
101 return; // Client cache fresh and headers sent, nothing more to do.
104 $this->preCacheMessages();
105 $config = $this->context->getConfig();
107 # Fill in the file cache if not set already
108 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
109 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
110 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
111 ob_start( [ &$cache, 'saveToFileCache' ] );
115 // Setup page variables.
116 $out->setFeedAppendQuery( 'action=history' );
117 $out->addModules( 'mediawiki.action.history' );
118 $out->addModuleStyles( [
119 'mediawiki.action.history.styles',
120 'mediawiki.special.changeslist',
121 ] );
122 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
123 $out = $this->getOutput();
124 $out->addModuleStyles( [
125 'mediawiki.ui.input',
126 'mediawiki.ui.checkbox',
127 ] );
130 // Handle atom/RSS feeds.
131 $feedType = $request->getVal( 'feed' );
132 if ( $feedType ) {
133 $this->feed( $feedType );
135 return;
138 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
140 // Fail nicely if article doesn't exist.
141 if ( !$this->page->exists() ) {
142 $out->addWikiMsg( 'nohistory' );
143 # show deletion/move log if there is an entry
144 LogEventsList::showLogExtract(
145 $out,
146 [ 'delete', 'move' ],
147 $this->getTitle(),
149 [ 'lim' => 10,
150 'conds' => [ "log_action != 'revision'" ],
151 'showIfEmpty' => false,
152 'msgKey' => [ 'moveddeleted-notice' ]
156 return;
160 * Add date selector to quickly get to a certain time
162 $year = $request->getInt( 'year' );
163 $month = $request->getInt( 'month' );
164 $tagFilter = $request->getVal( 'tagfilter' );
165 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
168 * Option to show only revisions that have been (partially) hidden via RevisionDelete
170 if ( $request->getBool( 'deleted' ) ) {
171 $conds = [ 'rev_deleted != 0' ];
172 } else {
173 $conds = [];
175 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
176 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
177 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
178 } else {
179 $checkDeleted = '';
182 // Add the general form
183 $action = htmlspecialchars( wfScript() );
184 $out->addHTML(
185 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
186 Xml::fieldset(
187 $this->msg( 'history-fieldset-title' )->text(),
188 false,
189 [ 'id' => 'mw-history-search' ]
191 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
192 Html::hidden( 'action', 'history' ) . "\n" .
193 Xml::dateMenu(
194 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
195 $month
196 ) . '&#160;' .
197 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
198 $checkDeleted .
199 Html::submitButton(
200 $this->msg( 'historyaction-submit' )->text(),
202 [ 'mw-ui-progressive' ]
203 ) . "\n" .
204 '</fieldset></form>'
207 Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
209 // Create and output the list.
210 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
211 $out->addHTML(
212 $pager->getNavigationBar() .
213 $pager->getBody() .
214 $pager->getNavigationBar()
216 $out->preventClickjacking( $pager->getPreventClickjacking() );
221 * Fetch an array of revisions, specified by a given limit, offset and
222 * direction. This is now only used by the feeds. It was previously
223 * used by the main UI but that's now handled by the pager.
225 * @param int $limit The limit number of revisions to get
226 * @param int $offset
227 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
228 * @return ResultWrapper
230 function fetchRevisions( $limit, $offset, $direction ) {
231 // Fail if article doesn't exist.
232 if ( !$this->getTitle()->exists() ) {
233 return new FakeResultWrapper( [] );
236 $dbr = wfGetDB( DB_REPLICA );
238 if ( $direction === self::DIR_PREV ) {
239 list( $dirs, $oper ) = [ "ASC", ">=" ];
240 } else { /* $direction === self::DIR_NEXT */
241 list( $dirs, $oper ) = [ "DESC", "<=" ];
244 if ( $offset ) {
245 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
246 } else {
247 $offsets = [];
250 $page_id = $this->page->getId();
252 return $dbr->select( 'revision',
253 Revision::selectFields(),
254 array_merge( [ 'rev_page' => $page_id ], $offsets ),
255 __METHOD__,
256 [ 'ORDER BY' => "rev_timestamp $dirs",
257 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
262 * Output a subscription feed listing recent edits to this page.
264 * @param string $type Feed type
266 function feed( $type ) {
267 if ( !FeedUtils::checkFeedOutput( $type ) ) {
268 return;
270 $request = $this->getRequest();
272 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
273 /** @var RSSFeed|AtomFeed $feed */
274 $feed = new $feedClasses[$type](
275 $this->getTitle()->getPrefixedText() . ' - ' .
276 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
277 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
278 $this->getTitle()->getFullURL( 'action=history' )
281 // Get a limit on number of feed entries. Provide a sane default
282 // of 10 if none is defined (but limit to $wgFeedLimit max)
283 $limit = $request->getInt( 'limit', 10 );
284 $limit = min(
285 max( $limit, 1 ),
286 $this->context->getConfig()->get( 'FeedLimit' )
289 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
291 // Generate feed elements enclosed between header and footer.
292 $feed->outHeader();
293 if ( $items->numRows() ) {
294 foreach ( $items as $row ) {
295 $feed->outItem( $this->feedItem( $row ) );
297 } else {
298 $feed->outItem( $this->feedEmpty() );
300 $feed->outFooter();
303 function feedEmpty() {
304 return new FeedItem(
305 $this->msg( 'nohistory' )->inContentLanguage()->text(),
306 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
307 $this->getTitle()->getFullURL(),
308 wfTimestamp( TS_MW ),
310 $this->getTitle()->getTalkPage()->getFullURL()
315 * Generate a FeedItem object from a given revision table row
316 * Borrows Recent Changes' feed generation functions for formatting;
317 * includes a diff to the previous revision (if any).
319 * @param stdClass|array $row Database row
320 * @return FeedItem
322 function feedItem( $row ) {
323 $rev = new Revision( $row );
324 $rev->setTitle( $this->getTitle() );
325 $text = FeedUtils::formatDiffRow(
326 $this->getTitle(),
327 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
328 $rev->getId(),
329 $rev->getTimestamp(),
330 $rev->getComment()
332 if ( $rev->getComment() == '' ) {
333 global $wgContLang;
334 $title = $this->msg( 'history-feed-item-nocomment',
335 $rev->getUserText(),
336 $wgContLang->timeanddate( $rev->getTimestamp() ),
337 $wgContLang->date( $rev->getTimestamp() ),
338 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
339 } else {
340 $title = $rev->getUserText() .
341 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
342 FeedItem::stripComment( $rev->getComment() );
345 return new FeedItem(
346 $title,
347 $text,
348 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
349 $rev->getTimestamp(),
350 $rev->getUserText(),
351 $this->getTitle()->getTalkPage()->getFullURL()
357 * @ingroup Pager
358 * @ingroup Actions
360 class HistoryPager extends ReverseChronologicalPager {
362 * @var bool|stdClass
364 public $lastRow = false;
366 public $counter, $historyPage, $buttons, $conds;
368 protected $oldIdChecked;
370 protected $preventClickjacking = false;
372 * @var array
374 protected $parentLens;
376 /** @var bool Whether to show the tag editing UI */
377 protected $showTagEditUI;
380 * @param HistoryAction $historyPage
381 * @param string $year
382 * @param string $month
383 * @param string $tagFilter
384 * @param array $conds
386 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
387 parent::__construct( $historyPage->getContext() );
388 $this->historyPage = $historyPage;
389 $this->tagFilter = $tagFilter;
390 $this->getDateCond( $year, $month );
391 $this->conds = $conds;
392 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
395 // For hook compatibility...
396 function getArticle() {
397 return $this->historyPage->getArticle();
400 function getSqlComment() {
401 if ( $this->conds ) {
402 return 'history page filtered'; // potentially slow, see CR r58153
403 } else {
404 return 'history page unfiltered';
408 function getQueryInfo() {
409 $queryInfo = [
410 'tables' => [ 'revision', 'user' ],
411 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
412 'conds' => array_merge(
413 [ 'rev_page' => $this->getWikiPage()->getId() ],
414 $this->conds ),
415 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
416 'join_conds' => [ 'user' => Revision::userJoinCond() ],
418 ChangeTags::modifyDisplayQuery(
419 $queryInfo['tables'],
420 $queryInfo['fields'],
421 $queryInfo['conds'],
422 $queryInfo['join_conds'],
423 $queryInfo['options'],
424 $this->tagFilter
426 Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
428 return $queryInfo;
431 function getIndexField() {
432 return 'rev_timestamp';
436 * @param stdClass $row
437 * @return string
439 function formatRow( $row ) {
440 if ( $this->lastRow ) {
441 $latest = ( $this->counter == 1 && $this->mIsFirst );
442 $firstInList = $this->counter == 1;
443 $this->counter++;
445 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
446 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
447 : false;
449 $s = $this->historyLine(
450 $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
451 } else {
452 $s = '';
454 $this->lastRow = $row;
456 return $s;
459 function doBatchLookups() {
460 if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
461 return;
464 # Do a link batch query
465 $this->mResult->seek( 0 );
466 $batch = new LinkBatch();
467 $revIds = [];
468 foreach ( $this->mResult as $row ) {
469 if ( $row->rev_parent_id ) {
470 $revIds[] = $row->rev_parent_id;
472 if ( !is_null( $row->user_name ) ) {
473 $batch->add( NS_USER, $row->user_name );
474 $batch->add( NS_USER_TALK, $row->user_name );
475 } else { # for anons or usernames of imported revisions
476 $batch->add( NS_USER, $row->rev_user_text );
477 $batch->add( NS_USER_TALK, $row->rev_user_text );
480 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
481 $batch->execute();
482 $this->mResult->seek( 0 );
486 * Creates begin of history list with a submit button
488 * @return string HTML output
490 function getStartBody() {
491 $this->lastRow = false;
492 $this->counter = 1;
493 $this->oldIdChecked = 0;
495 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
496 $s = Html::openElement( 'form', [ 'action' => wfScript(),
497 'id' => 'mw-history-compare' ] ) . "\n";
498 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
499 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
500 $s .= Html::hidden( 'type', 'revision' ) . "\n";
502 // Button container stored in $this->buttons for re-use in getEndBody()
503 $this->buttons = '<div>';
504 $className = 'historysubmit mw-history-compareselectedversions-button';
505 $attrs = [ 'class' => $className ]
506 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
507 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
508 $attrs
509 ) . "\n";
511 $user = $this->getUser();
512 $actionButtons = '';
513 if ( $user->isAllowed( 'deleterevision' ) ) {
514 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
516 if ( $this->showTagEditUI ) {
517 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
519 if ( $actionButtons ) {
520 $this->buttons .= Xml::tags( 'div', [ 'class' =>
521 'mw-history-revisionactions' ], $actionButtons );
524 if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
525 $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
528 $this->buttons .= '</div>';
530 $s .= $this->buttons;
531 $s .= '<ul id="pagehistory">' . "\n";
533 return $s;
536 private function getRevisionButton( $name, $msg ) {
537 $this->preventClickjacking();
538 # Note bug #20966, <button> is non-standard in IE<8
539 $element = Html::element(
540 'button',
542 'type' => 'submit',
543 'name' => $name,
544 'value' => '1',
545 'class' => "historysubmit mw-history-$name-button",
547 $this->msg( $msg )->text()
548 ) . "\n";
549 return $element;
552 function getEndBody() {
553 if ( $this->lastRow ) {
554 $latest = $this->counter == 1 && $this->mIsFirst;
555 $firstInList = $this->counter == 1;
556 if ( $this->mIsBackwards ) {
557 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
558 if ( $this->mOffset == '' ) {
559 $next = null;
560 } else {
561 $next = 'unknown';
563 } else {
564 # The next row is the past-the-end row
565 $next = $this->mPastTheEndRow;
567 $this->counter++;
569 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
570 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
571 : false;
573 $s = $this->historyLine(
574 $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
575 } else {
576 $s = '';
578 $s .= "</ul>\n";
579 # Add second buttons only if there is more than one rev
580 if ( $this->getNumRows() > 2 ) {
581 $s .= $this->buttons;
583 $s .= '</form>';
585 return $s;
589 * Creates a submit button
591 * @param string $message Text of the submit button, will be escaped
592 * @param array $attributes Attributes
593 * @return string HTML output for the submit button
595 function submitButton( $message, $attributes = [] ) {
596 # Disable submit button if history has 1 revision only
597 if ( $this->getNumRows() > 1 ) {
598 return Html::submitButton( $message, $attributes );
599 } else {
600 return '';
605 * Returns a row from the history printout.
607 * @todo document some more, and maybe clean up the code (some params redundant?)
609 * @param stdClass $row The database row corresponding to the previous line.
610 * @param mixed $next The database row corresponding to the next line
611 * (chronologically previous)
612 * @param bool|string $notificationtimestamp
613 * @param bool $latest Whether this row corresponds to the page's latest revision.
614 * @param bool $firstInList Whether this row corresponds to the first
615 * displayed on this history page.
616 * @return string HTML output for the row
618 function historyLine( $row, $next, $notificationtimestamp = false,
619 $latest = false, $firstInList = false ) {
620 $rev = new Revision( $row );
621 $rev->setTitle( $this->getTitle() );
623 if ( is_object( $next ) ) {
624 $prevRev = new Revision( $next );
625 $prevRev->setTitle( $this->getTitle() );
626 } else {
627 $prevRev = null;
630 $curlink = $this->curLink( $rev, $latest );
631 $lastlink = $this->lastLink( $rev, $next );
632 $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
633 $histLinks = Html::rawElement(
634 'span',
635 [ 'class' => 'mw-history-histlinks' ],
636 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
639 $diffButtons = $this->diffButtons( $rev, $firstInList );
640 $s = $histLinks . $diffButtons;
642 $link = $this->revLink( $rev );
643 $classes = [];
645 $del = '';
646 $user = $this->getUser();
647 $canRevDelete = $user->isAllowed( 'deleterevision' );
648 // Show checkboxes for each revision, to allow for revision deletion and
649 // change tags
650 if ( $canRevDelete || $this->showTagEditUI ) {
651 $this->preventClickjacking();
652 // If revision was hidden from sysops and we don't need the checkbox
653 // for anything else, disable it
654 if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
655 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
656 // Otherwise, enable the checkbox...
657 } else {
658 $del = Xml::check( 'showhiderevisions', false,
659 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
661 // User can only view deleted revisions...
662 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
663 // If revision was hidden from sysops, disable the link
664 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
665 $del = Linker::revDeleteLinkDisabled( false );
666 // Otherwise, show the link...
667 } else {
668 $query = [ 'type' => 'revision',
669 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
670 $del .= Linker::revDeleteLink( $query,
671 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
674 if ( $del ) {
675 $s .= " $del ";
678 $lang = $this->getLanguage();
679 $dirmark = $lang->getDirMark();
681 $s .= " $link";
682 $s .= $dirmark;
683 $s .= " <span class='history-user'>" .
684 Linker::revUserTools( $rev, true ) . "</span>";
685 $s .= $dirmark;
687 if ( $rev->isMinor() ) {
688 $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
691 # Sometimes rev_len isn't populated
692 if ( $rev->getSize() !== null ) {
693 # Size is always public data
694 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
695 ? $this->parentLens[$row->rev_parent_id]
696 : 0;
697 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
698 $fSize = Linker::formatRevisionSize( $rev->getSize() );
699 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
702 # Text following the character difference is added just before running hooks
703 $s2 = Linker::revComment( $rev, false, true );
705 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
706 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
707 $classes[] = 'mw-history-line-updated';
710 $tools = [];
712 # Rollback and undo links
713 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
714 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
715 // Get a rollback link without the brackets
716 $rollbackLink = Linker::generateRollback(
717 $rev,
718 $this->getContext(),
719 [ 'verify', 'noBrackets' ]
721 if ( $rollbackLink ) {
722 $this->preventClickjacking();
723 $tools[] = $rollbackLink;
727 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
728 && !$prevRev->isDeleted( Revision::DELETED_TEXT )
730 # Create undo tooltip for the first (=latest) line only
731 $undoTooltip = $latest
732 ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
733 : [];
734 $undolink = Linker::linkKnown(
735 $this->getTitle(),
736 $this->msg( 'editundo' )->escaped(),
737 $undoTooltip,
739 'action' => 'edit',
740 'undoafter' => $prevRev->getId(),
741 'undo' => $rev->getId()
744 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
747 // Allow extension to add their own links here
748 Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
750 if ( $tools ) {
751 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
754 # Tags
755 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
756 $row->ts_tags,
757 'history',
758 $this->getContext()
760 $classes = array_merge( $classes, $newClasses );
761 if ( $tagSummary !== '' ) {
762 $s2 .= " $tagSummary";
765 # Include separator between character difference and following text
766 if ( $s2 !== '' ) {
767 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
770 Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
772 $attribs = [];
773 if ( $classes ) {
774 $attribs['class'] = implode( ' ', $classes );
777 return Xml::tags( 'li', $attribs, $s ) . "\n";
781 * Create a link to view this revision of the page
783 * @param Revision $rev
784 * @return string
786 function revLink( $rev ) {
787 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
788 $date = htmlspecialchars( $date );
789 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
790 $link = Linker::linkKnown(
791 $this->getTitle(),
792 $date,
793 [ 'class' => 'mw-changeslist-date' ],
794 [ 'oldid' => $rev->getId() ]
796 } else {
797 $link = $date;
799 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
800 $link = "<span class=\"history-deleted\">$link</span>";
803 return $link;
807 * Create a diff-to-current link for this revision for this page
809 * @param Revision $rev
810 * @param bool $latest This is the latest revision of the page?
811 * @return string
813 function curLink( $rev, $latest ) {
814 $cur = $this->historyPage->message['cur'];
815 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
816 return $cur;
817 } else {
818 return Linker::linkKnown(
819 $this->getTitle(),
820 $cur,
823 'diff' => $this->getWikiPage()->getLatest(),
824 'oldid' => $rev->getId()
831 * Create a diff-to-previous link for this revision for this page.
833 * @param Revision $prevRev The revision being displayed
834 * @param stdClass|string|null $next The next revision in list (that is
835 * the previous one in chronological order).
836 * May either be a row, "unknown" or null.
837 * @return string
839 function lastLink( $prevRev, $next ) {
840 $last = $this->historyPage->message['last'];
842 if ( $next === null ) {
843 # Probably no next row
844 return $last;
847 if ( $next === 'unknown' ) {
848 # Next row probably exists but is unknown, use an oldid=prev link
849 return Linker::linkKnown(
850 $this->getTitle(),
851 $last,
854 'diff' => $prevRev->getId(),
855 'oldid' => 'prev'
860 $nextRev = new Revision( $next );
862 if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
863 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
865 return $last;
868 return Linker::linkKnown(
869 $this->getTitle(),
870 $last,
873 'diff' => $prevRev->getId(),
874 'oldid' => $next->rev_id
880 * Create radio buttons for page history
882 * @param Revision $rev
883 * @param bool $firstInList Is this version the first one?
885 * @return string HTML output for the radio buttons
887 function diffButtons( $rev, $firstInList ) {
888 if ( $this->getNumRows() > 1 ) {
889 $id = $rev->getId();
890 $radio = [ 'type' => 'radio', 'value' => $id ];
891 /** @todo Move title texts to javascript */
892 if ( $firstInList ) {
893 $first = Xml::element( 'input',
894 array_merge( $radio, [
895 'style' => 'visibility:hidden',
896 'name' => 'oldid',
897 'id' => 'mw-oldid-null' ] )
899 $checkmark = [ 'checked' => 'checked' ];
900 } else {
901 # Check visibility of old revisions
902 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
903 $radio['disabled'] = 'disabled';
904 $checkmark = []; // We will check the next possible one
905 } elseif ( !$this->oldIdChecked ) {
906 $checkmark = [ 'checked' => 'checked' ];
907 $this->oldIdChecked = $id;
908 } else {
909 $checkmark = [];
911 $first = Xml::element( 'input',
912 array_merge( $radio, $checkmark, [
913 'name' => 'oldid',
914 'id' => "mw-oldid-$id" ] ) );
915 $checkmark = [];
917 $second = Xml::element( 'input',
918 array_merge( $radio, $checkmark, [
919 'name' => 'diff',
920 'id' => "mw-diff-$id" ] ) );
922 return $first . $second;
923 } else {
924 return '';
929 * This is called if a write operation is possible from the generated HTML
930 * @param bool $enable
932 function preventClickjacking( $enable = true ) {
933 $this->preventClickjacking = $enable;
937 * Get the "prevent clickjacking" flag
938 * @return bool
940 function getPreventClickjacking() {
941 return $this->preventClickjacking;