Merge "Fix order on Special:Contributions when timestamps are identical"
[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 MapCacheLRU */
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 MapCacheLRU( 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|null $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
212 // Indicate watched status on the line to allow for more
213 // comprehensive styling.
214 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
215 ? self::CSS_CLASS_PREFIX . 'line-watched'
216 : self::CSS_CLASS_PREFIX . 'line-not-watched';
217
218 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
219
220 return $classes;
221 }
222
223 /**
224 * Get an array of CSS classes attributed to filters for this row. Used for highlighting
225 * in the front-end.
226 *
227 * @param RecentChange $rc
228 * @return array Array of CSS classes
229 */
230 protected function getHTMLClassesForFilters( $rc ) {
231 $classes = [];
232
233 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
234 $rc->mAttribs['rc_namespace'] );
235
236 if ( $this->filterGroups !== null ) {
237 foreach ( $this->filterGroups as $filterGroup ) {
238 foreach ( $filterGroup->getFilters() as $filter ) {
239 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
240 }
241 }
242 }
243
244 return $classes;
245 }
246
247 /**
248 * Make an "<abbr>" element for a given change flag. The flag indicating a new page, minor edit,
249 * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
250 *
251 * @param string $flag One key of $wgRecentChangesFlags
252 * @param IContextSource|null $context
253 * @return string HTML
254 */
255 public static function flag( $flag, IContextSource $context = null ) {
256 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
257 static $flagInfos = null;
258
259 if ( is_null( $flagInfos ) ) {
260 global $wgRecentChangesFlags;
261 $flagInfos = [];
262 foreach ( $wgRecentChangesFlags as $key => $value ) {
263 $flagInfos[$key]['letter'] = $value['letter'];
264 $flagInfos[$key]['title'] = $value['title'];
265 // Allow customized class name, fall back to flag name
266 $flagInfos[$key]['class'] = $value['class'] ?? $key;
267 }
268 }
269
270 $context = $context ?: RequestContext::getMain();
271
272 // Inconsistent naming, kepted for b/c
273 if ( isset( $map[$flag] ) ) {
274 $flag = $map[$flag];
275 }
276
277 $info = $flagInfos[$flag];
278 return Html::element( 'abbr', [
279 'class' => $info['class'],
280 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
281 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
282 }
283
284 /**
285 * Returns text for the start of the tabular part of RC
286 * @return string
287 */
288 public function beginRecentChangesList() {
289 $this->rc_cache = [];
290 $this->rcMoveIndex = 0;
291 $this->rcCacheIndex = 0;
292 $this->lastdate = '';
293 $this->rclistOpen = false;
294 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
295
296 return '<div class="mw-changeslist">';
297 }
298
299 /**
300 * @param ResultWrapper|array $rows
301 */
302 public function initChangesListRows( $rows ) {
303 Hooks::run( 'ChangesListInitRows', [ $this, $rows ] );
304 }
305
306 /**
307 * Show formatted char difference
308 *
309 * Needs the css module 'mediawiki.special.changeslist' to style output
310 *
311 * @param int $old Number of bytes
312 * @param int $new Number of bytes
313 * @param IContextSource|null $context
314 * @return string
315 */
316 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
317 if ( !$context ) {
318 $context = RequestContext::getMain();
319 }
320
321 $new = (int)$new;
322 $old = (int)$old;
323 $szdiff = $new - $old;
324
325 $lang = $context->getLanguage();
326 $config = $context->getConfig();
327 $code = $lang->getCode();
328 static $fastCharDiff = [];
329 if ( !isset( $fastCharDiff[$code] ) ) {
330 $fastCharDiff[$code] = $config->get( 'MiserMode' )
331 || $context->msg( 'rc-change-size' )->plain() === '$1';
332 }
333
334 $formattedSize = $lang->formatNum( $szdiff );
335
336 if ( !$fastCharDiff[$code] ) {
337 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
338 }
339
340 if ( abs( $szdiff ) > abs( $config->get( 'RCChangedSizeThreshold' ) ) ) {
341 $tag = 'strong';
342 } else {
343 $tag = 'span';
344 }
345
346 if ( $szdiff === 0 ) {
347 $formattedSizeClass = 'mw-plusminus-null';
348 } elseif ( $szdiff > 0 ) {
349 $formattedSize = '+' . $formattedSize;
350 $formattedSizeClass = 'mw-plusminus-pos';
351 } else {
352 $formattedSizeClass = 'mw-plusminus-neg';
353 }
354 $formattedSizeClass .= ' mw-diff-bytes';
355
356 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
357
358 return Html::element( $tag,
359 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
360 $formattedSize ) . $lang->getDirMark();
361 }
362
363 /**
364 * Format the character difference of one or several changes.
365 *
366 * @param RecentChange $old
367 * @param RecentChange|null $new Last change to use, if not provided, $old will be used
368 * @return string HTML fragment
369 */
370 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
371 $oldlen = $old->mAttribs['rc_old_len'];
372
373 if ( $new ) {
374 $newlen = $new->mAttribs['rc_new_len'];
375 } else {
376 $newlen = $old->mAttribs['rc_new_len'];
377 }
378
379 if ( $oldlen === null || $newlen === null ) {
380 return '';
381 }
382
383 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
384 }
385
386 /**
387 * Returns text for the end of RC
388 * @return string
389 */
390 public function endRecentChangesList() {
391 $out = $this->rclistOpen ? "</ul>\n" : '';
392 $out .= '</div>';
393
394 return $out;
395 }
396
397 /**
398 * @param string &$s HTML to update
399 * @param mixed $rc_timestamp
400 */
401 public function insertDateHeader( &$s, $rc_timestamp ) {
402 # Make date header if necessary
403 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
404 if ( $date != $this->lastdate ) {
405 if ( $this->lastdate != '' ) {
406 $s .= "</ul>\n";
407 }
408 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
409 $this->lastdate = $date;
410 $this->rclistOpen = true;
411 }
412 }
413
414 /**
415 * @param string &$s HTML to update
416 * @param Title $title
417 * @param string $logtype
418 */
419 public function insertLog( &$s, $title, $logtype ) {
420 $page = new LogPage( $logtype );
421 $logname = $page->getName()->setContext( $this->getContext() )->text();
422 $s .= $this->msg( 'parentheses' )->rawParams(
423 $this->linkRenderer->makeKnownLink( $title, $logname )
424 )->escaped();
425 }
426
427 /**
428 * @param string &$s HTML to update
429 * @param RecentChange &$rc
430 * @param bool|null $unpatrolled Unused variable, since 1.27.
431 */
432 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
433 # Diff link
434 if (
435 $rc->mAttribs['rc_type'] == RC_NEW ||
436 $rc->mAttribs['rc_type'] == RC_LOG ||
437 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
438 ) {
439 $diffLink = $this->message['diff'];
440 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
441 $diffLink = $this->message['diff'];
442 } else {
443 $query = [
444 'curid' => $rc->mAttribs['rc_cur_id'],
445 'diff' => $rc->mAttribs['rc_this_oldid'],
446 'oldid' => $rc->mAttribs['rc_last_oldid']
447 ];
448
449 $diffLink = $this->linkRenderer->makeKnownLink(
450 $rc->getTitle(),
451 new HtmlArmor( $this->message['diff'] ),
452 [ 'class' => 'mw-changeslist-diff' ],
453 $query
454 );
455 }
456 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
457 $histLink = $this->message['hist'];
458 } else {
459 $histLink = $this->linkRenderer->makeKnownLink(
460 $rc->getTitle(),
461 new HtmlArmor( $this->message['hist'] ),
462 [ 'class' => 'mw-changeslist-history' ],
463 [
464 'curid' => $rc->mAttribs['rc_cur_id'],
465 'action' => 'history'
466 ]
467 );
468 }
469
470 $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
471 Html::rawElement( 'span', [], $diffLink ) .
472 Html::rawElement( 'span', [], $histLink )
473 ) .
474 ' <span class="mw-changeslist-separator"></span> ';
475 }
476
477 /**
478 * @param string &$s Article link will be appended to this string, in place.
479 * @param RecentChange $rc
480 * @param bool $unpatrolled
481 * @param bool $watched
482 * @deprecated since 1.27, use getArticleLink instead.
483 */
484 public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
485 $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
486 }
487
488 /**
489 * @param RecentChange &$rc
490 * @param bool $unpatrolled
491 * @param bool $watched
492 * @return string HTML
493 * @since 1.26
494 */
495 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
496 $params = [];
497 if ( $rc->getTitle()->isRedirect() ) {
498 $params = [ 'redirect' => 'no' ];
499 }
500
501 $articlelink = $this->linkRenderer->makeLink(
502 $rc->getTitle(),
503 null,
504 [ 'class' => 'mw-changeslist-title' ],
505 $params
506 );
507 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
508 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
509 }
510 # To allow for boldening pages watched by this user
511 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
512 # RTL/LTR marker
513 $articlelink .= $this->getLanguage()->getDirMark();
514
515 # TODO: Deprecate the $s argument, it seems happily unused.
516 $s = '';
517 # Avoid PHP 7.1 warning from passing $this by reference
518 $changesList = $this;
519 Hooks::run( 'ChangesListInsertArticleLink',
520 [ &$changesList, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
521
522 return "{$s} {$articlelink}";
523 }
524
525 /**
526 * Get the timestamp from $rc formatted with current user's settings
527 * and a separator
528 *
529 * @param RecentChange $rc
530 * @return string HTML fragment
531 */
532 public function getTimestamp( $rc ) {
533 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
534 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
535 htmlspecialchars( $this->getLanguage()->userTime(
536 $rc->mAttribs['rc_timestamp'],
537 $this->getUser()
538 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
539 }
540
541 /**
542 * Insert time timestamp string from $rc into $s
543 *
544 * @param string &$s HTML to update
545 * @param RecentChange $rc
546 */
547 public function insertTimestamp( &$s, $rc ) {
548 $s .= $this->getTimestamp( $rc );
549 }
550
551 /**
552 * Insert links to user page, user talk page and eventually a blocking link
553 *
554 * @param string &$s HTML to update
555 * @param RecentChange &$rc
556 */
557 public function insertUserRelatedLinks( &$s, &$rc ) {
558 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
559 $s .= ' <span class="history-deleted">' .
560 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
561 } else {
562 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
563 $rc->mAttribs['rc_user_text'] );
564 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
565 }
566 }
567
568 /**
569 * Insert a formatted action
570 *
571 * @param RecentChange $rc
572 * @return string
573 */
574 public function insertLogEntry( $rc ) {
575 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
576 $formatter->setContext( $this->getContext() );
577 $formatter->setShowUserToolLinks( true );
578 $mark = $this->getLanguage()->getDirMark();
579
580 return $formatter->getActionText() . " $mark" . $formatter->getComment();
581 }
582
583 /**
584 * Insert a formatted comment
585 * @param RecentChange $rc
586 * @return string
587 */
588 public function insertComment( $rc ) {
589 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
590 return ' <span class="history-deleted">' .
591 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
592 } else {
593 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
594 }
595 }
596
597 /**
598 * Returns the string which indicates the number of watching users
599 * @param int $count Number of user watching a page
600 * @return string
601 */
602 protected function numberofWatchingusers( $count ) {
603 if ( $count <= 0 ) {
604 return '';
605 }
606
607 return $this->watchMsgCache->getWithSetCallback(
608 "watching-users-msg:$count",
609 function () use ( $count ) {
610 return $this->msg( 'number_of_watching_users_RCview' )
611 ->numParams( $count )->escaped();
612 }
613 );
614 }
615
616 /**
617 * Determine if said field of a revision is hidden
618 * @param RCCacheEntry|RecentChange $rc
619 * @param int $field One of DELETED_* bitfield constants
620 * @return bool
621 */
622 public static function isDeleted( $rc, $field ) {
623 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
624 }
625
626 /**
627 * Determine if the current user is allowed to view a particular
628 * field of this revision, if it's marked as deleted.
629 * @param RCCacheEntry|RecentChange $rc
630 * @param int $field
631 * @param User|null $user User object to check, or null to use $wgUser
632 * @return bool
633 */
634 public static function userCan( $rc, $field, User $user = null ) {
635 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
636 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
637 } else {
638 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
639 }
640 }
641
642 /**
643 * @param string $link
644 * @param bool $watched
645 * @return string
646 */
647 protected function maybeWatchedLink( $link, $watched = false ) {
648 if ( $watched ) {
649 return '<strong class="mw-watched">' . $link . '</strong>';
650 } else {
651 return '<span class="mw-rc-unwatched">' . $link . '</span>';
652 }
653 }
654
655 /**
656 * Insert a rollback link
657 *
658 * @param string &$s
659 * @param RecentChange &$rc
660 */
661 public function insertRollback( &$s, &$rc ) {
662 if ( $rc->mAttribs['rc_type'] == RC_EDIT
663 && $rc->mAttribs['rc_this_oldid']
664 && $rc->mAttribs['rc_cur_id']
665 && $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
666 ) {
667 $title = $rc->getTitle();
668 /** Check for rollback permissions, disallow special pages, and only
669 * show a link on the top-most revision */
670 if ( $title->quickUserCan( 'rollback', $this->getUser() ) ) {
671 $rev = new Revision( [
672 'title' => $title,
673 'id' => $rc->mAttribs['rc_this_oldid'],
674 'user' => $rc->mAttribs['rc_user'],
675 'user_text' => $rc->mAttribs['rc_user_text'],
676 'actor' => $rc->mAttribs['rc_actor'] ?? null,
677 'deleted' => $rc->mAttribs['rc_deleted']
678 ] );
679 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
680 }
681 }
682 }
683
684 /**
685 * @param RecentChange $rc
686 * @return string
687 * @since 1.26
688 */
689 public function getRollback( RecentChange $rc ) {
690 $s = '';
691 $this->insertRollback( $s, $rc );
692 return $s;
693 }
694
695 /**
696 * @param string &$s
697 * @param RecentChange &$rc
698 * @param array &$classes
699 */
700 public function insertTags( &$s, &$rc, &$classes ) {
701 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
702 return;
703 }
704
705 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
706 $rc->mAttribs['ts_tags'],
707 'changeslist',
708 $this->getContext()
709 );
710 $classes = array_merge( $classes, $newClasses );
711 $s .= ' ' . $tagSummary;
712 }
713
714 /**
715 * @param RecentChange $rc
716 * @param array &$classes
717 * @return string
718 * @since 1.26
719 */
720 public function getTags( RecentChange $rc, array &$classes ) {
721 $s = '';
722 $this->insertTags( $s, $rc, $classes );
723 return $s;
724 }
725
726 public function insertExtra( &$s, &$rc, &$classes ) {
727 // Empty, used for subclasses to add anything special.
728 }
729
730 protected function showAsUnpatrolled( RecentChange $rc ) {
731 return self::isUnpatrolled( $rc, $this->getUser() );
732 }
733
734 /**
735 * @param object|RecentChange $rc Database row from recentchanges or a RecentChange object
736 * @param User $user
737 * @return bool
738 */
739 public static function isUnpatrolled( $rc, User $user ) {
740 if ( $rc instanceof RecentChange ) {
741 $isPatrolled = $rc->mAttribs['rc_patrolled'];
742 $rcType = $rc->mAttribs['rc_type'];
743 $rcLogType = $rc->mAttribs['rc_log_type'];
744 } else {
745 $isPatrolled = $rc->rc_patrolled;
746 $rcType = $rc->rc_type;
747 $rcLogType = $rc->rc_log_type;
748 }
749
750 if ( !$isPatrolled ) {
751 if ( $user->useRCPatrol() ) {
752 return true;
753 }
754 if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
755 return true;
756 }
757 if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
758 return true;
759 }
760 }
761
762 return false;
763 }
764
765 /**
766 * Determines whether a revision is linked to this change; this may not be the case
767 * when the categorization wasn't done by an edit but a conditional parser function
768 *
769 * @since 1.27
770 *
771 * @param RecentChange|RCCacheEntry $rcObj
772 * @return bool
773 */
774 protected function isCategorizationWithoutRevision( $rcObj ) {
775 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
776 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
777 }
778
779 /**
780 * Get recommended data attributes for a change line.
781 * @param RecentChange $rc
782 * @return string[] attribute name => value
783 */
784 protected function getDataAttributes( RecentChange $rc ) {
785 $attrs = [];
786
787 $type = $rc->getAttribute( 'rc_source' );
788 switch ( $type ) {
789 case RecentChange::SRC_EDIT:
790 case RecentChange::SRC_NEW:
791 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
792 break;
793 case RecentChange::SRC_LOG:
794 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
795 $attrs['data-mw-logaction'] =
796 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
797 break;
798 }
799
800 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
801
802 return $attrs;
803 }
804
805 /**
806 * Sets the callable that generates a change line prefix added to the beginning of each line.
807 *
808 * @param callable $prefixer Callable to run that generates the change line prefix.
809 * Takes three parameters: a RecentChange object, a ChangesList object,
810 * and whether the current entry is a grouped entry.
811 */
812 public function setChangeLinePrefixer( callable $prefixer ) {
813 $this->changeLinePrefixer = $prefixer;
814 }
815 }