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
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
36 class HistoryAction
extends FormlessAction
{
40 /** @var array Array of message keys and strings */
43 public function getName() {
47 public function requiresWrite() {
51 public function requiresUnblock() {
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(),
65 [ 'page' => $this->getTitle()->getPrefixedText() ]
70 * @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
72 public function getArticle() {
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();
91 * Print the history page for an article.
94 $out = $this->getOutput();
95 $request = $this->getRequest();
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',
122 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
123 $out = $this->getOutput();
124 $out->addModuleStyles( [
125 'mediawiki.ui.input',
126 'mediawiki.ui.checkbox',
130 // Handle atom/RSS feeds.
131 $feedType = $request->getVal( 'feed' );
133 $this->feed( $feedType );
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 global $wgSend404Code;
143 if ( $wgSend404Code ) {
144 $out->setStatusCode( 404 );
146 $out->addWikiMsg( 'nohistory' );
147 # show deletion/move log if there is an entry
148 LogEventsList
::showLogExtract(
150 [ 'delete', 'move' ],
154 'conds' => [ "log_action != 'revision'" ],
155 'showIfEmpty' => false,
156 'msgKey' => [ 'moveddeleted-notice' ]
164 * Add date selector to quickly get to a certain time
166 $year = $request->getInt( 'year' );
167 $month = $request->getInt( 'month' );
168 $tagFilter = $request->getVal( 'tagfilter' );
169 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter );
172 * Option to show only revisions that have been (partially) hidden via RevisionDelete
174 if ( $request->getBool( 'deleted' ) ) {
175 $conds = [ 'rev_deleted != 0' ];
179 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
180 $checkDeleted = Xml
::checkLabel( $this->msg( 'history-show-deleted' )->text(),
181 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
186 // Add the general form
187 $action = htmlspecialchars( wfScript() );
189 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
191 $this->msg( 'history-fieldset-title' )->text(),
193 [ 'id' => 'mw-history-search' ]
195 Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
196 Html
::hidden( 'action', 'history' ) . "\n" .
198 ( $year == null ? MWTimestamp
::getLocalInstance()->format( 'Y' ) : $year ),
201 ( $tagSelector ?
( implode( ' ', $tagSelector ) . ' ' ) : '' ) .
204 $this->msg( 'historyaction-submit' )->text(),
206 [ 'mw-ui-progressive' ]
211 Hooks
::run( 'PageHistoryBeforeList', [ &$this->page
, $this->getContext() ] );
213 // Create and output the list.
214 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
216 $pager->getNavigationBar() .
218 $pager->getNavigationBar()
220 $out->preventClickjacking( $pager->getPreventClickjacking() );
225 * Fetch an array of revisions, specified by a given limit, offset and
226 * direction. This is now only used by the feeds. It was previously
227 * used by the main UI but that's now handled by the pager.
229 * @param int $limit The limit number of revisions to get
231 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
232 * @return ResultWrapper
234 function fetchRevisions( $limit, $offset, $direction ) {
235 // Fail if article doesn't exist.
236 if ( !$this->getTitle()->exists() ) {
237 return new FakeResultWrapper( [] );
240 $dbr = wfGetDB( DB_REPLICA
);
242 if ( $direction === self
::DIR_PREV
) {
243 list( $dirs, $oper ) = [ "ASC", ">=" ];
244 } else { /* $direction === self::DIR_NEXT */
245 list( $dirs, $oper ) = [ "DESC", "<=" ];
249 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
254 $page_id = $this->page
->getId();
256 return $dbr->select( 'revision',
257 Revision
::selectFields(),
258 array_merge( [ 'rev_page' => $page_id ], $offsets ),
260 [ 'ORDER BY' => "rev_timestamp $dirs",
261 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
266 * Output a subscription feed listing recent edits to this page.
268 * @param string $type Feed type
270 function feed( $type ) {
271 if ( !FeedUtils
::checkFeedOutput( $type ) ) {
274 $request = $this->getRequest();
276 $feedClasses = $this->context
->getConfig()->get( 'FeedClasses' );
277 /** @var RSSFeed|AtomFeed $feed */
278 $feed = new $feedClasses[$type](
279 $this->getTitle()->getPrefixedText() . ' - ' .
280 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
281 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
282 $this->getTitle()->getFullURL( 'action=history' )
285 // Get a limit on number of feed entries. Provide a sane default
286 // of 10 if none is defined (but limit to $wgFeedLimit max)
287 $limit = $request->getInt( 'limit', 10 );
290 $this->context
->getConfig()->get( 'FeedLimit' )
293 $items = $this->fetchRevisions( $limit, 0, self
::DIR_NEXT
);
295 // Generate feed elements enclosed between header and footer.
297 if ( $items->numRows() ) {
298 foreach ( $items as $row ) {
299 $feed->outItem( $this->feedItem( $row ) );
302 $feed->outItem( $this->feedEmpty() );
307 function feedEmpty() {
309 $this->msg( 'nohistory' )->inContentLanguage()->text(),
310 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
311 $this->getTitle()->getFullURL(),
312 wfTimestamp( TS_MW
),
314 $this->getTitle()->getTalkPage()->getFullURL()
319 * Generate a FeedItem object from a given revision table row
320 * Borrows Recent Changes' feed generation functions for formatting;
321 * includes a diff to the previous revision (if any).
323 * @param stdClass|array $row Database row
326 function feedItem( $row ) {
327 $rev = new Revision( $row );
328 $rev->setTitle( $this->getTitle() );
329 $text = FeedUtils
::formatDiffRow(
331 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
333 $rev->getTimestamp(),
336 if ( $rev->getComment() == '' ) {
338 $title = $this->msg( 'history-feed-item-nocomment',
340 $wgContLang->timeanddate( $rev->getTimestamp() ),
341 $wgContLang->date( $rev->getTimestamp() ),
342 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
344 $title = $rev->getUserText() .
345 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
346 FeedItem
::stripComment( $rev->getComment() );
352 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
353 $rev->getTimestamp(),
355 $this->getTitle()->getTalkPage()->getFullURL()
364 class HistoryPager
extends ReverseChronologicalPager
{
368 public $lastRow = false;
370 public $counter, $historyPage, $buttons, $conds;
372 protected $oldIdChecked;
374 protected $preventClickjacking = false;
378 protected $parentLens;
380 /** @var bool Whether to show the tag editing UI */
381 protected $showTagEditUI;
384 * @param HistoryAction $historyPage
385 * @param string $year
386 * @param string $month
387 * @param string $tagFilter
388 * @param array $conds
390 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
391 parent
::__construct( $historyPage->getContext() );
392 $this->historyPage
= $historyPage;
393 $this->tagFilter
= $tagFilter;
394 $this->getDateCond( $year, $month );
395 $this->conds
= $conds;
396 $this->showTagEditUI
= ChangeTags
::showTagEditingUI( $this->getUser() );
399 // For hook compatibility...
400 function getArticle() {
401 return $this->historyPage
->getArticle();
404 function getSqlComment() {
405 if ( $this->conds
) {
406 return 'history page filtered'; // potentially slow, see CR r58153
408 return 'history page unfiltered';
412 function getQueryInfo() {
414 'tables' => [ 'revision', 'user' ],
415 'fields' => array_merge( Revision
::selectFields(), Revision
::selectUserFields() ),
416 'conds' => array_merge(
417 [ 'rev_page' => $this->getWikiPage()->getId() ],
419 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
420 'join_conds' => [ 'user' => Revision
::userJoinCond() ],
422 ChangeTags
::modifyDisplayQuery(
423 $queryInfo['tables'],
424 $queryInfo['fields'],
426 $queryInfo['join_conds'],
427 $queryInfo['options'],
430 Hooks
::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
435 function getIndexField() {
436 return 'rev_timestamp';
440 * @param stdClass $row
443 function formatRow( $row ) {
444 if ( $this->lastRow
) {
445 $latest = ( $this->counter
== 1 && $this->mIsFirst
);
446 $firstInList = $this->counter
== 1;
449 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
450 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
453 $s = $this->historyLine(
454 $this->lastRow
, $row, $notifTimestamp, $latest, $firstInList );
458 $this->lastRow
= $row;
463 function doBatchLookups() {
464 if ( !Hooks
::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult
] ) ) {
468 # Do a link batch query
469 $this->mResult
->seek( 0 );
470 $batch = new LinkBatch();
472 foreach ( $this->mResult
as $row ) {
473 if ( $row->rev_parent_id
) {
474 $revIds[] = $row->rev_parent_id
;
476 if ( !is_null( $row->user_name
) ) {
477 $batch->add( NS_USER
, $row->user_name
);
478 $batch->add( NS_USER_TALK
, $row->user_name
);
479 } else { # for anons or usernames of imported revisions
480 $batch->add( NS_USER
, $row->rev_user_text
);
481 $batch->add( NS_USER_TALK
, $row->rev_user_text
);
484 $this->parentLens
= Revision
::getParentLengths( $this->mDb
, $revIds );
486 $this->mResult
->seek( 0 );
490 * Creates begin of history list with a submit button
492 * @return string HTML output
494 function getStartBody() {
495 $this->lastRow
= false;
497 $this->oldIdChecked
= 0;
499 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
500 $s = Html
::openElement( 'form', [ 'action' => wfScript(),
501 'id' => 'mw-history-compare' ] ) . "\n";
502 $s .= Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
503 $s .= Html
::hidden( 'action', 'historysubmit' ) . "\n";
504 $s .= Html
::hidden( 'type', 'revision' ) . "\n";
506 // Button container stored in $this->buttons for re-use in getEndBody()
507 $this->buttons
= '<div>';
508 $className = 'historysubmit mw-history-compareselectedversions-button';
509 $attrs = [ 'class' => $className ]
510 + Linker
::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
511 $this->buttons
.= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
515 $user = $this->getUser();
517 if ( $user->isAllowed( 'deleterevision' ) ) {
518 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
520 if ( $this->showTagEditUI
) {
521 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
523 if ( $actionButtons ) {
524 $this->buttons
.= Xml
::tags( 'div', [ 'class' =>
525 'mw-history-revisionactions' ], $actionButtons );
528 if ( $user->isAllowed( 'deleterevision' ) ||
$this->showTagEditUI
) {
529 $this->buttons
.= ( new ListToggle( $this->getOutput() ) )->getHTML();
532 $this->buttons
.= '</div>';
534 $s .= $this->buttons
;
535 $s .= '<ul id="pagehistory">' . "\n";
540 private function getRevisionButton( $name, $msg ) {
541 $this->preventClickjacking();
542 # Note bug #20966, <button> is non-standard in IE<8
543 $element = Html
::element(
549 'class' => "historysubmit mw-history-$name-button",
551 $this->msg( $msg )->text()
556 function getEndBody() {
557 if ( $this->lastRow
) {
558 $latest = $this->counter
== 1 && $this->mIsFirst
;
559 $firstInList = $this->counter
== 1;
560 if ( $this->mIsBackwards
) {
561 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
562 if ( $this->mOffset
== '' ) {
568 # The next row is the past-the-end row
569 $next = $this->mPastTheEndRow
;
573 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
574 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
577 $s = $this->historyLine(
578 $this->lastRow
, $next, $notifTimestamp, $latest, $firstInList );
583 # Add second buttons only if there is more than one rev
584 if ( $this->getNumRows() > 2 ) {
585 $s .= $this->buttons
;
593 * Creates a submit button
595 * @param string $message Text of the submit button, will be escaped
596 * @param array $attributes Attributes
597 * @return string HTML output for the submit button
599 function submitButton( $message, $attributes = [] ) {
600 # Disable submit button if history has 1 revision only
601 if ( $this->getNumRows() > 1 ) {
602 return Html
::submitButton( $message, $attributes );
609 * Returns a row from the history printout.
611 * @todo document some more, and maybe clean up the code (some params redundant?)
613 * @param stdClass $row The database row corresponding to the previous line.
614 * @param mixed $next The database row corresponding to the next line
615 * (chronologically previous)
616 * @param bool|string $notificationtimestamp
617 * @param bool $latest Whether this row corresponds to the page's latest revision.
618 * @param bool $firstInList Whether this row corresponds to the first
619 * displayed on this history page.
620 * @return string HTML output for the row
622 function historyLine( $row, $next, $notificationtimestamp = false,
623 $latest = false, $firstInList = false ) {
624 $rev = new Revision( $row );
625 $rev->setTitle( $this->getTitle() );
627 if ( is_object( $next ) ) {
628 $prevRev = new Revision( $next );
629 $prevRev->setTitle( $this->getTitle() );
634 $curlink = $this->curLink( $rev, $latest );
635 $lastlink = $this->lastLink( $rev, $next );
636 $curLastlinks = $curlink . $this->historyPage
->message
['pipe-separator'] . $lastlink;
637 $histLinks = Html
::rawElement(
639 [ 'class' => 'mw-history-histlinks' ],
640 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
643 $diffButtons = $this->diffButtons( $rev, $firstInList );
644 $s = $histLinks . $diffButtons;
646 $link = $this->revLink( $rev );
650 $user = $this->getUser();
651 $canRevDelete = $user->isAllowed( 'deleterevision' );
652 // Show checkboxes for each revision, to allow for revision deletion and
654 if ( $canRevDelete ||
$this->showTagEditUI
) {
655 $this->preventClickjacking();
656 // If revision was hidden from sysops and we don't need the checkbox
657 // for anything else, disable it
658 if ( !$this->showTagEditUI
&& !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
659 $del = Xml
::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
660 // Otherwise, enable the checkbox...
662 $del = Xml
::check( 'showhiderevisions', false,
663 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
665 // User can only view deleted revisions...
666 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
667 // If revision was hidden from sysops, disable the link
668 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
669 $del = Linker
::revDeleteLinkDisabled( false );
670 // Otherwise, show the link...
672 $query = [ 'type' => 'revision',
673 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
674 $del .= Linker
::revDeleteLink( $query,
675 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), false );
682 $lang = $this->getLanguage();
683 $dirmark = $lang->getDirMark();
687 $s .= " <span class='history-user'>" .
688 Linker
::revUserTools( $rev, true ) . "</span>";
691 if ( $rev->isMinor() ) {
692 $s .= ' ' . ChangesList
::flag( 'minor', $this->getContext() );
695 # Sometimes rev_len isn't populated
696 if ( $rev->getSize() !== null ) {
697 # Size is always public data
698 $prevSize = isset( $this->parentLens
[$row->rev_parent_id
] )
699 ?
$this->parentLens
[$row->rev_parent_id
]
701 $sDiff = ChangesList
::showCharacterDifference( $prevSize, $rev->getSize() );
702 $fSize = Linker
::formatRevisionSize( $rev->getSize() );
703 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
706 # Text following the character difference is added just before running hooks
707 $s2 = Linker
::revComment( $rev, false, true );
709 if ( $notificationtimestamp && ( $row->rev_timestamp
>= $notificationtimestamp ) ) {
710 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
711 $classes[] = 'mw-history-line-updated';
716 # Rollback and undo links
717 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
718 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
719 // Get a rollback link without the brackets
720 $rollbackLink = Linker
::generateRollback(
723 [ 'verify', 'noBrackets' ]
725 if ( $rollbackLink ) {
726 $this->preventClickjacking();
727 $tools[] = $rollbackLink;
731 if ( !$rev->isDeleted( Revision
::DELETED_TEXT
)
732 && !$prevRev->isDeleted( Revision
::DELETED_TEXT
)
734 # Create undo tooltip for the first (=latest) line only
735 $undoTooltip = $latest
736 ?
[ 'title' => $this->msg( 'tooltip-undo' )->text() ]
738 $undolink = Linker
::linkKnown(
740 $this->msg( 'editundo' )->escaped(),
744 'undoafter' => $prevRev->getId(),
745 'undo' => $rev->getId()
748 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
751 // Allow extension to add their own links here
752 Hooks
::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
755 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
759 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
764 $classes = array_merge( $classes, $newClasses );
765 if ( $tagSummary !== '' ) {
766 $s2 .= " $tagSummary";
769 # Include separator between character difference and following text
771 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
774 Hooks
::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
778 $attribs['class'] = implode( ' ', $classes );
781 return Xml
::tags( 'li', $attribs, $s ) . "\n";
785 * Create a link to view this revision of the page
787 * @param Revision $rev
790 function revLink( $rev ) {
791 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
792 $date = htmlspecialchars( $date );
793 if ( $rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
794 $link = Linker
::linkKnown(
797 [ 'class' => 'mw-changeslist-date' ],
798 [ 'oldid' => $rev->getId() ]
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 Linker
::linkKnown(
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 if ( $next === 'unknown' ) {
852 # Next row probably exists but is unknown, use an oldid=prev link
853 return Linker
::linkKnown(
858 'diff' => $prevRev->getId(),
864 $nextRev = new Revision( $next );
866 if ( !$prevRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
867 ||
!$nextRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
872 return Linker
::linkKnown(
877 'diff' => $prevRev->getId(),
878 'oldid' => $next->rev_id
884 * Create radio buttons for page history
886 * @param Revision $rev
887 * @param bool $firstInList Is this version the first one?
889 * @return string HTML output for the radio buttons
891 function diffButtons( $rev, $firstInList ) {
892 if ( $this->getNumRows() > 1 ) {
894 $radio = [ 'type' => 'radio', 'value' => $id ];
895 /** @todo Move title texts to javascript */
896 if ( $firstInList ) {
897 $first = Xml
::element( 'input',
898 array_merge( $radio, [
899 'style' => 'visibility:hidden',
901 'id' => 'mw-oldid-null' ] )
903 $checkmark = [ 'checked' => 'checked' ];
905 # Check visibility of old revisions
906 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
907 $radio['disabled'] = 'disabled';
908 $checkmark = []; // We will check the next possible one
909 } elseif ( !$this->oldIdChecked
) {
910 $checkmark = [ 'checked' => 'checked' ];
911 $this->oldIdChecked
= $id;
915 $first = Xml
::element( 'input',
916 array_merge( $radio, $checkmark, [
918 'id' => "mw-oldid-$id" ] ) );
921 $second = Xml
::element( 'input',
922 array_merge( $radio, $checkmark, [
924 'id' => "mw-diff-$id" ] ) );
926 return $first . $second;
933 * This is called if a write operation is possible from the generated HTML
934 * @param bool $enable
936 function preventClickjacking( $enable = true ) {
937 $this->preventClickjacking
= $enable;
941 * Get the "prevent clickjacking" flag
944 function getPreventClickjacking() {
945 return $this->preventClickjacking
;