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
26 use MediaWiki\MediaWikiServices
;
27 use Wikimedia\Rdbms\ResultWrapper
;
28 use Wikimedia\Rdbms\FakeResultWrapper
;
31 * This class handles printing the history page for an article. In order to
32 * be efficient, it uses timestamps rather than offsets for paging, to avoid
33 * costly LIMIT,offset queries.
35 * Construct it by passing in an Article, and call $h->history() to print the
40 class HistoryAction
extends FormlessAction
{
44 /** @var array Array of message keys and strings */
47 public function getName() {
51 public function requiresWrite() {
55 public function requiresUnblock() {
59 protected function getPageTitle() {
60 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
63 protected function getDescription() {
64 // Creation of a subtitle link pointing to [[Special:Log]]
65 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
66 $subtitle = $linkRenderer->makeKnownLink(
67 SpecialPage
::getTitleFor( 'Log' ),
68 $this->msg( 'viewpagelogs' )->text(),
70 [ 'page' => $this->getTitle()->getPrefixedText() ]
74 // Allow extensions to add more links
75 Hooks
::run( 'HistoryPageToolLinks', [ $this->getContext(), $linkRenderer, &$links ] );
78 . $this->msg( 'word-separator' )->escaped()
79 . $this->msg( 'parentheses' )
80 ->rawParams( $this->getLanguage()->pipeList( $links ) )
87 * @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
89 public function getArticle() {
94 * As we use the same small set of messages in various methods and that
95 * they are called often, we call them once and save them in $this->message
97 private function preCacheMessages() {
98 // Precache various messages
99 if ( !isset( $this->message
) ) {
100 $msgs = [ 'cur', 'last', 'pipe-separator' ];
101 foreach ( $msgs as $msg ) {
102 $this->message
[$msg] = $this->msg( $msg )->escaped();
108 * Print the history page for an article.
111 $out = $this->getOutput();
112 $request = $this->getRequest();
115 * Allow client caching.
117 if ( $out->checkLastModified( $this->page
->getTouched() ) ) {
118 return; // Client cache fresh and headers sent, nothing more to do.
121 $this->preCacheMessages();
122 $config = $this->context
->getConfig();
124 # Fill in the file cache if not set already
125 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
126 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
127 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
128 ob_start( [ &$cache, 'saveToFileCache' ] );
132 // Setup page variables.
133 $out->setFeedAppendQuery( 'action=history' );
134 $out->addModules( 'mediawiki.action.history' );
135 $out->addModuleStyles( [
136 'mediawiki.action.history.styles',
137 'mediawiki.special.changeslist',
139 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
140 $out = $this->getOutput();
141 $out->addModuleStyles( [
142 'mediawiki.ui.input',
143 'mediawiki.ui.checkbox',
147 // Handle atom/RSS feeds.
148 $feedType = $request->getVal( 'feed' );
150 $this->feed( $feedType );
155 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
157 // Fail nicely if article doesn't exist.
158 if ( !$this->page
->exists() ) {
159 global $wgSend404Code;
160 if ( $wgSend404Code ) {
161 $out->setStatusCode( 404 );
163 $out->addWikiMsg( 'nohistory' );
165 $dbr = wfGetDB( DB_REPLICA
);
167 # show deletion/move log if there is an entry
168 LogEventsList
::showLogExtract(
170 [ 'delete', 'move', 'protect' ],
174 'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
175 'showIfEmpty' => false,
176 'msgKey' => [ 'moveddeleted-notice' ]
184 * Add date selector to quickly get to a certain time
186 $year = $request->getInt( 'year' );
187 $month = $request->getInt( 'month' );
188 $tagFilter = $request->getVal( 'tagfilter' );
189 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
192 * Option to show only revisions that have been (partially) hidden via RevisionDelete
194 if ( $request->getBool( 'deleted' ) ) {
195 $conds = [ 'rev_deleted != 0' ];
199 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
200 $checkDeleted = Xml
::checkLabel( $this->msg( 'history-show-deleted' )->text(),
201 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
206 // Add the general form
207 $action = htmlspecialchars( wfScript() );
208 $content = Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
209 $content .= Html
::hidden( 'action', 'history' ) . "\n";
210 $content .= Xml
::dateMenu(
211 ( $year == null ? MWTimestamp
::getLocalInstance()->format( 'Y' ) : $year ),
214 $content .= $tagSelector ?
( implode( "\u{00A0}", $tagSelector ) . "\u{00A0}" ) : '';
215 $content .= $checkDeleted . Html
::submitButton(
216 $this->msg( 'historyaction-submit' )->text(),
218 [ 'mw-ui-progressive' ]
221 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
223 $this->msg( 'history-fieldset-title' )->text(),
225 [ 'id' => 'mw-history-search' ]
230 Hooks
::run( 'PageHistoryBeforeList', [ &$this->page
, $this->getContext() ] );
232 // Create and output the list.
233 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
235 $pager->getNavigationBar() .
237 $pager->getNavigationBar()
239 $out->preventClickjacking( $pager->getPreventClickjacking() );
243 * Fetch an array of revisions, specified by a given limit, offset and
244 * direction. This is now only used by the feeds. It was previously
245 * used by the main UI but that's now handled by the pager.
247 * @param int $limit The limit number of revisions to get
249 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
250 * @return ResultWrapper
252 function fetchRevisions( $limit, $offset, $direction ) {
253 // Fail if article doesn't exist.
254 if ( !$this->getTitle()->exists() ) {
255 return new FakeResultWrapper( [] );
258 $dbr = wfGetDB( DB_REPLICA
);
260 if ( $direction === self
::DIR_PREV
) {
261 list( $dirs, $oper ) = [ "ASC", ">=" ];
262 } else { /* $direction === self::DIR_NEXT */
263 list( $dirs, $oper ) = [ "DESC", "<=" ];
267 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
272 $page_id = $this->page
->getId();
274 $revQuery = Revision
::getQueryInfo();
278 array_merge( [ 'rev_page' => $page_id ], $offsets ),
281 'ORDER BY' => "rev_timestamp $dirs",
282 'USE INDEX' => [ 'revision' => 'page_timestamp' ],
290 * Output a subscription feed listing recent edits to this page.
292 * @param string $type Feed type
294 function feed( $type ) {
295 if ( !FeedUtils
::checkFeedOutput( $type ) ) {
298 $request = $this->getRequest();
300 $feedClasses = $this->context
->getConfig()->get( 'FeedClasses' );
301 /** @var RSSFeed|AtomFeed $feed */
302 $feed = new $feedClasses[$type](
303 $this->getTitle()->getPrefixedText() . ' - ' .
304 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
305 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
306 $this->getTitle()->getFullURL( 'action=history' )
309 // Get a limit on number of feed entries. Provide a sane default
310 // of 10 if none is defined (but limit to $wgFeedLimit max)
311 $limit = $request->getInt( 'limit', 10 );
314 $this->context
->getConfig()->get( 'FeedLimit' )
317 $items = $this->fetchRevisions( $limit, 0, self
::DIR_NEXT
);
319 // Generate feed elements enclosed between header and footer.
321 if ( $items->numRows() ) {
322 foreach ( $items as $row ) {
323 $feed->outItem( $this->feedItem( $row ) );
326 $feed->outItem( $this->feedEmpty() );
331 function feedEmpty() {
333 $this->msg( 'nohistory' )->inContentLanguage()->text(),
334 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
335 $this->getTitle()->getFullURL(),
336 wfTimestamp( TS_MW
),
338 $this->getTitle()->getTalkPage()->getFullURL()
343 * Generate a FeedItem object from a given revision table row
344 * Borrows Recent Changes' feed generation functions for formatting;
345 * includes a diff to the previous revision (if any).
347 * @param stdClass|array $row Database row
350 function feedItem( $row ) {
351 $rev = new Revision( $row, 0, $this->getTitle() );
353 $text = FeedUtils
::formatDiffRow(
355 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
357 $rev->getTimestamp(),
360 if ( $rev->getComment() == '' ) {
361 $contLang = MediaWikiServices
::getInstance()->getContentLanguage();
362 $title = $this->msg( 'history-feed-item-nocomment',
364 $contLang->timeanddate( $rev->getTimestamp() ),
365 $contLang->date( $rev->getTimestamp() ),
366 $contLang->time( $rev->getTimestamp() )
367 )->inContentLanguage()->text();
369 $title = $rev->getUserText() .
370 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
371 FeedItem
::stripComment( $rev->getComment() );
377 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
378 $rev->getTimestamp(),
380 $this->getTitle()->getTalkPage()->getFullURL()
389 class HistoryPager
extends ReverseChronologicalPager
{
393 public $lastRow = false;
395 public $counter, $historyPage, $buttons, $conds;
397 protected $oldIdChecked;
399 protected $preventClickjacking = false;
403 protected $parentLens;
405 /** @var bool Whether to show the tag editing UI */
406 protected $showTagEditUI;
412 * @param HistoryAction $historyPage
413 * @param string $year
414 * @param string $month
415 * @param string $tagFilter
416 * @param array $conds
418 public function __construct(
419 HistoryAction
$historyPage,
425 parent
::__construct( $historyPage->getContext() );
426 $this->historyPage
= $historyPage;
427 $this->tagFilter
= $tagFilter;
428 $this->getDateCond( $year, $month );
429 $this->conds
= $conds;
430 $this->showTagEditUI
= ChangeTags
::showTagEditingUI( $this->getUser() );
433 // For hook compatibility...
434 function getArticle() {
435 return $this->historyPage
->getArticle();
438 function getSqlComment() {
439 if ( $this->conds
) {
440 return 'history page filtered'; // potentially slow, see CR r58153
442 return 'history page unfiltered';
446 function getQueryInfo() {
447 $revQuery = Revision
::getQueryInfo( [ 'user' ] );
449 'tables' => $revQuery['tables'],
450 'fields' => $revQuery['fields'],
451 'conds' => array_merge(
452 [ 'rev_page' => $this->getWikiPage()->getId() ],
454 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
455 'join_conds' => $revQuery['joins'],
457 ChangeTags
::modifyDisplayQuery(
458 $queryInfo['tables'],
459 $queryInfo['fields'],
461 $queryInfo['join_conds'],
462 $queryInfo['options'],
466 // Avoid PHP 7.1 warning of passing $this by reference
467 $historyPager = $this;
468 Hooks
::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
473 function getIndexField() {
474 return 'rev_timestamp';
478 * @param stdClass $row
481 function formatRow( $row ) {
482 if ( $this->lastRow
) {
483 $latest = ( $this->counter
== 1 && $this->mIsFirst
);
484 $firstInList = $this->counter
== 1;
487 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
488 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
491 $s = $this->historyLine(
492 $this->lastRow
, $row, $notifTimestamp, $latest, $firstInList );
496 $this->lastRow
= $row;
501 protected function doBatchLookups() {
502 if ( !Hooks
::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult
] ) ) {
506 # Do a link batch query
507 $this->mResult
->seek( 0 );
508 $batch = new LinkBatch();
510 foreach ( $this->mResult
as $row ) {
511 if ( $row->rev_parent_id
) {
512 $revIds[] = $row->rev_parent_id
;
514 if ( $row->user_name
!== null ) {
515 $batch->add( NS_USER
, $row->user_name
);
516 $batch->add( NS_USER_TALK
, $row->user_name
);
517 } else { # for anons or usernames of imported revisions
518 $batch->add( NS_USER
, $row->rev_user_text
);
519 $batch->add( NS_USER_TALK
, $row->rev_user_text
);
522 $this->parentLens
= Revision
::getParentLengths( $this->mDb
, $revIds );
524 $this->mResult
->seek( 0 );
528 * Creates begin of history list with a submit button
530 * @return string HTML output
532 protected function getStartBody() {
533 $this->lastRow
= false;
535 $this->oldIdChecked
= 0;
537 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
538 $s = Html
::openElement( 'form', [ 'action' => wfScript(),
539 'id' => 'mw-history-compare' ] ) . "\n";
540 $s .= Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
541 $s .= Html
::hidden( 'action', 'historysubmit' ) . "\n";
542 $s .= Html
::hidden( 'type', 'revision' ) . "\n";
544 // Button container stored in $this->buttons for re-use in getEndBody()
545 $this->buttons
= '<div>';
546 $className = 'historysubmit mw-history-compareselectedversions-button';
547 $attrs = [ 'class' => $className ]
548 + Linker
::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
549 $this->buttons
.= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
553 $user = $this->getUser();
555 if ( $user->isAllowed( 'deleterevision' ) ) {
556 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
558 if ( $this->showTagEditUI
) {
559 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
561 if ( $actionButtons ) {
562 $this->buttons
.= Xml
::tags( 'div', [ 'class' =>
563 'mw-history-revisionactions' ], $actionButtons );
566 if ( $user->isAllowed( 'deleterevision' ) ||
$this->showTagEditUI
) {
567 $this->buttons
.= ( new ListToggle( $this->getOutput() ) )->getHTML();
570 $this->buttons
.= '</div>';
572 $s .= $this->buttons
;
573 $s .= '<ul id="pagehistory">' . "\n";
578 private function getRevisionButton( $name, $msg ) {
579 $this->preventClickjacking();
580 # Note T22966, <button> is non-standard in IE<8
581 $element = Html
::element(
587 'class' => "historysubmit mw-history-$name-button",
589 $this->msg( $msg )->text()
594 protected function getEndBody() {
595 if ( $this->lastRow
) {
596 $latest = $this->counter
== 1 && $this->mIsFirst
;
597 $firstInList = $this->counter
== 1;
598 if ( $this->mIsBackwards
) {
599 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
600 if ( $this->mOffset
== '' ) {
606 # The next row is the past-the-end row
607 $next = $this->mPastTheEndRow
;
611 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
612 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
615 $s = $this->historyLine(
616 $this->lastRow
, $next, $notifTimestamp, $latest, $firstInList );
621 # Add second buttons only if there is more than one rev
622 if ( $this->getNumRows() > 2 ) {
623 $s .= $this->buttons
;
631 * Creates a submit button
633 * @param string $message Text of the submit button, will be escaped
634 * @param array $attributes
635 * @return string HTML output for the submit button
637 function submitButton( $message, $attributes = [] ) {
638 # Disable submit button if history has 1 revision only
639 if ( $this->getNumRows() > 1 ) {
640 return Html
::submitButton( $message, $attributes );
647 * Returns a row from the history printout.
649 * @todo document some more, and maybe clean up the code (some params redundant?)
651 * @param stdClass $row The database row corresponding to the previous line.
652 * @param mixed $next The database row corresponding to the next line
653 * (chronologically previous)
654 * @param bool|string $notificationtimestamp
655 * @param bool $latest Whether this row corresponds to the page's latest revision.
656 * @param bool $firstInList Whether this row corresponds to the first
657 * displayed on this history page.
658 * @return string HTML output for the row
660 function historyLine( $row, $next, $notificationtimestamp = false,
661 $latest = false, $firstInList = false ) {
662 $rev = new Revision( $row, 0, $this->getTitle() );
664 if ( is_object( $next ) ) {
665 $prevRev = new Revision( $next, 0, $this->getTitle() );
670 $curlink = $this->curLink( $rev, $latest );
671 $lastlink = $this->lastLink( $rev, $next );
672 $curLastlinks = $curlink . $this->historyPage
->message
['pipe-separator'] . $lastlink;
673 $histLinks = Html
::rawElement(
675 [ 'class' => 'mw-history-histlinks' ],
676 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
679 $diffButtons = $this->diffButtons( $rev, $firstInList );
680 $s = $histLinks . $diffButtons;
682 $link = $this->revLink( $rev );
686 $user = $this->getUser();
687 $canRevDelete = $user->isAllowed( 'deleterevision' );
688 // Show checkboxes for each revision, to allow for revision deletion and
690 if ( $canRevDelete ||
$this->showTagEditUI
) {
691 $this->preventClickjacking();
692 // If revision was hidden from sysops and we don't need the checkbox
693 // for anything else, disable it
694 if ( !$this->showTagEditUI
&& !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
695 $del = Xml
::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
696 // Otherwise, enable the checkbox...
698 $del = Xml
::check( 'showhiderevisions', false,
699 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
701 // User can only view deleted revisions...
702 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
703 // If revision was hidden from sysops, disable the link
704 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
705 $del = Linker
::revDeleteLinkDisabled( false );
706 // Otherwise, show the link...
708 $query = [ 'type' => 'revision',
709 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
710 $del .= Linker
::revDeleteLink( $query,
711 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), false );
718 $lang = $this->getLanguage();
719 $dirmark = $lang->getDirMark();
723 $s .= " <span class='history-user'>" .
724 Linker
::revUserTools( $rev, true ) . "</span>";
727 if ( $rev->isMinor() ) {
728 $s .= ' ' . ChangesList
::flag( 'minor', $this->getContext() );
731 # Sometimes rev_len isn't populated
732 if ( $rev->getSize() !== null ) {
733 # Size is always public data
734 $prevSize = $this->parentLens
[$row->rev_parent_id
] ??
0;
735 $sDiff = ChangesList
::showCharacterDifference( $prevSize, $rev->getSize() );
736 $fSize = Linker
::formatRevisionSize( $rev->getSize() );
737 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
740 # Text following the character difference is added just before running hooks
741 $s2 = Linker
::revComment( $rev, false, true );
743 if ( $notificationtimestamp && ( $row->rev_timestamp
>= $notificationtimestamp ) ) {
744 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
745 $classes[] = 'mw-history-line-updated';
750 # Rollback and undo links
751 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
752 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
753 // Get a rollback link without the brackets
754 $rollbackLink = Linker
::generateRollback(
757 [ 'verify', 'noBrackets' ]
759 if ( $rollbackLink ) {
760 $this->preventClickjacking();
761 $tools[] = $rollbackLink;
765 if ( !$rev->isDeleted( Revision
::DELETED_TEXT
)
766 && !$prevRev->isDeleted( Revision
::DELETED_TEXT
)
768 # Create undo tooltip for the first (=latest) line only
769 $undoTooltip = $latest
770 ?
[ 'title' => $this->msg( 'tooltip-undo' )->text() ]
772 $undolink = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
774 $this->msg( 'editundo' )->text(),
778 'undoafter' => $prevRev->getId(),
779 'undo' => $rev->getId()
782 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
785 // Allow extension to add their own links here
786 Hooks
::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
789 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
793 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
798 $classes = array_merge( $classes, $newClasses );
799 if ( $tagSummary !== '' ) {
800 $s2 .= " $tagSummary";
803 # Include separator between character difference and following text
805 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
808 $attribs = [ 'data-mw-revid' => $rev->getId() ];
810 Hooks
::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes, &$attribs ] );
811 $attribs = array_filter( $attribs,
812 [ Sanitizer
::class, 'isReservedDataAttribute' ],
817 $attribs['class'] = implode( ' ', $classes );
820 return Xml
::tags( 'li', $attribs, $s ) . "\n";
824 * Create a link to view this revision of the page
826 * @param Revision $rev
829 function revLink( $rev ) {
830 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
831 if ( $rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
832 $link = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
835 [ 'class' => 'mw-changeslist-date' ],
836 [ 'oldid' => $rev->getId() ]
839 $link = htmlspecialchars( $date );
841 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
842 $link = "<span class=\"history-deleted\">$link</span>";
849 * Create a diff-to-current link for this revision for this page
851 * @param Revision $rev
852 * @param bool $latest This is the latest revision of the page?
855 function curLink( $rev, $latest ) {
856 $cur = $this->historyPage
->message
['cur'];
857 if ( $latest ||
!$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
860 return MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
862 new HtmlArmor( $cur ),
865 'diff' => $this->getWikiPage()->getLatest(),
866 'oldid' => $rev->getId()
873 * Create a diff-to-previous link for this revision for this page.
875 * @param Revision $prevRev The revision being displayed
876 * @param stdClass|string|null $next The next revision in list (that is
877 * the previous one in chronological order).
878 * May either be a row, "unknown" or null.
881 function lastLink( $prevRev, $next ) {
882 $last = $this->historyPage
->message
['last'];
884 if ( $next === null ) {
885 # Probably no next row
889 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
890 if ( $next === 'unknown' ) {
891 # Next row probably exists but is unknown, use an oldid=prev link
892 return $linkRenderer->makeKnownLink(
894 new HtmlArmor( $last ),
897 'diff' => $prevRev->getId(),
903 $nextRev = new Revision( $next );
905 if ( !$prevRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
906 ||
!$nextRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
911 return $linkRenderer->makeKnownLink(
913 new HtmlArmor( $last ),
916 'diff' => $prevRev->getId(),
917 'oldid' => $next->rev_id
923 * Create radio buttons for page history
925 * @param Revision $rev
926 * @param bool $firstInList Is this version the first one?
928 * @return string HTML output for the radio buttons
930 function diffButtons( $rev, $firstInList ) {
931 if ( $this->getNumRows() > 1 ) {
933 $radio = [ 'type' => 'radio', 'value' => $id ];
934 /** @todo Move title texts to javascript */
935 if ( $firstInList ) {
936 $first = Xml
::element( 'input',
937 array_merge( $radio, [
938 'style' => 'visibility:hidden',
940 'id' => 'mw-oldid-null' ] )
942 $checkmark = [ 'checked' => 'checked' ];
944 # Check visibility of old revisions
945 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
946 $radio['disabled'] = 'disabled';
947 $checkmark = []; // We will check the next possible one
948 } elseif ( !$this->oldIdChecked
) {
949 $checkmark = [ 'checked' => 'checked' ];
950 $this->oldIdChecked
= $id;
954 $first = Xml
::element( 'input',
955 array_merge( $radio, $checkmark, [
957 'id' => "mw-oldid-$id" ] ) );
960 $second = Xml
::element( 'input',
961 array_merge( $radio, $checkmark, [
963 'id' => "mw-diff-$id" ] ) );
965 return $first . $second;
972 * This is called if a write operation is possible from the generated HTML
973 * @param bool $enable
975 function preventClickjacking( $enable = true ) {
976 $this->preventClickjacking
= $enable;
980 * Get the "prevent clickjacking" flag
983 function getPreventClickjacking() {
984 return $this->preventClickjacking
;