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