Merge "Make sure database update succeeds from older database versions too."
[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 * @param Skin|IContextSource $obj
62 * @param array $filterGroups Array of ChangesListFilterGroup objects (currently optional)
63 */
64 public function __construct( $obj, array $filterGroups = [] ) {
65 if ( $obj instanceof IContextSource ) {
66 $this->setContext( $obj );
67 $this->skin = $obj->getSkin();
68 } else {
69 $this->setContext( $obj->getContext() );
70 $this->skin = $obj;
71 }
72 $this->preCacheMessages();
73 $this->watchMsgCache = new MapCacheLRU( 50 );
74 $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
75 $this->filterGroups = $filterGroups;
76 }
77
78 /**
79 * Fetch an appropriate changes list class for the specified context
80 * Some users might want to use an enhanced list format, for instance
81 *
82 * @param IContextSource $context
83 * @param array $groups Array of ChangesListFilterGroup objects (currently optional)
84 * @return ChangesList
85 */
86 public static function newFromContext( IContextSource $context, array $groups = [] ) {
87 $user = $context->getUser();
88 $sk = $context->getSkin();
89 $list = null;
90 if ( Hooks::run( 'FetchChangesList', [ $user, &$sk, &$list ] ) ) {
91 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
92
93 return $new ?
94 new EnhancedChangesList( $context, $groups ) :
95 new OldChangesList( $context, $groups );
96 } else {
97 return $list;
98 }
99 }
100
101 /**
102 * Format a line
103 *
104 * @since 1.27
105 *
106 * @param RecentChange &$rc Passed by reference
107 * @param bool $watched (default false)
108 * @param int|null $linenumber (default null)
109 *
110 * @return string|bool
111 */
112 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
113 throw new RuntimeException( 'recentChangesLine should be implemented' );
114 }
115
116 /**
117 * Get the container for highlights that are used in the new StructuredFilters
118 * system
119 *
120 * @return string HTML structure of the highlight container div
121 */
122 protected function getHighlightsContainerDiv() {
123 $highlightColorDivs = '';
124 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
125 $highlightColorDivs .= Html::rawElement(
126 'div',
127 [
128 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
129 'data-color' => $color
130 ]
131 );
132 }
133
134 return Html::rawElement(
135 'div',
136 [ 'class' => 'mw-rcfilters-ui-highlights' ],
137 $highlightColorDivs
138 );
139 }
140
141 /**
142 * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
143 * @param bool $value
144 */
145 public function setWatchlistDivs( $value = true ) {
146 $this->watchlist = $value;
147 }
148
149 /**
150 * @return bool True when setWatchlistDivs has been called
151 * @since 1.23
152 */
153 public function isWatchlist() {
154 return (bool)$this->watchlist;
155 }
156
157 /**
158 * As we use the same small set of messages in various methods and that
159 * they are called often, we call them once and save them in $this->message
160 */
161 private function preCacheMessages() {
162 if ( !isset( $this->message ) ) {
163 foreach ( [
164 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
165 'semicolon-separator', 'pipe-separator' ] as $msg
166 ) {
167 $this->message[$msg] = $this->msg( $msg )->escaped();
168 }
169 }
170 }
171
172 /**
173 * Returns the appropriate flags for new page, minor change and patrolling
174 * @param array $flags Associative array of 'flag' => Bool
175 * @param string $nothing To use for empty space
176 * @return string
177 */
178 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
179 $f = '';
180 foreach ( array_keys( $this->getConfig()->get( 'RecentChangesFlags' ) ) as $flag ) {
181 $f .= isset( $flags[$flag] ) && $flags[$flag]
182 ? self::flag( $flag, $this->getContext() )
183 : $nothing;
184 }
185
186 return $f;
187 }
188
189 /**
190 * Get an array of default HTML class attributes for the change.
191 *
192 * @param RecentChange|RCCacheEntry $rc
193 * @param string|bool $watched Optionally timestamp for adding watched class
194 *
195 * @return array of classes
196 */
197 protected function getHTMLClasses( $rc, $watched ) {
198 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
199 $logType = $rc->mAttribs['rc_log_type'];
200
201 if ( $logType ) {
202 $classes[] = self::CSS_CLASS_PREFIX . 'log';
203 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
204 } else {
205 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
206 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
207 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
208 }
209
210 // Indicate watched status on the line to allow for more
211 // comprehensive styling.
212 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
213 ? self::CSS_CLASS_PREFIX . 'line-watched'
214 : self::CSS_CLASS_PREFIX . 'line-not-watched';
215
216 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
217
218 return $classes;
219 }
220
221 /**
222 * Get an array of CSS classes attributed to filters for this row. Used for highlighting
223 * in the front-end.
224 *
225 * @param RecentChange $rc
226 * @return array Array of CSS classes
227 */
228 protected function getHTMLClassesForFilters( $rc ) {
229 $classes = [];
230
231 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
232 $rc->mAttribs['rc_namespace'] );
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|null $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|null $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 $formattedSizeClass .= ' mw-diff-bytes';
353
354 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
355
356 return Html::element( $tag,
357 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
358 $formattedSize ) . $lang->getDirMark();
359 }
360
361 /**
362 * Format the character difference of one or several changes.
363 *
364 * @param RecentChange $old
365 * @param RecentChange|null $new Last change to use, if not provided, $old will be used
366 * @return string HTML fragment
367 */
368 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
369 $oldlen = $old->mAttribs['rc_old_len'];
370
371 if ( $new ) {
372 $newlen = $new->mAttribs['rc_new_len'];
373 } else {
374 $newlen = $old->mAttribs['rc_new_len'];
375 }
376
377 if ( $oldlen === null || $newlen === null ) {
378 return '';
379 }
380
381 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
382 }
383
384 /**
385 * Returns text for the end of RC
386 * @return string
387 */
388 public function endRecentChangesList() {
389 $out = $this->rclistOpen ? "</ul>\n" : '';
390 $out .= '</div>';
391
392 return $out;
393 }
394
395 /**
396 * @param string &$s HTML to update
397 * @param mixed $rc_timestamp
398 */
399 public function insertDateHeader( &$s, $rc_timestamp ) {
400 # Make date header if necessary
401 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
402 if ( $date != $this->lastdate ) {
403 if ( $this->lastdate != '' ) {
404 $s .= "</ul>\n";
405 }
406 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
407 $this->lastdate = $date;
408 $this->rclistOpen = true;
409 }
410 }
411
412 /**
413 * @param string &$s HTML to update
414 * @param Title $title
415 * @param string $logtype
416 */
417 public function insertLog( &$s, $title, $logtype ) {
418 $page = new LogPage( $logtype );
419 $logname = $page->getName()->setContext( $this->getContext() )->text();
420 $s .= $this->msg( 'parentheses' )->rawParams(
421 $this->linkRenderer->makeKnownLink( $title, $logname )
422 )->escaped();
423 }
424
425 /**
426 * @param string &$s HTML to update
427 * @param RecentChange &$rc
428 * @param bool|null $unpatrolled Unused variable, since 1.27.
429 */
430 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
431 # Diff link
432 if (
433 $rc->mAttribs['rc_type'] == RC_NEW ||
434 $rc->mAttribs['rc_type'] == RC_LOG ||
435 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
436 ) {
437 $diffLink = $this->message['diff'];
438 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
439 $diffLink = $this->message['diff'];
440 } else {
441 $query = [
442 'curid' => $rc->mAttribs['rc_cur_id'],
443 'diff' => $rc->mAttribs['rc_this_oldid'],
444 'oldid' => $rc->mAttribs['rc_last_oldid']
445 ];
446
447 $diffLink = $this->linkRenderer->makeKnownLink(
448 $rc->getTitle(),
449 new HtmlArmor( $this->message['diff'] ),
450 [ 'class' => 'mw-changeslist-diff' ],
451 $query
452 );
453 }
454 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
455 $histLink = $this->message['hist'];
456 } else {
457 $histLink = $this->linkRenderer->makeKnownLink(
458 $rc->getTitle(),
459 new HtmlArmor( $this->message['hist'] ),
460 [ 'class' => 'mw-changeslist-history' ],
461 [
462 'curid' => $rc->mAttribs['rc_cur_id'],
463 'action' => 'history'
464 ]
465 );
466 }
467
468 $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
469 Html::rawElement( 'span', [], $diffLink ) .
470 Html::rawElement( 'span', [], $histLink )
471 ) .
472 ' <span class="mw-changeslist-separator"></span> ';
473 }
474
475 /**
476 * @param string &$s Article link will be appended to this string, in place.
477 * @param RecentChange $rc
478 * @param bool $unpatrolled
479 * @param bool $watched
480 * @deprecated since 1.27, use getArticleLink instead.
481 */
482 public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
483 $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
484 }
485
486 /**
487 * @param RecentChange &$rc
488 * @param bool $unpatrolled
489 * @param bool $watched
490 * @return string HTML
491 * @since 1.26
492 */
493 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
494 $params = [];
495 if ( $rc->getTitle()->isRedirect() ) {
496 $params = [ 'redirect' => 'no' ];
497 }
498
499 $articlelink = $this->linkRenderer->makeLink(
500 $rc->getTitle(),
501 null,
502 [ 'class' => 'mw-changeslist-title' ],
503 $params
504 );
505 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
506 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
507 }
508 # To allow for boldening pages watched by this user
509 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
510 # RTL/LTR marker
511 $articlelink .= $this->getLanguage()->getDirMark();
512
513 # TODO: Deprecate the $s argument, it seems happily unused.
514 $s = '';
515 # Avoid PHP 7.1 warning from passing $this by reference
516 $changesList = $this;
517 Hooks::run( 'ChangesListInsertArticleLink',
518 [ &$changesList, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
519
520 return "{$s} {$articlelink}";
521 }
522
523 /**
524 * Get the timestamp from $rc formatted with current user's settings
525 * and a separator
526 *
527 * @param RecentChange $rc
528 * @return string HTML fragment
529 */
530 public function getTimestamp( $rc ) {
531 // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
532 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
533 htmlspecialchars( $this->getLanguage()->userTime(
534 $rc->mAttribs['rc_timestamp'],
535 $this->getUser()
536 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
537 }
538
539 /**
540 * Insert time timestamp string from $rc into $s
541 *
542 * @param string &$s HTML to update
543 * @param RecentChange $rc
544 */
545 public function insertTimestamp( &$s, $rc ) {
546 $s .= $this->getTimestamp( $rc );
547 }
548
549 /**
550 * Insert links to user page, user talk page and eventually a blocking link
551 *
552 * @param string &$s HTML to update
553 * @param RecentChange &$rc
554 */
555 public function insertUserRelatedLinks( &$s, &$rc ) {
556 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
557 $s .= ' <span class="history-deleted">' .
558 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
559 } else {
560 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
561 $rc->mAttribs['rc_user_text'] );
562 $s .= Linker::userToolLinks(
563 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
564 false, 0, null,
565 // The text content of tools is not wrapped with parenthesises or "piped".
566 // This will be handled in CSS (T205581).
567 false
568 );
569 }
570 }
571
572 /**
573 * Insert a formatted action
574 *
575 * @param RecentChange $rc
576 * @return string
577 */
578 public function insertLogEntry( $rc ) {
579 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
580 $formatter->setContext( $this->getContext() );
581 $formatter->setShowUserToolLinks( true );
582 $mark = $this->getLanguage()->getDirMark();
583
584 return $formatter->getActionText() . " $mark" . $formatter->getComment();
585 }
586
587 /**
588 * Insert a formatted comment
589 * @param RecentChange $rc
590 * @return string
591 */
592 public function insertComment( $rc ) {
593 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
594 return ' <span class="history-deleted">' .
595 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
596 } else {
597 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
598 }
599 }
600
601 /**
602 * Returns the string which indicates the number of watching users
603 * @param int $count Number of user watching a page
604 * @return string
605 */
606 protected function numberofWatchingusers( $count ) {
607 if ( $count <= 0 ) {
608 return '';
609 }
610
611 return $this->watchMsgCache->getWithSetCallback(
612 "watching-users-msg:$count",
613 function () use ( $count ) {
614 return $this->msg( 'number_of_watching_users_RCview' )
615 ->numParams( $count )->escaped();
616 }
617 );
618 }
619
620 /**
621 * Determine if said field of a revision is hidden
622 * @param RCCacheEntry|RecentChange $rc
623 * @param int $field One of DELETED_* bitfield constants
624 * @return bool
625 */
626 public static function isDeleted( $rc, $field ) {
627 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
628 }
629
630 /**
631 * Determine if the current user is allowed to view a particular
632 * field of this revision, if it's marked as deleted.
633 * @param RCCacheEntry|RecentChange $rc
634 * @param int $field
635 * @param User|null $user User object to check, or null to use $wgUser
636 * @return bool
637 */
638 public static function userCan( $rc, $field, User $user = null ) {
639 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
640 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
641 } else {
642 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
643 }
644 }
645
646 /**
647 * @param string $link
648 * @param bool $watched
649 * @return string
650 */
651 protected function maybeWatchedLink( $link, $watched = false ) {
652 if ( $watched ) {
653 return '<strong class="mw-watched">' . $link . '</strong>';
654 } else {
655 return '<span class="mw-rc-unwatched">' . $link . '</span>';
656 }
657 }
658
659 /**
660 * Insert a rollback link
661 *
662 * @param string &$s
663 * @param RecentChange &$rc
664 */
665 public function insertRollback( &$s, &$rc ) {
666 if ( $rc->mAttribs['rc_type'] == RC_EDIT
667 && $rc->mAttribs['rc_this_oldid']
668 && $rc->mAttribs['rc_cur_id']
669 && $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
670 ) {
671 $title = $rc->getTitle();
672 /** Check for rollback permissions, disallow special pages, and only
673 * show a link on the top-most revision */
674 if ( $title->quickUserCan( 'rollback', $this->getUser() ) ) {
675 $rev = new Revision( [
676 'title' => $title,
677 'id' => $rc->mAttribs['rc_this_oldid'],
678 'user' => $rc->mAttribs['rc_user'],
679 'user_text' => $rc->mAttribs['rc_user_text'],
680 'actor' => $rc->mAttribs['rc_actor'] ?? null,
681 'deleted' => $rc->mAttribs['rc_deleted']
682 ] );
683 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
684 }
685 }
686 }
687
688 /**
689 * @param RecentChange $rc
690 * @return string
691 * @since 1.26
692 */
693 public function getRollback( RecentChange $rc ) {
694 $s = '';
695 $this->insertRollback( $s, $rc );
696 return $s;
697 }
698
699 /**
700 * @param string &$s
701 * @param RecentChange &$rc
702 * @param array &$classes
703 */
704 public function insertTags( &$s, &$rc, &$classes ) {
705 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
706 return;
707 }
708
709 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
710 $rc->mAttribs['ts_tags'],
711 'changeslist',
712 $this->getContext()
713 );
714 $classes = array_merge( $classes, $newClasses );
715 $s .= ' ' . $tagSummary;
716 }
717
718 /**
719 * @param RecentChange $rc
720 * @param array &$classes
721 * @return string
722 * @since 1.26
723 */
724 public function getTags( RecentChange $rc, array &$classes ) {
725 $s = '';
726 $this->insertTags( $s, $rc, $classes );
727 return $s;
728 }
729
730 public function insertExtra( &$s, &$rc, &$classes ) {
731 // Empty, used for subclasses to add anything special.
732 }
733
734 protected function showAsUnpatrolled( RecentChange $rc ) {
735 return self::isUnpatrolled( $rc, $this->getUser() );
736 }
737
738 /**
739 * @param object|RecentChange $rc Database row from recentchanges or a RecentChange object
740 * @param User $user
741 * @return bool
742 */
743 public static function isUnpatrolled( $rc, User $user ) {
744 if ( $rc instanceof RecentChange ) {
745 $isPatrolled = $rc->mAttribs['rc_patrolled'];
746 $rcType = $rc->mAttribs['rc_type'];
747 $rcLogType = $rc->mAttribs['rc_log_type'];
748 } else {
749 $isPatrolled = $rc->rc_patrolled;
750 $rcType = $rc->rc_type;
751 $rcLogType = $rc->rc_log_type;
752 }
753
754 if ( !$isPatrolled ) {
755 if ( $user->useRCPatrol() ) {
756 return true;
757 }
758 if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
759 return true;
760 }
761 if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
762 return true;
763 }
764 }
765
766 return false;
767 }
768
769 /**
770 * Determines whether a revision is linked to this change; this may not be the case
771 * when the categorization wasn't done by an edit but a conditional parser function
772 *
773 * @since 1.27
774 *
775 * @param RecentChange|RCCacheEntry $rcObj
776 * @return bool
777 */
778 protected function isCategorizationWithoutRevision( $rcObj ) {
779 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
780 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
781 }
782
783 /**
784 * Get recommended data attributes for a change line.
785 * @param RecentChange $rc
786 * @return string[] attribute name => value
787 */
788 protected function getDataAttributes( RecentChange $rc ) {
789 $attrs = [];
790
791 $type = $rc->getAttribute( 'rc_source' );
792 switch ( $type ) {
793 case RecentChange::SRC_EDIT:
794 case RecentChange::SRC_NEW:
795 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
796 break;
797 case RecentChange::SRC_LOG:
798 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
799 $attrs['data-mw-logaction'] =
800 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
801 break;
802 }
803
804 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
805
806 return $attrs;
807 }
808
809 /**
810 * Sets the callable that generates a change line prefix added to the beginning of each line.
811 *
812 * @param callable $prefixer Callable to run that generates the change line prefix.
813 * Takes three parameters: a RecentChange object, a ChangesList object,
814 * and whether the current entry is a grouped entry.
815 */
816 public function setChangeLinePrefixer( callable $prefixer ) {
817 $this->changeLinePrefixer = $prefixer;
818 }
819 }