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