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