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