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
;
29 * This class handles printing the history page for an article. In order to
30 * be efficient, it uses timestamps rather than offsets for paging, to avoid
31 * costly LIMIT,offset queries.
33 * Construct it by passing in an Article, and call $h->history() to print the
38 class HistoryAction
extends FormlessAction
{
42 /** @var array Array of message keys and strings */
45 public function getName() {
49 public function requiresWrite() {
53 public function requiresUnblock() {
57 protected function getPageTitle() {
58 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
61 protected function getDescription() {
62 // Creation of a subtitle link pointing to [[Special:Log]]
63 return MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
64 SpecialPage
::getTitleFor( 'Log' ),
65 $this->msg( 'viewpagelogs' )->text(),
67 [ 'page' => $this->getTitle()->getPrefixedText() ]
72 * @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
74 public function getArticle() {
79 * As we use the same small set of messages in various methods and that
80 * they are called often, we call them once and save them in $this->message
82 private function preCacheMessages() {
83 // Precache various messages
84 if ( !isset( $this->message
) ) {
85 $msgs = [ 'cur', 'last', 'pipe-separator' ];
86 foreach ( $msgs as $msg ) {
87 $this->message
[$msg] = $this->msg( $msg )->escaped();
93 * Print the history page for an article.
96 $out = $this->getOutput();
97 $request = $this->getRequest();
100 * Allow client caching.
102 if ( $out->checkLastModified( $this->page
->getTouched() ) ) {
103 return; // Client cache fresh and headers sent, nothing more to do.
106 $this->preCacheMessages();
107 $config = $this->context
->getConfig();
109 # Fill in the file cache if not set already
110 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
111 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
112 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
113 ob_start( [ &$cache, 'saveToFileCache' ] );
117 // Setup page variables.
118 $out->setFeedAppendQuery( 'action=history' );
119 $out->addModules( 'mediawiki.action.history' );
120 $out->addModuleStyles( [
121 'mediawiki.action.history.styles',
122 'mediawiki.special.changeslist',
124 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
125 $out = $this->getOutput();
126 $out->addModuleStyles( [
127 'mediawiki.ui.input',
128 'mediawiki.ui.checkbox',
132 // Handle atom/RSS feeds.
133 $feedType = $request->getVal( 'feed' );
135 $this->feed( $feedType );
140 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
142 // Fail nicely if article doesn't exist.
143 if ( !$this->page
->exists() ) {
144 global $wgSend404Code;
145 if ( $wgSend404Code ) {
146 $out->setStatusCode( 404 );
148 $out->addWikiMsg( 'nohistory' );
149 # show deletion/move log if there is an entry
150 LogEventsList
::showLogExtract(
152 [ 'delete', 'move' ],
156 'conds' => [ "log_action != 'revision'" ],
157 'showIfEmpty' => false,
158 'msgKey' => [ 'moveddeleted-notice' ]
166 * Add date selector to quickly get to a certain time
168 $year = $request->getInt( 'year' );
169 $month = $request->getInt( 'month' );
170 $tagFilter = $request->getVal( 'tagfilter' );
171 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
174 * Option to show only revisions that have been (partially) hidden via RevisionDelete
176 if ( $request->getBool( 'deleted' ) ) {
177 $conds = [ 'rev_deleted != 0' ];
181 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
182 $checkDeleted = Xml
::checkLabel( $this->msg( 'history-show-deleted' )->text(),
183 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
188 // Add the general form
189 $action = htmlspecialchars( wfScript() );
191 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
193 $this->msg( 'history-fieldset-title' )->text(),
195 [ 'id' => 'mw-history-search' ]
197 Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
198 Html
::hidden( 'action', 'history' ) . "\n" .
200 ( $year == null ? MWTimestamp
::getLocalInstance()->format( 'Y' ) : $year ),
203 ( $tagSelector ?
( implode( ' ', $tagSelector ) . ' ' ) : '' ) .
206 $this->msg( 'historyaction-submit' )->text(),
208 [ 'mw-ui-progressive' ]
213 Hooks
::run( 'PageHistoryBeforeList', [ &$this->page
, $this->getContext() ] );
215 // Create and output the list.
216 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
218 $pager->getNavigationBar() .
220 $pager->getNavigationBar()
222 $out->preventClickjacking( $pager->getPreventClickjacking() );
226 * Fetch an array of revisions, specified by a given limit, offset and
227 * direction. This is now only used by the feeds. It was previously
228 * used by the main UI but that's now handled by the pager.
230 * @param int $limit The limit number of revisions to get
232 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
233 * @return ResultWrapper
235 function fetchRevisions( $limit, $offset, $direction ) {
236 // Fail if article doesn't exist.
237 if ( !$this->getTitle()->exists() ) {
238 return new FakeResultWrapper( [] );
241 $dbr = wfGetDB( DB_REPLICA
);
243 if ( $direction === self
::DIR_PREV
) {
244 list( $dirs, $oper ) = [ "ASC", ">=" ];
245 } else { /* $direction === self::DIR_NEXT */
246 list( $dirs, $oper ) = [ "DESC", "<=" ];
250 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
255 $page_id = $this->page
->getId();
257 return $dbr->select( 'revision',
258 Revision
::selectFields(),
259 array_merge( [ 'rev_page' => $page_id ], $offsets ),
261 [ 'ORDER BY' => "rev_timestamp $dirs",
262 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
267 * Output a subscription feed listing recent edits to this page.
269 * @param string $type Feed type
271 function feed( $type ) {
272 if ( !FeedUtils
::checkFeedOutput( $type ) ) {
275 $request = $this->getRequest();
277 $feedClasses = $this->context
->getConfig()->get( 'FeedClasses' );
278 /** @var RSSFeed|AtomFeed $feed */
279 $feed = new $feedClasses[$type](
280 $this->getTitle()->getPrefixedText() . ' - ' .
281 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
282 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
283 $this->getTitle()->getFullURL( 'action=history' )
286 // Get a limit on number of feed entries. Provide a sane default
287 // of 10 if none is defined (but limit to $wgFeedLimit max)
288 $limit = $request->getInt( 'limit', 10 );
291 $this->context
->getConfig()->get( 'FeedLimit' )
294 $items = $this->fetchRevisions( $limit, 0, self
::DIR_NEXT
);
296 // Generate feed elements enclosed between header and footer.
298 if ( $items->numRows() ) {
299 foreach ( $items as $row ) {
300 $feed->outItem( $this->feedItem( $row ) );
303 $feed->outItem( $this->feedEmpty() );
308 function feedEmpty() {
310 $this->msg( 'nohistory' )->inContentLanguage()->text(),
311 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
312 $this->getTitle()->getFullURL(),
313 wfTimestamp( TS_MW
),
315 $this->getTitle()->getTalkPage()->getFullURL()
320 * Generate a FeedItem object from a given revision table row
321 * Borrows Recent Changes' feed generation functions for formatting;
322 * includes a diff to the previous revision (if any).
324 * @param stdClass|array $row Database row
327 function feedItem( $row ) {
328 $rev = new Revision( $row );
329 $rev->setTitle( $this->getTitle() );
330 $text = FeedUtils
::formatDiffRow(
332 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
334 $rev->getTimestamp(),
337 if ( $rev->getComment() == '' ) {
339 $title = $this->msg( 'history-feed-item-nocomment',
341 $wgContLang->timeanddate( $rev->getTimestamp() ),
342 $wgContLang->date( $rev->getTimestamp() ),
343 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
345 $title = $rev->getUserText() .
346 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
347 FeedItem
::stripComment( $rev->getComment() );
353 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
354 $rev->getTimestamp(),
356 $this->getTitle()->getTalkPage()->getFullURL()
365 class HistoryPager
extends ReverseChronologicalPager
{
369 public $lastRow = false;
371 public $counter, $historyPage, $buttons, $conds;
373 protected $oldIdChecked;
375 protected $preventClickjacking = false;
379 protected $parentLens;
381 /** @var bool Whether to show the tag editing UI */
382 protected $showTagEditUI;
385 * @param HistoryAction $historyPage
386 * @param string $year
387 * @param string $month
388 * @param string $tagFilter
389 * @param array $conds
391 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
392 parent
::__construct( $historyPage->getContext() );
393 $this->historyPage
= $historyPage;
394 $this->tagFilter
= $tagFilter;
395 $this->getDateCond( $year, $month );
396 $this->conds
= $conds;
397 $this->showTagEditUI
= ChangeTags
::showTagEditingUI( $this->getUser() );
400 // For hook compatibility...
401 function getArticle() {
402 return $this->historyPage
->getArticle();
405 function getSqlComment() {
406 if ( $this->conds
) {
407 return 'history page filtered'; // potentially slow, see CR r58153
409 return 'history page unfiltered';
413 function getQueryInfo() {
415 'tables' => [ 'revision', 'user' ],
416 'fields' => array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
417 'conds' => array_merge(
418 [ 'rev_page' => $this->getWikiPage()->getId() ],
420 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
421 'join_conds' => [ 'user' => Revision
::userJoinCond() ],
423 ChangeTags
::modifyDisplayQuery(
424 $queryInfo['tables'],
425 $queryInfo['fields'],
427 $queryInfo['join_conds'],
428 $queryInfo['options'],
431 Hooks
::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
436 function getIndexField() {
437 return 'rev_timestamp';
441 * @param stdClass $row
444 function formatRow( $row ) {
445 if ( $this->lastRow
) {
446 $latest = ( $this->counter
== 1 && $this->mIsFirst
);
447 $firstInList = $this->counter
== 1;
450 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
451 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
454 $s = $this->historyLine(
455 $this->lastRow
, $row, $notifTimestamp, $latest, $firstInList );
459 $this->lastRow
= $row;
464 function doBatchLookups() {
465 if ( !Hooks
::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult
] ) ) {
469 # Do a link batch query
470 $this->mResult
->seek( 0 );
471 $batch = new LinkBatch();
473 foreach ( $this->mResult
as $row ) {
474 if ( $row->rev_parent_id
) {
475 $revIds[] = $row->rev_parent_id
;
477 if ( !is_null( $row->user_name
) ) {
478 $batch->add( NS_USER
, $row->user_name
);
479 $batch->add( NS_USER_TALK
, $row->user_name
);
480 } else { # for anons or usernames of imported revisions
481 $batch->add( NS_USER
, $row->rev_user_text
);
482 $batch->add( NS_USER_TALK
, $row->rev_user_text
);
485 $this->parentLens
= Revision
::getParentLengths( $this->mDb
, $revIds );
487 $this->mResult
->seek( 0 );
491 * Creates begin of history list with a submit button
493 * @return string HTML output
495 function getStartBody() {
496 $this->lastRow
= false;
498 $this->oldIdChecked
= 0;
500 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
501 $s = Html
::openElement( 'form', [ 'action' => wfScript(),
502 'id' => 'mw-history-compare' ] ) . "\n";
503 $s .= Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
504 $s .= Html
::hidden( 'action', 'historysubmit' ) . "\n";
505 $s .= Html
::hidden( 'type', 'revision' ) . "\n";
507 // Button container stored in $this->buttons for re-use in getEndBody()
508 $this->buttons
= '<div>';
509 $className = 'historysubmit mw-history-compareselectedversions-button';
510 $attrs = [ 'class' => $className ]
511 + Linker
::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
512 $this->buttons
.= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
516 $user = $this->getUser();
518 if ( $user->isAllowed( 'deleterevision' ) ) {
519 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
521 if ( $this->showTagEditUI
) {
522 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
524 if ( $actionButtons ) {
525 $this->buttons
.= Xml
::tags( 'div', [ 'class' =>
526 'mw-history-revisionactions' ], $actionButtons );
529 if ( $user->isAllowed( 'deleterevision' ) ||
$this->showTagEditUI
) {
530 $this->buttons
.= ( new ListToggle( $this->getOutput() ) )->getHTML();
533 $this->buttons
.= '</div>';
535 $s .= $this->buttons
;
536 $s .= '<ul id="pagehistory">' . "\n";
541 private function getRevisionButton( $name, $msg ) {
542 $this->preventClickjacking();
543 # Note bug #20966, <button> is non-standard in IE<8
544 $element = Html
::element(
550 'class' => "historysubmit mw-history-$name-button",
552 $this->msg( $msg )->text()
557 function getEndBody() {
558 if ( $this->lastRow
) {
559 $latest = $this->counter
== 1 && $this->mIsFirst
;
560 $firstInList = $this->counter
== 1;
561 if ( $this->mIsBackwards
) {
562 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
563 if ( $this->mOffset
== '' ) {
569 # The next row is the past-the-end row
570 $next = $this->mPastTheEndRow
;
574 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
575 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
578 $s = $this->historyLine(
579 $this->lastRow
, $next, $notifTimestamp, $latest, $firstInList );
584 # Add second buttons only if there is more than one rev
585 if ( $this->getNumRows() > 2 ) {
586 $s .= $this->buttons
;
594 * Creates a submit button
596 * @param string $message Text of the submit button, will be escaped
597 * @param array $attributes Attributes
598 * @return string HTML output for the submit button
600 function submitButton( $message, $attributes = [] ) {
601 # Disable submit button if history has 1 revision only
602 if ( $this->getNumRows() > 1 ) {
603 return Html
::submitButton( $message, $attributes );
610 * Returns a row from the history printout.
612 * @todo document some more, and maybe clean up the code (some params redundant?)
614 * @param stdClass $row The database row corresponding to the previous line.
615 * @param mixed $next The database row corresponding to the next line
616 * (chronologically previous)
617 * @param bool|string $notificationtimestamp
618 * @param bool $latest Whether this row corresponds to the page's latest revision.
619 * @param bool $firstInList Whether this row corresponds to the first
620 * displayed on this history page.
621 * @return string HTML output for the row
623 function historyLine( $row, $next, $notificationtimestamp = false,
624 $latest = false, $firstInList = false ) {
625 $rev = new Revision( $row );
626 $rev->setTitle( $this->getTitle() );
628 if ( is_object( $next ) ) {
629 $prevRev = new Revision( $next );
630 $prevRev->setTitle( $this->getTitle() );
635 $curlink = $this->curLink( $rev, $latest );
636 $lastlink = $this->lastLink( $rev, $next );
637 $curLastlinks = $curlink . $this->historyPage
->message
['pipe-separator'] . $lastlink;
638 $histLinks = Html
::rawElement(
640 [ 'class' => 'mw-history-histlinks' ],
641 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
644 $diffButtons = $this->diffButtons( $rev, $firstInList );
645 $s = $histLinks . $diffButtons;
647 $link = $this->revLink( $rev );
651 $user = $this->getUser();
652 $canRevDelete = $user->isAllowed( 'deleterevision' );
653 // Show checkboxes for each revision, to allow for revision deletion and
655 if ( $canRevDelete ||
$this->showTagEditUI
) {
656 $this->preventClickjacking();
657 // If revision was hidden from sysops and we don't need the checkbox
658 // for anything else, disable it
659 if ( !$this->showTagEditUI
&& !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
660 $del = Xml
::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
661 // Otherwise, enable the checkbox...
663 $del = Xml
::check( 'showhiderevisions', false,
664 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
666 // User can only view deleted revisions...
667 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
668 // If revision was hidden from sysops, disable the link
669 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
670 $del = Linker
::revDeleteLinkDisabled( false );
671 // Otherwise, show the link...
673 $query = [ 'type' => 'revision',
674 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
675 $del .= Linker
::revDeleteLink( $query,
676 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), false );
683 $lang = $this->getLanguage();
684 $dirmark = $lang->getDirMark();
688 $s .= " <span class='history-user'>" .
689 Linker
::revUserTools( $rev, true ) . "</span>";
692 if ( $rev->isMinor() ) {
693 $s .= ' ' . ChangesList
::flag( 'minor', $this->getContext() );
696 # Sometimes rev_len isn't populated
697 if ( $rev->getSize() !== null ) {
698 # Size is always public data
699 $prevSize = isset( $this->parentLens
[$row->rev_parent_id
] )
700 ?
$this->parentLens
[$row->rev_parent_id
]
702 $sDiff = ChangesList
::showCharacterDifference( $prevSize, $rev->getSize() );
703 $fSize = Linker
::formatRevisionSize( $rev->getSize() );
704 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
707 # Text following the character difference is added just before running hooks
708 $s2 = Linker
::revComment( $rev, false, true );
710 if ( $notificationtimestamp && ( $row->rev_timestamp
>= $notificationtimestamp ) ) {
711 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
712 $classes[] = 'mw-history-line-updated';
717 # Rollback and undo links
718 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
719 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
720 // Get a rollback link without the brackets
721 $rollbackLink = Linker
::generateRollback(
724 [ 'verify', 'noBrackets' ]
726 if ( $rollbackLink ) {
727 $this->preventClickjacking();
728 $tools[] = $rollbackLink;
732 if ( !$rev->isDeleted( Revision
::DELETED_TEXT
)
733 && !$prevRev->isDeleted( Revision
::DELETED_TEXT
)
735 # Create undo tooltip for the first (=latest) line only
736 $undoTooltip = $latest
737 ?
[ 'title' => $this->msg( 'tooltip-undo' )->text() ]
739 $undolink = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
741 $this->msg( 'editundo' )->text(),
745 'undoafter' => $prevRev->getId(),
746 'undo' => $rev->getId()
749 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
752 // Allow extension to add their own links here
753 Hooks
::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
756 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
760 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
765 $classes = array_merge( $classes, $newClasses );
766 if ( $tagSummary !== '' ) {
767 $s2 .= " $tagSummary";
770 # Include separator between character difference and following text
772 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
775 Hooks
::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
779 $attribs['class'] = implode( ' ', $classes );
782 return Xml
::tags( 'li', $attribs, $s ) . "\n";
786 * Create a link to view this revision of the page
788 * @param Revision $rev
791 function revLink( $rev ) {
792 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
793 if ( $rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
794 $link = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
797 [ 'class' => 'mw-changeslist-date' ],
798 [ 'oldid' => $rev->getId() ]
801 $link = htmlspecialchars( $date );
803 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
804 $link = "<span class=\"history-deleted\">$link</span>";
811 * Create a diff-to-current link for this revision for this page
813 * @param Revision $rev
814 * @param bool $latest This is the latest revision of the page?
817 function curLink( $rev, $latest ) {
818 $cur = $this->historyPage
->message
['cur'];
819 if ( $latest ||
!$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
822 return MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
827 'diff' => $this->getWikiPage()->getLatest(),
828 'oldid' => $rev->getId()
835 * Create a diff-to-previous link for this revision for this page.
837 * @param Revision $prevRev The revision being displayed
838 * @param stdClass|string|null $next The next revision in list (that is
839 * the previous one in chronological order).
840 * May either be a row, "unknown" or null.
843 function lastLink( $prevRev, $next ) {
844 $last = $this->historyPage
->message
['last'];
846 if ( $next === null ) {
847 # Probably no next row
851 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
852 if ( $next === 'unknown' ) {
853 # Next row probably exists but is unknown, use an oldid=prev link
854 return $linkRenderer->makeKnownLink(
859 'diff' => $prevRev->getId(),
865 $nextRev = new Revision( $next );
867 if ( !$prevRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
868 ||
!$nextRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
873 return $linkRenderer->makeKnownLink(
878 'diff' => $prevRev->getId(),
879 'oldid' => $next->rev_id
885 * Create radio buttons for page history
887 * @param Revision $rev
888 * @param bool $firstInList Is this version the first one?
890 * @return string HTML output for the radio buttons
892 function diffButtons( $rev, $firstInList ) {
893 if ( $this->getNumRows() > 1 ) {
895 $radio = [ 'type' => 'radio', 'value' => $id ];
896 /** @todo Move title texts to javascript */
897 if ( $firstInList ) {
898 $first = Xml
::element( 'input',
899 array_merge( $radio, [
900 'style' => 'visibility:hidden',
902 'id' => 'mw-oldid-null' ] )
904 $checkmark = [ 'checked' => 'checked' ];
906 # Check visibility of old revisions
907 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
908 $radio['disabled'] = 'disabled';
909 $checkmark = []; // We will check the next possible one
910 } elseif ( !$this->oldIdChecked
) {
911 $checkmark = [ 'checked' => 'checked' ];
912 $this->oldIdChecked
= $id;
916 $first = Xml
::element( 'input',
917 array_merge( $radio, $checkmark, [
919 'id' => "mw-oldid-$id" ] ) );
922 $second = Xml
::element( 'input',
923 array_merge( $radio, $checkmark, [
925 'id' => "mw-diff-$id" ] ) );
927 return $first . $second;
934 * This is called if a write operation is possible from the generated HTML
935 * @param bool $enable
937 function preventClickjacking( $enable = true ) {
938 $this->preventClickjacking
= $enable;
942 * Get the "prevent clickjacking" flag
945 function getPreventClickjacking() {
946 return $this->preventClickjacking
;