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.interface.helpers.styles',
137 'mediawiki.action.history.styles',
138 'mediawiki.special.changeslist',
140 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
141 $out = $this->getOutput();
142 $out->addModuleStyles( [
143 'mediawiki.ui.input',
144 'mediawiki.ui.checkbox',
148 // Handle atom/RSS feeds.
149 $feedType = $request->getVal( 'feed' );
151 $this->feed( $feedType );
156 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
158 // Fail nicely if article doesn't exist.
159 if ( !$this->page
->exists() ) {
160 global $wgSend404Code;
161 if ( $wgSend404Code ) {
162 $out->setStatusCode( 404 );
164 $out->addWikiMsg( 'nohistory' );
166 $dbr = wfGetDB( DB_REPLICA
);
168 # show deletion/move log if there is an entry
169 LogEventsList
::showLogExtract(
171 [ 'delete', 'move', 'protect' ],
175 'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
176 'showIfEmpty' => false,
177 'msgKey' => [ 'moveddeleted-notice' ]
185 * Add date selector to quickly get to a certain time
187 $year = $request->getInt( 'year' );
188 $month = $request->getInt( 'month' );
189 $tagFilter = $request->getVal( 'tagfilter' );
190 $tagSelector = ChangeTags
::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
193 * Option to show only revisions that have been (partially) hidden via RevisionDelete
195 if ( $request->getBool( 'deleted' ) ) {
196 $conds = [ 'rev_deleted != 0' ];
200 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
201 $checkDeleted = Xml
::checkLabel( $this->msg( 'history-show-deleted' )->text(),
202 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
207 // Add the general form
208 $action = htmlspecialchars( wfScript() );
209 $content = Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
210 $content .= Html
::hidden( 'action', 'history' ) . "\n";
211 $content .= Xml
::dateMenu(
212 ( $year == null ? MWTimestamp
::getLocalInstance()->format( 'Y' ) : $year ),
215 $content .= $tagSelector ?
( implode( "\u{00A0}", $tagSelector ) . "\u{00A0}" ) : '';
216 $content .= $checkDeleted . Html
::submitButton(
217 $this->msg( 'historyaction-submit' )->text(),
219 [ 'mw-ui-progressive' ]
222 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
224 $this->msg( 'history-fieldset-title' )->text(),
226 [ 'id' => 'mw-history-search' ]
231 Hooks
::run( 'PageHistoryBeforeList', [ &$this->page
, $this->getContext() ] );
233 // Create and output the list.
234 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
236 $pager->getNavigationBar() .
238 $pager->getNavigationBar()
240 $out->preventClickjacking( $pager->getPreventClickjacking() );
244 * Fetch an array of revisions, specified by a given limit, offset and
245 * direction. This is now only used by the feeds. It was previously
246 * used by the main UI but that's now handled by the pager.
248 * @param int $limit The limit number of revisions to get
250 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
251 * @return ResultWrapper
253 function fetchRevisions( $limit, $offset, $direction ) {
254 // Fail if article doesn't exist.
255 if ( !$this->getTitle()->exists() ) {
256 return new FakeResultWrapper( [] );
259 $dbr = wfGetDB( DB_REPLICA
);
261 if ( $direction === self
::DIR_PREV
) {
262 list( $dirs, $oper ) = [ "ASC", ">=" ];
263 } else { /* $direction === self::DIR_NEXT */
264 list( $dirs, $oper ) = [ "DESC", "<=" ];
268 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
273 $page_id = $this->page
->getId();
275 $revQuery = Revision
::getQueryInfo();
279 array_merge( [ 'rev_page' => $page_id ], $offsets ),
282 'ORDER BY' => "rev_timestamp $dirs",
283 'USE INDEX' => [ 'revision' => 'page_timestamp' ],
291 * Output a subscription feed listing recent edits to this page.
293 * @param string $type Feed type
295 function feed( $type ) {
296 if ( !FeedUtils
::checkFeedOutput( $type ) ) {
299 $request = $this->getRequest();
301 $feedClasses = $this->context
->getConfig()->get( 'FeedClasses' );
302 /** @var RSSFeed|AtomFeed $feed */
303 $feed = new $feedClasses[$type](
304 $this->getTitle()->getPrefixedText() . ' - ' .
305 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
306 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
307 $this->getTitle()->getFullURL( 'action=history' )
310 // Get a limit on number of feed entries. Provide a sane default
311 // of 10 if none is defined (but limit to $wgFeedLimit max)
312 $limit = $request->getInt( 'limit', 10 );
315 $this->context
->getConfig()->get( 'FeedLimit' )
318 $items = $this->fetchRevisions( $limit, 0, self
::DIR_NEXT
);
320 // Generate feed elements enclosed between header and footer.
322 if ( $items->numRows() ) {
323 foreach ( $items as $row ) {
324 $feed->outItem( $this->feedItem( $row ) );
327 $feed->outItem( $this->feedEmpty() );
332 function feedEmpty() {
334 $this->msg( 'nohistory' )->inContentLanguage()->text(),
335 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
336 $this->getTitle()->getFullURL(),
337 wfTimestamp( TS_MW
),
339 $this->getTitle()->getTalkPage()->getFullURL()
344 * Generate a FeedItem object from a given revision table row
345 * Borrows Recent Changes' feed generation functions for formatting;
346 * includes a diff to the previous revision (if any).
348 * @param stdClass|array $row Database row
351 function feedItem( $row ) {
352 $rev = new Revision( $row, 0, $this->getTitle() );
354 $text = FeedUtils
::formatDiffRow(
356 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
358 $rev->getTimestamp(),
361 if ( $rev->getComment() == '' ) {
362 $contLang = MediaWikiServices
::getInstance()->getContentLanguage();
363 $title = $this->msg( 'history-feed-item-nocomment',
365 $contLang->timeanddate( $rev->getTimestamp() ),
366 $contLang->date( $rev->getTimestamp() ),
367 $contLang->time( $rev->getTimestamp() )
368 )->inContentLanguage()->text();
370 $title = $rev->getUserText() .
371 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
372 FeedItem
::stripComment( $rev->getComment() );
378 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
379 $rev->getTimestamp(),
381 $this->getTitle()->getTalkPage()->getFullURL()
390 class HistoryPager
extends ReverseChronologicalPager
{
394 public $lastRow = false;
396 public $counter, $historyPage, $buttons, $conds;
398 protected $oldIdChecked;
400 protected $preventClickjacking = false;
404 protected $parentLens;
406 /** @var bool Whether to show the tag editing UI */
407 protected $showTagEditUI;
413 * @param HistoryAction $historyPage
414 * @param string $year
415 * @param string $month
416 * @param string $tagFilter
417 * @param array $conds
419 public function __construct(
420 HistoryAction
$historyPage,
426 parent
::__construct( $historyPage->getContext() );
427 $this->historyPage
= $historyPage;
428 $this->tagFilter
= $tagFilter;
429 $this->getDateCond( $year, $month );
430 $this->conds
= $conds;
431 $this->showTagEditUI
= ChangeTags
::showTagEditingUI( $this->getUser() );
434 // For hook compatibility...
435 function getArticle() {
436 return $this->historyPage
->getArticle();
439 function getSqlComment() {
440 if ( $this->conds
) {
441 return 'history page filtered'; // potentially slow, see CR r58153
443 return 'history page unfiltered';
447 function getQueryInfo() {
448 $revQuery = Revision
::getQueryInfo( [ 'user' ] );
450 'tables' => $revQuery['tables'],
451 'fields' => $revQuery['fields'],
452 'conds' => array_merge(
453 [ 'rev_page' => $this->getWikiPage()->getId() ],
455 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
456 'join_conds' => $revQuery['joins'],
458 ChangeTags
::modifyDisplayQuery(
459 $queryInfo['tables'],
460 $queryInfo['fields'],
462 $queryInfo['join_conds'],
463 $queryInfo['options'],
467 // Avoid PHP 7.1 warning of passing $this by reference
468 $historyPager = $this;
469 Hooks
::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
474 function getIndexField() {
475 return 'rev_timestamp';
479 * @param stdClass $row
482 function formatRow( $row ) {
483 if ( $this->lastRow
) {
484 $latest = ( $this->counter
== 1 && $this->mIsFirst
);
485 $firstInList = $this->counter
== 1;
488 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
489 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
492 $s = $this->historyLine(
493 $this->lastRow
, $row, $notifTimestamp, $latest, $firstInList );
497 $this->lastRow
= $row;
502 protected function doBatchLookups() {
503 if ( !Hooks
::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult
] ) ) {
507 # Do a link batch query
508 $this->mResult
->seek( 0 );
509 $batch = new LinkBatch();
511 foreach ( $this->mResult
as $row ) {
512 if ( $row->rev_parent_id
) {
513 $revIds[] = $row->rev_parent_id
;
515 if ( $row->user_name
!== null ) {
516 $batch->add( NS_USER
, $row->user_name
);
517 $batch->add( NS_USER_TALK
, $row->user_name
);
518 } else { # for anons or usernames of imported revisions
519 $batch->add( NS_USER
, $row->rev_user_text
);
520 $batch->add( NS_USER_TALK
, $row->rev_user_text
);
523 $this->parentLens
= Revision
::getParentLengths( $this->mDb
, $revIds );
525 $this->mResult
->seek( 0 );
529 * Creates begin of history list with a submit button
531 * @return string HTML output
533 protected function getStartBody() {
534 $this->lastRow
= false;
536 $this->oldIdChecked
= 0;
538 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
539 $s = Html
::openElement( 'form', [ 'action' => wfScript(),
540 'id' => 'mw-history-compare' ] ) . "\n";
541 $s .= Html
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
542 $s .= Html
::hidden( 'action', 'historysubmit' ) . "\n";
543 $s .= Html
::hidden( 'type', 'revision' ) . "\n";
545 // Button container stored in $this->buttons for re-use in getEndBody()
546 $this->buttons
= '<div>';
547 $className = 'historysubmit mw-history-compareselectedversions-button';
548 $attrs = [ 'class' => $className ]
549 + Linker
::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
550 $this->buttons
.= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
554 $user = $this->getUser();
556 if ( $user->isAllowed( 'deleterevision' ) ) {
557 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
559 if ( $this->showTagEditUI
) {
560 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
562 if ( $actionButtons ) {
563 $this->buttons
.= Xml
::tags( 'div', [ 'class' =>
564 'mw-history-revisionactions' ], $actionButtons );
567 if ( $user->isAllowed( 'deleterevision' ) ||
$this->showTagEditUI
) {
568 $this->buttons
.= ( new ListToggle( $this->getOutput() ) )->getHTML();
571 $this->buttons
.= '</div>';
573 $s .= $this->buttons
;
574 $s .= '<ul id="pagehistory">' . "\n";
579 private function getRevisionButton( $name, $msg ) {
580 $this->preventClickjacking();
581 # Note T22966, <button> is non-standard in IE<8
582 $element = Html
::element(
588 'class' => "historysubmit mw-history-$name-button",
590 $this->msg( $msg )->text()
595 protected function getEndBody() {
596 if ( $this->lastRow
) {
597 $latest = $this->counter
== 1 && $this->mIsFirst
;
598 $firstInList = $this->counter
== 1;
599 if ( $this->mIsBackwards
) {
600 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
601 if ( $this->mOffset
== '' ) {
607 # The next row is the past-the-end row
608 $next = $this->mPastTheEndRow
;
612 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
613 ?
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
616 $s = $this->historyLine(
617 $this->lastRow
, $next, $notifTimestamp, $latest, $firstInList );
622 # Add second buttons only if there is more than one rev
623 if ( $this->getNumRows() > 2 ) {
624 $s .= $this->buttons
;
632 * Creates a submit button
634 * @param string $message Text of the submit button, will be escaped
635 * @param array $attributes
636 * @return string HTML output for the submit button
638 function submitButton( $message, $attributes = [] ) {
639 # Disable submit button if history has 1 revision only
640 if ( $this->getNumRows() > 1 ) {
641 return Html
::submitButton( $message, $attributes );
648 * Returns a row from the history printout.
650 * @todo document some more, and maybe clean up the code (some params redundant?)
652 * @param stdClass $row The database row corresponding to the previous line.
653 * @param mixed $next The database row corresponding to the next line
654 * (chronologically previous)
655 * @param bool|string $notificationtimestamp
656 * @param bool $latest Whether this row corresponds to the page's latest revision.
657 * @param bool $firstInList Whether this row corresponds to the first
658 * displayed on this history page.
659 * @return string HTML output for the row
661 function historyLine( $row, $next, $notificationtimestamp = false,
662 $latest = false, $firstInList = false ) {
663 $rev = new Revision( $row, 0, $this->getTitle() );
665 if ( is_object( $next ) ) {
666 $prevRev = new Revision( $next, 0, $this->getTitle() );
671 $curlink = $this->curLink( $rev, $latest );
672 $lastlink = $this->lastLink( $rev, $next );
673 $curLastlinks = $curlink . $this->historyPage
->message
['pipe-separator'] . $lastlink;
674 $histLinks = Html
::rawElement(
676 [ 'class' => 'mw-history-histlinks' ],
677 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
680 $diffButtons = $this->diffButtons( $rev, $firstInList );
681 $s = $histLinks . $diffButtons;
683 $link = $this->revLink( $rev );
687 $user = $this->getUser();
688 $canRevDelete = $user->isAllowed( 'deleterevision' );
689 // Show checkboxes for each revision, to allow for revision deletion and
691 if ( $canRevDelete ||
$this->showTagEditUI
) {
692 $this->preventClickjacking();
693 // If revision was hidden from sysops and we don't need the checkbox
694 // for anything else, disable it
695 if ( !$this->showTagEditUI
&& !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
696 $del = Xml
::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
697 // Otherwise, enable the checkbox...
699 $del = Xml
::check( 'showhiderevisions', false,
700 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
702 // User can only view deleted revisions...
703 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
704 // If revision was hidden from sysops, disable the link
705 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
706 $del = Linker
::revDeleteLinkDisabled( false );
707 // Otherwise, show the link...
709 $query = [ 'type' => 'revision',
710 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
711 $del .= Linker
::revDeleteLink( $query,
712 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), false );
719 $lang = $this->getLanguage();
720 $dirmark = $lang->getDirMark();
724 $s .= " <span class='history-user'>" .
725 Linker
::revUserTools( $rev, true ) . "</span>";
728 if ( $rev->isMinor() ) {
729 $s .= ' ' . ChangesList
::flag( 'minor', $this->getContext() );
732 # Sometimes rev_len isn't populated
733 if ( $rev->getSize() !== null ) {
734 # Size is always public data
735 $prevSize = $this->parentLens
[$row->rev_parent_id
] ??
0;
736 $sDiff = ChangesList
::showCharacterDifference( $prevSize, $rev->getSize() );
737 $fSize = Linker
::formatRevisionSize( $rev->getSize() );
738 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
741 # Text following the character difference is added just before running hooks
742 $s2 = Linker
::revComment( $rev, false, true );
744 if ( $notificationtimestamp && ( $row->rev_timestamp
>= $notificationtimestamp ) ) {
745 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
746 $classes[] = 'mw-history-line-updated';
751 # Rollback and undo links
752 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
753 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
754 // Get a rollback link without the brackets
755 $rollbackLink = Linker
::generateRollback(
758 [ 'verify', 'noBrackets' ]
760 if ( $rollbackLink ) {
761 $this->preventClickjacking();
762 $tools[] = $rollbackLink;
766 if ( !$rev->isDeleted( Revision
::DELETED_TEXT
)
767 && !$prevRev->isDeleted( Revision
::DELETED_TEXT
)
769 # Create undo tooltip for the first (=latest) line only
770 $undoTooltip = $latest
771 ?
[ 'title' => $this->msg( 'tooltip-undo' )->text() ]
773 $undolink = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
775 $this->msg( 'editundo' )->text(),
779 'undoafter' => $prevRev->getId(),
780 'undo' => $rev->getId()
783 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
786 // Allow extension to add their own links here
787 Hooks
::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
790 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
794 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow(
799 $classes = array_merge( $classes, $newClasses );
800 if ( $tagSummary !== '' ) {
801 $s2 .= " $tagSummary";
804 # Include separator between character difference and following text
806 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
809 $attribs = [ 'data-mw-revid' => $rev->getId() ];
811 Hooks
::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes, &$attribs ] );
812 $attribs = array_filter( $attribs,
813 [ Sanitizer
::class, 'isReservedDataAttribute' ],
818 $attribs['class'] = implode( ' ', $classes );
821 return Xml
::tags( 'li', $attribs, $s ) . "\n";
825 * Create a link to view this revision of the page
827 * @param Revision $rev
830 function revLink( $rev ) {
831 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
832 if ( $rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
833 $link = MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
836 [ 'class' => 'mw-changeslist-date' ],
837 [ 'oldid' => $rev->getId() ]
840 $link = htmlspecialchars( $date );
842 if ( $rev->isDeleted( Revision
::DELETED_TEXT
) ) {
843 $link = "<span class=\"history-deleted\">$link</span>";
850 * Create a diff-to-current link for this revision for this page
852 * @param Revision $rev
853 * @param bool $latest This is the latest revision of the page?
856 function curLink( $rev, $latest ) {
857 $cur = $this->historyPage
->message
['cur'];
858 if ( $latest ||
!$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
861 return MediaWikiServices
::getInstance()->getLinkRenderer()->makeKnownLink(
863 new HtmlArmor( $cur ),
866 'diff' => $this->getWikiPage()->getLatest(),
867 'oldid' => $rev->getId()
874 * Create a diff-to-previous link for this revision for this page.
876 * @param Revision $prevRev The revision being displayed
877 * @param stdClass|string|null $next The next revision in list (that is
878 * the previous one in chronological order).
879 * May either be a row, "unknown" or null.
882 function lastLink( $prevRev, $next ) {
883 $last = $this->historyPage
->message
['last'];
885 if ( $next === null ) {
886 # Probably no next row
890 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
891 if ( $next === 'unknown' ) {
892 # Next row probably exists but is unknown, use an oldid=prev link
893 return $linkRenderer->makeKnownLink(
895 new HtmlArmor( $last ),
898 'diff' => $prevRev->getId(),
904 $nextRev = new Revision( $next );
906 if ( !$prevRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
907 ||
!$nextRev->userCan( Revision
::DELETED_TEXT
, $this->getUser() )
912 return $linkRenderer->makeKnownLink(
914 new HtmlArmor( $last ),
917 'diff' => $prevRev->getId(),
918 'oldid' => $next->rev_id
924 * Create radio buttons for page history
926 * @param Revision $rev
927 * @param bool $firstInList Is this version the first one?
929 * @return string HTML output for the radio buttons
931 function diffButtons( $rev, $firstInList ) {
932 if ( $this->getNumRows() > 1 ) {
934 $radio = [ 'type' => 'radio', 'value' => $id ];
935 /** @todo Move title texts to javascript */
936 if ( $firstInList ) {
937 $first = Xml
::element( 'input',
938 array_merge( $radio, [
939 'style' => 'visibility:hidden',
941 'id' => 'mw-oldid-null' ] )
943 $checkmark = [ 'checked' => 'checked' ];
945 # Check visibility of old revisions
946 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
947 $radio['disabled'] = 'disabled';
948 $checkmark = []; // We will check the next possible one
949 } elseif ( !$this->oldIdChecked
) {
950 $checkmark = [ 'checked' => 'checked' ];
951 $this->oldIdChecked
= $id;
955 $first = Xml
::element( 'input',
956 array_merge( $radio, $checkmark, [
958 'id' => "mw-oldid-$id" ] ) );
961 $second = Xml
::element( 'input',
962 array_merge( $radio, $checkmark, [
964 'id' => "mw-diff-$id" ] ) );
966 return $first . $second;
973 * This is called if a write operation is possible from the generated HTML
974 * @param bool $enable
976 function preventClickjacking( $enable = true ) {
977 $this->preventClickjacking
= $enable;
981 * Get the "prevent clickjacking" flag
984 function getPreventClickjacking() {
985 return $this->preventClickjacking
;