Fix PhanTypeMismatchDeclaredParam
[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|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
355 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
356
357 return Html::element( $tag,
358 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
359 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
360 }
361
362 /**
363 * Format the character difference of one or several changes.
364 *
365 * @param RecentChange $old
366 * @param RecentChange|null $new Last change to use, if not provided, $old will be used
367 * @return string HTML fragment
368 */
369 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
370 $oldlen = $old->mAttribs['rc_old_len'];
371
372 if ( $new ) {
373 $newlen = $new->mAttribs['rc_new_len'];
374 } else {
375 $newlen = $old->mAttribs['rc_new_len'];
376 }
377
378 if ( $oldlen === null || $newlen === null ) {
379 return '';
380 }
381
382 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
383 }
384
385 /**
386 * Returns text for the end of RC
387 * @return string
388 */
389 public function endRecentChangesList() {
390 $out = $this->rclistOpen ? "</ul>\n" : '';
391 $out .= '</div>';
392
393 return $out;
394 }
395
396 /**
397 * @param string &$s HTML to update
398 * @param mixed $rc_timestamp
399 */
400 public function insertDateHeader( &$s, $rc_timestamp ) {
401 # Make date header if necessary
402 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
403 if ( $date != $this->lastdate ) {
404 if ( $this->lastdate != '' ) {
405 $s .= "</ul>\n";
406 }
407 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
408 $this->lastdate = $date;
409 $this->rclistOpen = true;
410 }
411 }
412
413 /**
414 * @param string &$s HTML to update
415 * @param Title $title
416 * @param string $logtype
417 */
418 public function insertLog( &$s, $title, $logtype ) {
419 $page = new LogPage( $logtype );
420 $logname = $page->getName()->setContext( $this->getContext() )->text();
421 $s .= $this->msg( 'parentheses' )->rawParams(
422 $this->linkRenderer->makeKnownLink( $title, $logname )
423 )->escaped();
424 }
425
426 /**
427 * @param string &$s HTML to update
428 * @param RecentChange &$rc
429 * @param bool|null $unpatrolled Unused variable, since 1.27.
430 */
431 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
432 # Diff link
433 if (
434 $rc->mAttribs['rc_type'] == RC_NEW ||
435 $rc->mAttribs['rc_type'] == RC_LOG ||
436 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
437 ) {
438 $diffLink = $this->message['diff'];
439 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
440 $diffLink = $this->message['diff'];
441 } else {
442 $query = [
443 'curid' => $rc->mAttribs['rc_cur_id'],
444 'diff' => $rc->mAttribs['rc_this_oldid'],
445 'oldid' => $rc->mAttribs['rc_last_oldid']
446 ];
447
448 $diffLink = $this->linkRenderer->makeKnownLink(
449 $rc->getTitle(),
450 new HtmlArmor( $this->message['diff'] ),
451 [ 'class' => 'mw-changeslist-diff' ],
452 $query
453 );
454 }
455 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
456 $diffhist = $diffLink . $this->message['pipe-separator'] . $this->message['hist'];
457 } else {
458 $diffhist = $diffLink . $this->message['pipe-separator'];
459 # History link
460 $diffhist .= $this->linkRenderer->makeKnownLink(
461 $rc->getTitle(),
462 new HtmlArmor( $this->message['hist'] ),
463 [ 'class' => 'mw-changeslist-history' ],
464 [
465 'curid' => $rc->mAttribs['rc_cur_id'],
466 'action' => 'history'
467 ]
468 );
469 }
470
471 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
472 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() .
473 ' <span class="mw-changeslist-separator">. .</span> ';
474 }
475
476 /**
477 * @param string &$s Article link will be appended to this string, in place.
478 * @param RecentChange $rc
479 * @param bool $unpatrolled
480 * @param bool $watched
481 * @deprecated since 1.27, use getArticleLink instead.
482 */
483 public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
484 $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
485 }
486
487 /**
488 * @param RecentChange &$rc
489 * @param bool $unpatrolled
490 * @param bool $watched
491 * @return string HTML
492 * @since 1.26
493 */
494 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
495 $params = [];
496 if ( $rc->getTitle()->isRedirect() ) {
497 $params = [ 'redirect' => 'no' ];
498 }
499
500 $articlelink = $this->linkRenderer->makeLink(
501 $rc->getTitle(),
502 null,
503 [ 'class' => 'mw-changeslist-title' ],
504 $params
505 );
506 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
507 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
508 }
509 # To allow for boldening pages watched by this user
510 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
511 # RTL/LTR marker
512 $articlelink .= $this->getLanguage()->getDirMark();
513
514 # TODO: Deprecate the $s argument, it seems happily unused.
515 $s = '';
516 # Avoid PHP 7.1 warning from passing $this by reference
517 $changesList = $this;
518 Hooks::run( 'ChangesListInsertArticleLink',
519 [ &$changesList, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
520
521 return "{$s} {$articlelink}";
522 }
523
524 /**
525 * Get the timestamp from $rc formatted with current user's settings
526 * and a separator
527 *
528 * @param RecentChange $rc
529 * @return string HTML fragment
530 */
531 public function getTimestamp( $rc ) {
532 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
533 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
534 $this->getLanguage()->userTime(
535 $rc->mAttribs['rc_timestamp'],
536 $this->getUser()
537 ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
538 }
539
540 /**
541 * Insert time timestamp string from $rc into $s
542 *
543 * @param string &$s HTML to update
544 * @param RecentChange $rc
545 */
546 public function insertTimestamp( &$s, $rc ) {
547 $s .= $this->getTimestamp( $rc );
548 }
549
550 /**
551 * Insert links to user page, user talk page and eventually a blocking link
552 *
553 * @param string &$s HTML to update
554 * @param RecentChange &$rc
555 */
556 public function insertUserRelatedLinks( &$s, &$rc ) {
557 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
558 $s .= ' <span class="history-deleted">' .
559 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
560 } else {
561 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
562 $rc->mAttribs['rc_user_text'] );
563 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
564 }
565 }
566
567 /**
568 * Insert a formatted action
569 *
570 * @param RecentChange $rc
571 * @return string
572 */
573 public function insertLogEntry( $rc ) {
574 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
575 $formatter->setContext( $this->getContext() );
576 $formatter->setShowUserToolLinks( true );
577 $mark = $this->getLanguage()->getDirMark();
578
579 return $formatter->getActionText() . " $mark" . $formatter->getComment();
580 }
581
582 /**
583 * Insert a formatted comment
584 * @param RecentChange $rc
585 * @return string
586 */
587 public function insertComment( $rc ) {
588 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
589 return ' <span class="history-deleted">' .
590 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
591 } else {
592 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
593 }
594 }
595
596 /**
597 * Returns the string which indicates the number of watching users
598 * @param int $count Number of user watching a page
599 * @return string
600 */
601 protected function numberofWatchingusers( $count ) {
602 if ( $count <= 0 ) {
603 return '';
604 }
605 $cache = $this->watchMsgCache;
606 return $cache->getWithSetCallback(
607 $cache->makeKey( 'watching-users-msg', $count ),
608 $cache::TTL_INDEFINITE,
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 /** Inserts a rollback link
656 *
657 * @param string &$s
658 * @param RecentChange &$rc
659 */
660 public function insertRollback( &$s, &$rc ) {
661 if ( $rc->mAttribs['rc_type'] == RC_EDIT
662 && $rc->mAttribs['rc_this_oldid']
663 && $rc->mAttribs['rc_cur_id']
664 ) {
665 $page = $rc->getTitle();
666 /** Check for rollback and edit permissions, disallow special pages, and only
667 * show a link on the top-most revision */
668 if ( $this->getUser()->isAllowed( 'rollback' )
669 && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']
670 ) {
671 $rev = new Revision( [
672 'title' => $page,
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 }