Convert all array() syntax to []
[lhc/web/wiklou.git] / includes / actions / HistoryAction.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 * @ingroup Actions
24 */
25
26 /**
27 * This class handles printing the history page for an article. In order to
28 * be efficient, it uses timestamps rather than offsets for paging, to avoid
29 * costly LIMIT,offset queries.
30 *
31 * Construct it by passing in an Article, and call $h->history() to print the
32 * history.
33 *
34 * @ingroup Actions
35 */
36 class HistoryAction extends FormlessAction {
37 const DIR_PREV = 0;
38 const DIR_NEXT = 1;
39
40 /** @var array Array of message keys and strings */
41 public $message;
42
43 public function getName() {
44 return 'history';
45 }
46
47 public function requiresWrite() {
48 return false;
49 }
50
51 public function requiresUnblock() {
52 return false;
53 }
54
55 protected function getPageTitle() {
56 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
57 }
58
59 protected function getDescription() {
60 // Creation of a subtitle link pointing to [[Special:Log]]
61 return Linker::linkKnown(
62 SpecialPage::getTitleFor( 'Log' ),
63 $this->msg( 'viewpagelogs' )->escaped(),
64 [],
65 [ 'page' => $this->getTitle()->getPrefixedText() ]
66 );
67 }
68
69 /**
70 * @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
71 */
72 public function getArticle() {
73 return $this->page;
74 }
75
76 /**
77 * As we use the same small set of messages in various methods and that
78 * they are called often, we call them once and save them in $this->message
79 */
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();
86 }
87 }
88 }
89
90 /**
91 * Print the history page for an article.
92 */
93 function onView() {
94 $out = $this->getOutput();
95 $request = $this->getRequest();
96
97 /**
98 * Allow client caching.
99 */
100 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
101 return; // Client cache fresh and headers sent, nothing more to do.
102 }
103
104 $this->preCacheMessages();
105 $config = $this->context->getConfig();
106
107 # Fill in the file cache if not set already
108 $useFileCache = $config->get( 'UseFileCache' );
109 if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
110 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
111 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
112 ob_start( [ &$cache, 'saveToFileCache' ] );
113 }
114 }
115
116 // Setup page variables.
117 $out->setFeedAppendQuery( 'action=history' );
118 $out->addModules( 'mediawiki.action.history' );
119 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
120 $out = $this->getOutput();
121 $out->addModuleStyles( [
122 'mediawiki.ui.input',
123 'mediawiki.ui.checkbox',
124 ] );
125 }
126
127 // Handle atom/RSS feeds.
128 $feedType = $request->getVal( 'feed' );
129 if ( $feedType ) {
130 $this->feed( $feedType );
131
132 return;
133 }
134
135 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
136
137 // Fail nicely if article doesn't exist.
138 if ( !$this->page->exists() ) {
139 $out->addWikiMsg( 'nohistory' );
140 # show deletion/move log if there is an entry
141 LogEventsList::showLogExtract(
142 $out,
143 [ 'delete', 'move' ],
144 $this->getTitle(),
145 '',
146 [ 'lim' => 10,
147 'conds' => [ "log_action != 'revision'" ],
148 'showIfEmpty' => false,
149 'msgKey' => [ 'moveddeleted-notice' ]
150 ]
151 );
152
153 return;
154 }
155
156 /**
157 * Add date selector to quickly get to a certain time
158 */
159 $year = $request->getInt( 'year' );
160 $month = $request->getInt( 'month' );
161 $tagFilter = $request->getVal( 'tagfilter' );
162 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
163
164 /**
165 * Option to show only revisions that have been (partially) hidden via RevisionDelete
166 */
167 if ( $request->getBool( 'deleted' ) ) {
168 $conds = [ 'rev_deleted != 0' ];
169 } else {
170 $conds = [];
171 }
172 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
173 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
174 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
175 } else {
176 $checkDeleted = '';
177 }
178
179 // Add the general form
180 $action = htmlspecialchars( wfScript() );
181 $out->addHTML(
182 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
183 Xml::fieldset(
184 $this->msg( 'history-fieldset-title' )->text(),
185 false,
186 [ 'id' => 'mw-history-search' ]
187 ) .
188 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
189 Html::hidden( 'action', 'history' ) . "\n" .
190 Xml::dateMenu(
191 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
192 $month
193 ) . '&#160;' .
194 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
195 $checkDeleted .
196 Html::submitButton(
197 $this->msg( 'historyaction-submit' )->text(),
198 [],
199 [ 'mw-ui-progressive' ]
200 ) . "\n" .
201 '</fieldset></form>'
202 );
203
204 Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
205
206 // Create and output the list.
207 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
208 $out->addHTML(
209 $pager->getNavigationBar() .
210 $pager->getBody() .
211 $pager->getNavigationBar()
212 );
213 $out->preventClickjacking( $pager->getPreventClickjacking() );
214
215 }
216
217 /**
218 * Fetch an array of revisions, specified by a given limit, offset and
219 * direction. This is now only used by the feeds. It was previously
220 * used by the main UI but that's now handled by the pager.
221 *
222 * @param int $limit The limit number of revisions to get
223 * @param int $offset
224 * @param int $direction Either self::DIR_PREV or self::DIR_NEXT
225 * @return ResultWrapper
226 */
227 function fetchRevisions( $limit, $offset, $direction ) {
228 // Fail if article doesn't exist.
229 if ( !$this->getTitle()->exists() ) {
230 return new FakeResultWrapper( [] );
231 }
232
233 $dbr = wfGetDB( DB_SLAVE );
234
235 if ( $direction === self::DIR_PREV ) {
236 list( $dirs, $oper ) = [ "ASC", ">=" ];
237 } else { /* $direction === self::DIR_NEXT */
238 list( $dirs, $oper ) = [ "DESC", "<=" ];
239 }
240
241 if ( $offset ) {
242 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
243 } else {
244 $offsets = [];
245 }
246
247 $page_id = $this->page->getId();
248
249 return $dbr->select( 'revision',
250 Revision::selectFields(),
251 array_merge( [ 'rev_page' => $page_id ], $offsets ),
252 __METHOD__,
253 [ 'ORDER BY' => "rev_timestamp $dirs",
254 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
255 );
256 }
257
258 /**
259 * Output a subscription feed listing recent edits to this page.
260 *
261 * @param string $type Feed type
262 */
263 function feed( $type ) {
264 if ( !FeedUtils::checkFeedOutput( $type ) ) {
265 return;
266 }
267 $request = $this->getRequest();
268
269 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
270 /** @var RSSFeed|AtomFeed $feed */
271 $feed = new $feedClasses[$type](
272 $this->getTitle()->getPrefixedText() . ' - ' .
273 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
274 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
275 $this->getTitle()->getFullURL( 'action=history' )
276 );
277
278 // Get a limit on number of feed entries. Provide a sane default
279 // of 10 if none is defined (but limit to $wgFeedLimit max)
280 $limit = $request->getInt( 'limit', 10 );
281 $limit = min(
282 max( $limit, 1 ),
283 $this->context->getConfig()->get( 'FeedLimit' )
284 );
285
286 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
287
288 // Generate feed elements enclosed between header and footer.
289 $feed->outHeader();
290 if ( $items->numRows() ) {
291 foreach ( $items as $row ) {
292 $feed->outItem( $this->feedItem( $row ) );
293 }
294 } else {
295 $feed->outItem( $this->feedEmpty() );
296 }
297 $feed->outFooter();
298 }
299
300 function feedEmpty() {
301 return new FeedItem(
302 $this->msg( 'nohistory' )->inContentLanguage()->text(),
303 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
304 $this->getTitle()->getFullURL(),
305 wfTimestamp( TS_MW ),
306 '',
307 $this->getTitle()->getTalkPage()->getFullURL()
308 );
309 }
310
311 /**
312 * Generate a FeedItem object from a given revision table row
313 * Borrows Recent Changes' feed generation functions for formatting;
314 * includes a diff to the previous revision (if any).
315 *
316 * @param stdClass|array $row Database row
317 * @return FeedItem
318 */
319 function feedItem( $row ) {
320 $rev = new Revision( $row );
321 $rev->setTitle( $this->getTitle() );
322 $text = FeedUtils::formatDiffRow(
323 $this->getTitle(),
324 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
325 $rev->getId(),
326 $rev->getTimestamp(),
327 $rev->getComment()
328 );
329 if ( $rev->getComment() == '' ) {
330 global $wgContLang;
331 $title = $this->msg( 'history-feed-item-nocomment',
332 $rev->getUserText(),
333 $wgContLang->timeanddate( $rev->getTimestamp() ),
334 $wgContLang->date( $rev->getTimestamp() ),
335 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
336 } else {
337 $title = $rev->getUserText() .
338 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
339 FeedItem::stripComment( $rev->getComment() );
340 }
341
342 return new FeedItem(
343 $title,
344 $text,
345 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
346 $rev->getTimestamp(),
347 $rev->getUserText(),
348 $this->getTitle()->getTalkPage()->getFullURL()
349 );
350 }
351 }
352
353 /**
354 * @ingroup Pager
355 * @ingroup Actions
356 */
357 class HistoryPager extends ReverseChronologicalPager {
358 /**
359 * @var bool|stdClass
360 */
361 public $lastRow = false;
362
363 public $counter, $historyPage, $buttons, $conds;
364
365 protected $oldIdChecked;
366
367 protected $preventClickjacking = false;
368 /**
369 * @var array
370 */
371 protected $parentLens;
372
373 /** @var bool Whether to show the tag editing UI */
374 protected $showTagEditUI;
375
376 /**
377 * @param HistoryAction $historyPage
378 * @param string $year
379 * @param string $month
380 * @param string $tagFilter
381 * @param array $conds
382 */
383 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
384 parent::__construct( $historyPage->getContext() );
385 $this->historyPage = $historyPage;
386 $this->tagFilter = $tagFilter;
387 $this->getDateCond( $year, $month );
388 $this->conds = $conds;
389 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
390 }
391
392 // For hook compatibility...
393 function getArticle() {
394 return $this->historyPage->getArticle();
395 }
396
397 function getSqlComment() {
398 if ( $this->conds ) {
399 return 'history page filtered'; // potentially slow, see CR r58153
400 } else {
401 return 'history page unfiltered';
402 }
403 }
404
405 function getQueryInfo() {
406 $queryInfo = [
407 'tables' => [ 'revision', 'user' ],
408 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
409 'conds' => array_merge(
410 [ 'rev_page' => $this->getWikiPage()->getId() ],
411 $this->conds ),
412 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
413 'join_conds' => [ 'user' => Revision::userJoinCond() ],
414 ];
415 ChangeTags::modifyDisplayQuery(
416 $queryInfo['tables'],
417 $queryInfo['fields'],
418 $queryInfo['conds'],
419 $queryInfo['join_conds'],
420 $queryInfo['options'],
421 $this->tagFilter
422 );
423 Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
424
425 return $queryInfo;
426 }
427
428 function getIndexField() {
429 return 'rev_timestamp';
430 }
431
432 /**
433 * @param stdClass $row
434 * @return string
435 */
436 function formatRow( $row ) {
437 if ( $this->lastRow ) {
438 $latest = ( $this->counter == 1 && $this->mIsFirst );
439 $firstInList = $this->counter == 1;
440 $this->counter++;
441
442 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
443 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
444 : false;
445
446 $s = $this->historyLine(
447 $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
448 } else {
449 $s = '';
450 }
451 $this->lastRow = $row;
452
453 return $s;
454 }
455
456 function doBatchLookups() {
457 if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
458 return;
459 }
460
461 # Do a link batch query
462 $this->mResult->seek( 0 );
463 $batch = new LinkBatch();
464 $revIds = [];
465 foreach ( $this->mResult as $row ) {
466 if ( $row->rev_parent_id ) {
467 $revIds[] = $row->rev_parent_id;
468 }
469 if ( !is_null( $row->user_name ) ) {
470 $batch->add( NS_USER, $row->user_name );
471 $batch->add( NS_USER_TALK, $row->user_name );
472 } else { # for anons or usernames of imported revisions
473 $batch->add( NS_USER, $row->rev_user_text );
474 $batch->add( NS_USER_TALK, $row->rev_user_text );
475 }
476 }
477 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
478 $batch->execute();
479 $this->mResult->seek( 0 );
480 }
481
482 /**
483 * Creates begin of history list with a submit button
484 *
485 * @return string HTML output
486 */
487 function getStartBody() {
488 $this->lastRow = false;
489 $this->counter = 1;
490 $this->oldIdChecked = 0;
491
492 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
493 $s = Html::openElement( 'form', [ 'action' => wfScript(),
494 'id' => 'mw-history-compare' ] ) . "\n";
495 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
496 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
497 $s .= Html::hidden( 'type', 'revision' ) . "\n";
498
499 // Button container stored in $this->buttons for re-use in getEndBody()
500 $this->buttons = '<div>';
501 $className = 'historysubmit mw-history-compareselectedversions-button';
502 $attrs = [ 'class' => $className ]
503 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
504 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
505 $attrs
506 ) . "\n";
507
508 $user = $this->getUser();
509 $actionButtons = '';
510 if ( $user->isAllowed( 'deleterevision' ) ) {
511 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
512 }
513 if ( $this->showTagEditUI ) {
514 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
515 }
516 if ( $actionButtons ) {
517 $this->buttons .= Xml::tags( 'div', [ 'class' =>
518 'mw-history-revisionactions' ], $actionButtons );
519 }
520 $this->buttons .= '</div>';
521
522 $s .= $this->buttons;
523 $s .= '<ul id="pagehistory">' . "\n";
524
525 return $s;
526 }
527
528 private function getRevisionButton( $name, $msg ) {
529 $this->preventClickjacking();
530 # Note bug #20966, <button> is non-standard in IE<8
531 $element = Html::element(
532 'button',
533 [
534 'type' => 'submit',
535 'name' => $name,
536 'value' => '1',
537 'class' => "historysubmit mw-history-$name-button",
538 ],
539 $this->msg( $msg )->text()
540 ) . "\n";
541 return $element;
542 }
543
544 function getEndBody() {
545 if ( $this->lastRow ) {
546 $latest = $this->counter == 1 && $this->mIsFirst;
547 $firstInList = $this->counter == 1;
548 if ( $this->mIsBackwards ) {
549 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
550 if ( $this->mOffset == '' ) {
551 $next = null;
552 } else {
553 $next = 'unknown';
554 }
555 } else {
556 # The next row is the past-the-end row
557 $next = $this->mPastTheEndRow;
558 }
559 $this->counter++;
560
561 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
562 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
563 : false;
564
565 $s = $this->historyLine(
566 $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
567 } else {
568 $s = '';
569 }
570 $s .= "</ul>\n";
571 # Add second buttons only if there is more than one rev
572 if ( $this->getNumRows() > 2 ) {
573 $s .= $this->buttons;
574 }
575 $s .= '</form>';
576
577 return $s;
578 }
579
580 /**
581 * Creates a submit button
582 *
583 * @param string $message Text of the submit button, will be escaped
584 * @param array $attributes Attributes
585 * @return string HTML output for the submit button
586 */
587 function submitButton( $message, $attributes = [] ) {
588 # Disable submit button if history has 1 revision only
589 if ( $this->getNumRows() > 1 ) {
590 return Html::submitButton( $message, $attributes );
591 } else {
592 return '';
593 }
594 }
595
596 /**
597 * Returns a row from the history printout.
598 *
599 * @todo document some more, and maybe clean up the code (some params redundant?)
600 *
601 * @param stdClass $row The database row corresponding to the previous line.
602 * @param mixed $next The database row corresponding to the next line
603 * (chronologically previous)
604 * @param bool|string $notificationtimestamp
605 * @param bool $latest Whether this row corresponds to the page's latest revision.
606 * @param bool $firstInList Whether this row corresponds to the first
607 * displayed on this history page.
608 * @return string HTML output for the row
609 */
610 function historyLine( $row, $next, $notificationtimestamp = false,
611 $latest = false, $firstInList = false ) {
612 $rev = new Revision( $row );
613 $rev->setTitle( $this->getTitle() );
614
615 if ( is_object( $next ) ) {
616 $prevRev = new Revision( $next );
617 $prevRev->setTitle( $this->getTitle() );
618 } else {
619 $prevRev = null;
620 }
621
622 $curlink = $this->curLink( $rev, $latest );
623 $lastlink = $this->lastLink( $rev, $next );
624 $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
625 $histLinks = Html::rawElement(
626 'span',
627 [ 'class' => 'mw-history-histlinks' ],
628 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
629 );
630
631 $diffButtons = $this->diffButtons( $rev, $firstInList );
632 $s = $histLinks . $diffButtons;
633
634 $link = $this->revLink( $rev );
635 $classes = [];
636
637 $del = '';
638 $user = $this->getUser();
639 $canRevDelete = $user->isAllowed( 'deleterevision' );
640 // Show checkboxes for each revision, to allow for revision deletion and
641 // change tags
642 if ( $canRevDelete || $this->showTagEditUI ) {
643 $this->preventClickjacking();
644 // If revision was hidden from sysops and we don't need the checkbox
645 // for anything else, disable it
646 if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
647 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
648 // Otherwise, enable the checkbox...
649 } else {
650 $del = Xml::check( 'showhiderevisions', false,
651 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
652 }
653 // User can only view deleted revisions...
654 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
655 // If revision was hidden from sysops, disable the link
656 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
657 $del = Linker::revDeleteLinkDisabled( false );
658 // Otherwise, show the link...
659 } else {
660 $query = [ 'type' => 'revision',
661 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
662 $del .= Linker::revDeleteLink( $query,
663 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
664 }
665 }
666 if ( $del ) {
667 $s .= " $del ";
668 }
669
670 $lang = $this->getLanguage();
671 $dirmark = $lang->getDirMark();
672
673 $s .= " $link";
674 $s .= $dirmark;
675 $s .= " <span class='history-user'>" .
676 Linker::revUserTools( $rev, true ) . "</span>";
677 $s .= $dirmark;
678
679 if ( $rev->isMinor() ) {
680 $s .= ' ' . ChangesList::flag( 'minor' );
681 }
682
683 # Sometimes rev_len isn't populated
684 if ( $rev->getSize() !== null ) {
685 # Size is always public data
686 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
687 ? $this->parentLens[$row->rev_parent_id]
688 : 0;
689 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
690 $fSize = Linker::formatRevisionSize( $rev->getSize() );
691 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
692 }
693
694 # Text following the character difference is added just before running hooks
695 $s2 = Linker::revComment( $rev, false, true );
696
697 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
698 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
699 $classes[] = 'mw-history-line-updated';
700 }
701
702 $tools = [];
703
704 # Rollback and undo links
705 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
706 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
707 // Get a rollback link without the brackets
708 $rollbackLink = Linker::generateRollback(
709 $rev,
710 $this->getContext(),
711 [ 'verify', 'noBrackets' ]
712 );
713 if ( $rollbackLink ) {
714 $this->preventClickjacking();
715 $tools[] = $rollbackLink;
716 }
717 }
718
719 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
720 && !$prevRev->isDeleted( Revision::DELETED_TEXT )
721 ) {
722 # Create undo tooltip for the first (=latest) line only
723 $undoTooltip = $latest
724 ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
725 : [];
726 $undolink = Linker::linkKnown(
727 $this->getTitle(),
728 $this->msg( 'editundo' )->escaped(),
729 $undoTooltip,
730 [
731 'action' => 'edit',
732 'undoafter' => $prevRev->getId(),
733 'undo' => $rev->getId()
734 ]
735 );
736 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
737 }
738 }
739 // Allow extension to add their own links here
740 Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
741
742 if ( $tools ) {
743 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
744 }
745
746 # Tags
747 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
748 $row->ts_tags,
749 'history',
750 $this->getContext()
751 );
752 $classes = array_merge( $classes, $newClasses );
753 if ( $tagSummary !== '' ) {
754 $s2 .= " $tagSummary";
755 }
756
757 # Include separator between character difference and following text
758 if ( $s2 !== '' ) {
759 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
760 }
761
762 Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
763
764 $attribs = [];
765 if ( $classes ) {
766 $attribs['class'] = implode( ' ', $classes );
767 }
768
769 return Xml::tags( 'li', $attribs, $s ) . "\n";
770 }
771
772 /**
773 * Create a link to view this revision of the page
774 *
775 * @param Revision $rev
776 * @return string
777 */
778 function revLink( $rev ) {
779 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
780 $date = htmlspecialchars( $date );
781 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
782 $link = Linker::linkKnown(
783 $this->getTitle(),
784 $date,
785 [ 'class' => 'mw-changeslist-date' ],
786 [ 'oldid' => $rev->getId() ]
787 );
788 } else {
789 $link = $date;
790 }
791 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
792 $link = "<span class=\"history-deleted\">$link</span>";
793 }
794
795 return $link;
796 }
797
798 /**
799 * Create a diff-to-current link for this revision for this page
800 *
801 * @param Revision $rev
802 * @param bool $latest This is the latest revision of the page?
803 * @return string
804 */
805 function curLink( $rev, $latest ) {
806 $cur = $this->historyPage->message['cur'];
807 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
808 return $cur;
809 } else {
810 return Linker::linkKnown(
811 $this->getTitle(),
812 $cur,
813 [],
814 [
815 'diff' => $this->getWikiPage()->getLatest(),
816 'oldid' => $rev->getId()
817 ]
818 );
819 }
820 }
821
822 /**
823 * Create a diff-to-previous link for this revision for this page.
824 *
825 * @param Revision $prevRev The revision being displayed
826 * @param stdClass|string|null $next The next revision in list (that is
827 * the previous one in chronological order).
828 * May either be a row, "unknown" or null.
829 * @return string
830 */
831 function lastLink( $prevRev, $next ) {
832 $last = $this->historyPage->message['last'];
833
834 if ( $next === null ) {
835 # Probably no next row
836 return $last;
837 }
838
839 if ( $next === 'unknown' ) {
840 # Next row probably exists but is unknown, use an oldid=prev link
841 return Linker::linkKnown(
842 $this->getTitle(),
843 $last,
844 [],
845 [
846 'diff' => $prevRev->getId(),
847 'oldid' => 'prev'
848 ]
849 );
850 }
851
852 $nextRev = new Revision( $next );
853
854 if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
855 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
856 ) {
857 return $last;
858 }
859
860 return Linker::linkKnown(
861 $this->getTitle(),
862 $last,
863 [],
864 [
865 'diff' => $prevRev->getId(),
866 'oldid' => $next->rev_id
867 ]
868 );
869 }
870
871 /**
872 * Create radio buttons for page history
873 *
874 * @param Revision $rev
875 * @param bool $firstInList Is this version the first one?
876 *
877 * @return string HTML output for the radio buttons
878 */
879 function diffButtons( $rev, $firstInList ) {
880 if ( $this->getNumRows() > 1 ) {
881 $id = $rev->getId();
882 $radio = [ 'type' => 'radio', 'value' => $id ];
883 /** @todo Move title texts to javascript */
884 if ( $firstInList ) {
885 $first = Xml::element( 'input',
886 array_merge( $radio, [
887 'style' => 'visibility:hidden',
888 'name' => 'oldid',
889 'id' => 'mw-oldid-null' ] )
890 );
891 $checkmark = [ 'checked' => 'checked' ];
892 } else {
893 # Check visibility of old revisions
894 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
895 $radio['disabled'] = 'disabled';
896 $checkmark = []; // We will check the next possible one
897 } elseif ( !$this->oldIdChecked ) {
898 $checkmark = [ 'checked' => 'checked' ];
899 $this->oldIdChecked = $id;
900 } else {
901 $checkmark = [];
902 }
903 $first = Xml::element( 'input',
904 array_merge( $radio, $checkmark, [
905 'name' => 'oldid',
906 'id' => "mw-oldid-$id" ] ) );
907 $checkmark = [];
908 }
909 $second = Xml::element( 'input',
910 array_merge( $radio, $checkmark, [
911 'name' => 'diff',
912 'id' => "mw-diff-$id" ] ) );
913
914 return $first . $second;
915 } else {
916 return '';
917 }
918 }
919
920 /**
921 * This is called if a write operation is possible from the generated HTML
922 * @param bool $enable
923 */
924 function preventClickjacking( $enable = true ) {
925 $this->preventClickjacking = $enable;
926 }
927
928 /**
929 * Get the "prevent clickjacking" flag
930 * @return bool
931 */
932 function getPreventClickjacking() {
933 return $this->preventClickjacking;
934 }
935
936 }