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