Move construction of highlight divs to backend
[lhc/web/wiklou.git] / includes / changes / ChangesList.php
1 <?php
2 /**
3 * Base class for all changes lists.
4 *
5 * The class is used for formatting recent changes, related changes and watchlist.
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 */
24 use MediaWiki\Linker\LinkRenderer;
25 use MediaWiki\MediaWikiServices;
26 use Wikimedia\Rdbms\ResultWrapper;
27
28 class ChangesList extends ContextSource {
29 const CSS_CLASS_PREFIX = 'mw-changeslist-';
30
31 /**
32 * @var Skin
33 */
34 public $skin;
35
36 protected $watchlist = false;
37 protected $lastdate;
38 protected $message;
39 protected $rc_cache;
40 protected $rcCacheIndex;
41 protected $rclistOpen;
42 protected $rcMoveIndex;
43
44 /** @var callable */
45 protected $changeLinePrefixer;
46
47 /** @var BagOStuff */
48 protected $watchMsgCache;
49
50 /**
51 * @var LinkRenderer
52 */
53 protected $linkRenderer;
54
55 /**
56 * @var array
57 */
58 protected $filterGroups;
59
60 /**
61 * Changeslist constructor
62 *
63 * @param Skin|IContextSource $obj
64 * @param array $filterGroups Array of ChangesListFilterGroup objects (currently optional)
65 */
66 public function __construct( $obj, array $filterGroups = [] ) {
67 if ( $obj instanceof IContextSource ) {
68 $this->setContext( $obj );
69 $this->skin = $obj->getSkin();
70 } else {
71 $this->setContext( $obj->getContext() );
72 $this->skin = $obj;
73 }
74 $this->preCacheMessages();
75 $this->watchMsgCache = new HashBagOStuff( [ 'maxKeys' => 50 ] );
76 $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
77 $this->filterGroups = $filterGroups;
78 }
79
80 /**
81 * Fetch an appropriate changes list class for the specified context
82 * Some users might want to use an enhanced list format, for instance
83 *
84 * @param IContextSource $context
85 * @param array $groups Array of ChangesListFilterGroup objects (currently optional)
86 * @return ChangesList
87 */
88 public static function newFromContext( IContextSource $context, array $groups = [] ) {
89 $user = $context->getUser();
90 $sk = $context->getSkin();
91 $list = null;
92 if ( Hooks::run( 'FetchChangesList', [ $user, &$sk, &$list ] ) ) {
93 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
94
95 return $new ?
96 new EnhancedChangesList( $context, $groups ) :
97 new OldChangesList( $context, $groups );
98 } else {
99 return $list;
100 }
101 }
102
103 /**
104 * Format a line
105 *
106 * @since 1.27
107 *
108 * @param RecentChange &$rc Passed by reference
109 * @param bool $watched (default false)
110 * @param int $linenumber (default null)
111 *
112 * @return string|bool
113 */
114 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
115 throw new RuntimeException( 'recentChangesLine should be implemented' );
116 }
117
118 /**
119 * Get the container for highlights that are used in the new StructuredFilters
120 * system
121 *
122 * @return string HTML structure of the highlight container div
123 */
124 protected function getHighlightsContainerDiv() {
125 $highlightColorDivs = '';
126 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
127 $highlightColorDivs .= Html::rawElement(
128 'div',
129 [
130 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
131 'data-color' => $color
132 ]
133 );
134 }
135
136 return Html::rawElement(
137 'div',
138 [ 'class' => 'mw-rcfilters-ui-highlights' ],
139 $highlightColorDivs
140 );
141 }
142
143 /**
144 * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
145 * @param bool $value
146 */
147 public function setWatchlistDivs( $value = true ) {
148 $this->watchlist = $value;
149 }
150
151 /**
152 * @return bool True when setWatchlistDivs has been called
153 * @since 1.23
154 */
155 public function isWatchlist() {
156 return (bool)$this->watchlist;
157 }
158
159 /**
160 * As we use the same small set of messages in various methods and that
161 * they are called often, we call them once and save them in $this->message
162 */
163 private function preCacheMessages() {
164 if ( !isset( $this->message ) ) {
165 foreach ( [
166 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
167 'semicolon-separator', 'pipe-separator' ] as $msg
168 ) {
169 $this->message[$msg] = $this->msg( $msg )->escaped();
170 }
171 }
172 }
173
174 /**
175 * Returns the appropriate flags for new page, minor change and patrolling
176 * @param array $flags Associative array of 'flag' => Bool
177 * @param string $nothing To use for empty space
178 * @return string
179 */
180 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
181 $f = '';
182 foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
183 $f .= isset( $flags[$flag] ) && $flags[$flag]
184 ? self::flag( $flag, $this->getContext() )
185 : $nothing;
186 }
187
188 return $f;
189 }
190
191 /**
192 * Get an array of default HTML class attributes for the change.
193 *
194 * @param RecentChange|RCCacheEntry $rc
195 * @param string|bool $watched Optionally timestamp for adding watched class
196 *
197 * @return array of classes
198 */
199 protected function getHTMLClasses( $rc, $watched ) {
200 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
201 $logType = $rc->mAttribs['rc_log_type'];
202
203 if ( $logType ) {
204 $classes[] = self::CSS_CLASS_PREFIX . 'log';
205 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
206 } else {
207 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
208 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
209 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
210 }
211 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
212 $rc->mAttribs['rc_namespace'] );
213
214 // Indicate watched status on the line to allow for more
215 // comprehensive styling.
216 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
217 ? self::CSS_CLASS_PREFIX . 'line-watched'
218 : self::CSS_CLASS_PREFIX . 'line-not-watched';
219
220 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
221
222 return $classes;
223 }
224
225 /**
226 * Get an array of CSS classes attributed to filters for this row
227 *
228 * @param RecentChange $rc
229 * @return array Array of CSS classes
230 */
231 protected function getHTMLClassesForFilters( $rc ) {
232 $classes = [];
233
234 if ( $this->filterGroups !== null ) {
235 foreach ( $this->filterGroups as $filterGroup ) {
236 foreach ( $filterGroup->getFilters() as $filter ) {
237 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
238 }
239 }
240 }
241
242 return $classes;
243 }
244
245 /**
246 * Make an "<abbr>" element for a given change flag. The flag indicating a new page, minor edit,
247 * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
248 *
249 * @param string $flag One key of $wgRecentChangesFlags
250 * @param IContextSource $context
251 * @return string HTML
252 */
253 public static function flag( $flag, IContextSource $context = null ) {
254 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
255 static $flagInfos = null;
256
257 if ( is_null( $flagInfos ) ) {
258 global $wgRecentChangesFlags;
259 $flagInfos = [];
260 foreach ( $wgRecentChangesFlags as $key => $value ) {
261 $flagInfos[$key]['letter'] = $value['letter'];
262 $flagInfos[$key]['title'] = $value['title'];
263 // Allow customized class name, fall back to flag name
264 $flagInfos[$key]['class'] = $value['class'] ?? $key;
265 }
266 }
267
268 $context = $context ?: RequestContext::getMain();
269
270 // Inconsistent naming, kepted for b/c
271 if ( isset( $map[$flag] ) ) {
272 $flag = $map[$flag];
273 }
274
275 $info = $flagInfos[$flag];
276 return Html::element( 'abbr', [
277 'class' => $info['class'],
278 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
279 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
280 }
281
282 /**
283 * Returns text for the start of the tabular part of RC
284 * @return string
285 */
286 public function beginRecentChangesList() {
287 $this->rc_cache = [];
288 $this->rcMoveIndex = 0;
289 $this->rcCacheIndex = 0;
290 $this->lastdate = '';
291 $this->rclistOpen = false;
292 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
293
294 return '<div class="mw-changeslist">';
295 }
296
297 /**
298 * @param ResultWrapper|array $rows
299 */
300 public function initChangesListRows( $rows ) {
301 Hooks::run( 'ChangesListInitRows', [ $this, $rows ] );
302 }
303
304 /**
305 * Show formatted char difference
306 *
307 * Needs the css module 'mediawiki.special.changeslist' to style output
308 *
309 * @param int $old Number of bytes
310 * @param int $new Number of bytes
311 * @param IContextSource $context
312 * @return string
313 */
314 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
315 if ( !$context ) {
316 $context = RequestContext::getMain();
317 }
318
319 $new = (int)$new;
320 $old = (int)$old;
321 $szdiff = $new - $old;
322
323 $lang = $context->getLanguage();
324 $config = $context->getConfig();
325 $code = $lang->getCode();
326 static $fastCharDiff = [];
327 if ( !isset( $fastCharDiff[$code] ) ) {
328 $fastCharDiff[$code] = $config->get( 'MiserMode' )
329 || $context->msg( 'rc-change-size' )->plain() === '$1';
330 }
331
332 $formattedSize = $lang->formatNum( $szdiff );
333
334 if ( !$fastCharDiff[$code] ) {
335 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
336 }
337
338 if ( abs( $szdiff ) > abs( $config->get( 'RCChangedSizeThreshold' ) ) ) {
339 $tag = 'strong';
340 } else {
341 $tag = 'span';
342 }
343
344 if ( $szdiff === 0 ) {
345 $formattedSizeClass = 'mw-plusminus-null';
346 } elseif ( $szdiff > 0 ) {
347 $formattedSize = '+' . $formattedSize;
348 $formattedSizeClass = 'mw-plusminus-pos';
349 } else {
350 $formattedSizeClass = 'mw-plusminus-neg';
351 }
352
353 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
354
355 return Html::element( $tag,
356 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
357 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
358 }
359
360 /**
361 * Format the character difference of one or several changes.
362 *
363 * @param RecentChange $old
364 * @param RecentChange $new Last change to use, if not provided, $old will be used
365 * @return string HTML fragment
366 */
367 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
368 $oldlen = $old->mAttribs['rc_old_len'];
369
370 if ( $new ) {
371 $newlen = $new->mAttribs['rc_new_len'];
372 } else {
373 $newlen = $old->mAttribs['rc_new_len'];
374 }
375
376 if ( $oldlen === null || $newlen === null ) {
377 return '';
378 }
379
380 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
381 }
382
383 /**
384 * Returns text for the end of RC
385 * @return string
386 */
387 public function endRecentChangesList() {
388 $out = $this->rclistOpen ? "</ul>\n" : '';
389 $out .= '</div>';
390
391 return $out;
392 }
393
394 /**
395 * @param string &$s HTML to update
396 * @param mixed $rc_timestamp
397 */
398 public function insertDateHeader( &$s, $rc_timestamp ) {
399 # Make date header if necessary
400 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
401 if ( $date != $this->lastdate ) {
402 if ( $this->lastdate != '' ) {
403 $s .= "</ul>\n";
404 }
405 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
406 $this->lastdate = $date;
407 $this->rclistOpen = true;
408 }
409 }
410
411 /**
412 * @param string &$s HTML to update
413 * @param Title $title
414 * @param string $logtype
415 */
416 public function insertLog( &$s, $title, $logtype ) {
417 $page = new LogPage( $logtype );
418 $logname = $page->getName()->setContext( $this->getContext() )->text();
419 $s .= $this->msg( 'parentheses' )->rawParams(
420 $this->linkRenderer->makeKnownLink( $title, $logname )
421 )->escaped();
422 }
423
424 /**
425 * @param string &$s HTML to update
426 * @param RecentChange &$rc
427 * @param bool|null $unpatrolled Unused variable, since 1.27.
428 */
429 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
430 # Diff link
431 if (
432 $rc->mAttribs['rc_type'] == RC_NEW ||
433 $rc->mAttribs['rc_type'] == RC_LOG ||
434 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
435 ) {
436 $diffLink = $this->message['diff'];
437 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
438 $diffLink = $this->message['diff'];
439 } else {
440 $query = [
441 'curid' => $rc->mAttribs['rc_cur_id'],
442 'diff' => $rc->mAttribs['rc_this_oldid'],
443 'oldid' => $rc->mAttribs['rc_last_oldid']
444 ];
445
446 $diffLink = $this->linkRenderer->makeKnownLink(
447 $rc->getTitle(),
448 new HtmlArmor( $this->message['diff'] ),
449 [ 'class' => 'mw-changeslist-diff' ],
450 $query
451 );
452 }
453 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
454 $diffhist = $diffLink . $this->message['pipe-separator'] . $this->message['hist'];
455 } else {
456 $diffhist = $diffLink . $this->message['pipe-separator'];
457 # History link
458 $diffhist .= $this->linkRenderer->makeKnownLink(
459 $rc->getTitle(),
460 new HtmlArmor( $this->message['hist'] ),
461 [ 'class' => 'mw-changeslist-history' ],
462 [
463 'curid' => $rc->mAttribs['rc_cur_id'],
464 'action' => 'history'
465 ]
466 );
467 }
468
469 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
470 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() .
471 ' <span class="mw-changeslist-separator">. .</span> ';
472 }
473
474 /**
475 * @param string &$s Article link will be appended to this string, in place.
476 * @param RecentChange $rc
477 * @param bool $unpatrolled
478 * @param bool $watched
479 * @deprecated since 1.27, use getArticleLink instead.
480 */
481 public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
482 $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
483 }
484
485 /**
486 * @param RecentChange &$rc
487 * @param bool $unpatrolled
488 * @param bool $watched
489 * @return string HTML
490 * @since 1.26
491 */
492 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
493 $params = [];
494 if ( $rc->getTitle()->isRedirect() ) {
495 $params = [ 'redirect' => 'no' ];
496 }
497
498 $articlelink = $this->linkRenderer->makeLink(
499 $rc->getTitle(),
500 null,
501 [ 'class' => 'mw-changeslist-title' ],
502 $params
503 );
504 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
505 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
506 }
507 # To allow for boldening pages watched by this user
508 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
509 # RTL/LTR marker
510 $articlelink .= $this->getLanguage()->getDirMark();
511
512 # TODO: Deprecate the $s argument, it seems happily unused.
513 $s = '';
514 # Avoid PHP 7.1 warning from passing $this by reference
515 $changesList = $this;
516 Hooks::run( 'ChangesListInsertArticleLink',
517 [ &$changesList, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
518
519 return "{$s} {$articlelink}";
520 }
521
522 /**
523 * Get the timestamp from $rc formatted with current user's settings
524 * and a separator
525 *
526 * @param RecentChange $rc
527 * @return string HTML fragment
528 */
529 public function getTimestamp( $rc ) {
530 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
531 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
532 $this->getLanguage()->userTime(
533 $rc->mAttribs['rc_timestamp'],
534 $this->getUser()
535 ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
536 }
537
538 /**
539 * Insert time timestamp string from $rc into $s
540 *
541 * @param string &$s HTML to update
542 * @param RecentChange $rc
543 */
544 public function insertTimestamp( &$s, $rc ) {
545 $s .= $this->getTimestamp( $rc );
546 }
547
548 /**
549 * Insert links to user page, user talk page and eventually a blocking link
550 *
551 * @param string &$s HTML to update
552 * @param RecentChange &$rc
553 */
554 public function insertUserRelatedLinks( &$s, &$rc ) {
555 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
556 $s .= ' <span class="history-deleted">' .
557 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
558 } else {
559 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
560 $rc->mAttribs['rc_user_text'] );
561 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
562 }
563 }
564
565 /**
566 * Insert a formatted action
567 *
568 * @param RecentChange $rc
569 * @return string
570 */
571 public function insertLogEntry( $rc ) {
572 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
573 $formatter->setContext( $this->getContext() );
574 $formatter->setShowUserToolLinks( true );
575 $mark = $this->getLanguage()->getDirMark();
576
577 return $formatter->getActionText() . " $mark" . $formatter->getComment();
578 }
579
580 /**
581 * Insert a formatted comment
582 * @param RecentChange $rc
583 * @return string
584 */
585 public function insertComment( $rc ) {
586 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
587 return ' <span class="history-deleted">' .
588 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
589 } else {
590 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
591 }
592 }
593
594 /**
595 * Returns the string which indicates the number of watching users
596 * @param int $count Number of user watching a page
597 * @return string
598 */
599 protected function numberofWatchingusers( $count ) {
600 if ( $count <= 0 ) {
601 return '';
602 }
603 $cache = $this->watchMsgCache;
604 return $cache->getWithSetCallback(
605 $cache->makeKey( 'watching-users-msg', $count ),
606 $cache::TTL_INDEFINITE,
607 function () use ( $count ) {
608 return $this->msg( 'number_of_watching_users_RCview' )
609 ->numParams( $count )->escaped();
610 }
611 );
612 }
613
614 /**
615 * Determine if said field of a revision is hidden
616 * @param RCCacheEntry|RecentChange $rc
617 * @param int $field One of DELETED_* bitfield constants
618 * @return bool
619 */
620 public static function isDeleted( $rc, $field ) {
621 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
622 }
623
624 /**
625 * Determine if the current user is allowed to view a particular
626 * field of this revision, if it's marked as deleted.
627 * @param RCCacheEntry|RecentChange $rc
628 * @param int $field
629 * @param User $user User object to check, or null to use $wgUser
630 * @return bool
631 */
632 public static function userCan( $rc, $field, User $user = null ) {
633 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
634 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
635 } else {
636 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
637 }
638 }
639
640 /**
641 * @param string $link
642 * @param bool $watched
643 * @return string
644 */
645 protected function maybeWatchedLink( $link, $watched = false ) {
646 if ( $watched ) {
647 return '<strong class="mw-watched">' . $link . '</strong>';
648 } else {
649 return '<span class="mw-rc-unwatched">' . $link . '</span>';
650 }
651 }
652
653 /** Inserts a rollback link
654 *
655 * @param string &$s
656 * @param RecentChange &$rc
657 */
658 public function insertRollback( &$s, &$rc ) {
659 if ( $rc->mAttribs['rc_type'] == RC_EDIT
660 && $rc->mAttribs['rc_this_oldid']
661 && $rc->mAttribs['rc_cur_id']
662 ) {
663 $page = $rc->getTitle();
664 /** Check for rollback and edit permissions, disallow special pages, and only
665 * show a link on the top-most revision */
666 if ( $this->getUser()->isAllowed( 'rollback' )
667 && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']
668 ) {
669 $rev = new Revision( [
670 'title' => $page,
671 'id' => $rc->mAttribs['rc_this_oldid'],
672 'user' => $rc->mAttribs['rc_user'],
673 'user_text' => $rc->mAttribs['rc_user_text'],
674 'actor' => $rc->mAttribs['rc_actor'] ?? null,
675 'deleted' => $rc->mAttribs['rc_deleted']
676 ] );
677 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
678 }
679 }
680 }
681
682 /**
683 * @param RecentChange $rc
684 * @return string
685 * @since 1.26
686 */
687 public function getRollback( RecentChange $rc ) {
688 $s = '';
689 $this->insertRollback( $s, $rc );
690 return $s;
691 }
692
693 /**
694 * @param string &$s
695 * @param RecentChange &$rc
696 * @param array &$classes
697 */
698 public function insertTags( &$s, &$rc, &$classes ) {
699 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
700 return;
701 }
702
703 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
704 $rc->mAttribs['ts_tags'],
705 'changeslist',
706 $this->getContext()
707 );
708 $classes = array_merge( $classes, $newClasses );
709 $s .= ' ' . $tagSummary;
710 }
711
712 /**
713 * @param RecentChange $rc
714 * @param array &$classes
715 * @return string
716 * @since 1.26
717 */
718 public function getTags( RecentChange $rc, array &$classes ) {
719 $s = '';
720 $this->insertTags( $s, $rc, $classes );
721 return $s;
722 }
723
724 public function insertExtra( &$s, &$rc, &$classes ) {
725 // Empty, used for subclasses to add anything special.
726 }
727
728 protected function showAsUnpatrolled( RecentChange $rc ) {
729 return self::isUnpatrolled( $rc, $this->getUser() );
730 }
731
732 /**
733 * @param object|RecentChange $rc Database row from recentchanges or a RecentChange object
734 * @param User $user
735 * @return bool
736 */
737 public static function isUnpatrolled( $rc, User $user ) {
738 if ( $rc instanceof RecentChange ) {
739 $isPatrolled = $rc->mAttribs['rc_patrolled'];
740 $rcType = $rc->mAttribs['rc_type'];
741 $rcLogType = $rc->mAttribs['rc_log_type'];
742 } else {
743 $isPatrolled = $rc->rc_patrolled;
744 $rcType = $rc->rc_type;
745 $rcLogType = $rc->rc_log_type;
746 }
747
748 if ( !$isPatrolled ) {
749 if ( $user->useRCPatrol() ) {
750 return true;
751 }
752 if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
753 return true;
754 }
755 if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
756 return true;
757 }
758 }
759
760 return false;
761 }
762
763 /**
764 * Determines whether a revision is linked to this change; this may not be the case
765 * when the categorization wasn't done by an edit but a conditional parser function
766 *
767 * @since 1.27
768 *
769 * @param RecentChange|RCCacheEntry $rcObj
770 * @return bool
771 */
772 protected function isCategorizationWithoutRevision( $rcObj ) {
773 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
774 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
775 }
776
777 /**
778 * Get recommended data attributes for a change line.
779 * @param RecentChange $rc
780 * @return string[] attribute name => value
781 */
782 protected function getDataAttributes( RecentChange $rc ) {
783 $attrs = [];
784
785 $type = $rc->getAttribute( 'rc_source' );
786 switch ( $type ) {
787 case RecentChange::SRC_EDIT:
788 case RecentChange::SRC_NEW:
789 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
790 break;
791 case RecentChange::SRC_LOG:
792 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
793 $attrs['data-mw-logaction'] =
794 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
795 break;
796 }
797
798 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
799
800 return $attrs;
801 }
802
803 /**
804 * Sets the callable that generates a change line prefix added to the beginning of each line.
805 *
806 * @param callable $prefixer Callable to run that generates the change line prefix.
807 * Takes three parameters: a RecentChange object, a ChangesList object,
808 * and whether the current entry is a grouped entry.
809 */
810 public function setChangeLinePrefixer( callable $prefixer ) {
811 $this->changeLinePrefixer = $prefixer;
812 }
813 }