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