3 * Implements Special:Recentchanges
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 use MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\ResultWrapper
;
28 * A special page that lists last changes made to the wiki
30 * @ingroup SpecialPage
32 class SpecialRecentChanges
extends ChangesListSpecialPage
{
33 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
34 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
35 parent
::__construct( $name, $restriction );
37 // @codingStandardsIgnoreEnd
40 * Main execution point
42 * @param string $subpage
44 public function execute( $subpage ) {
45 // Backwards-compatibility: redirect to new feed URLs
46 $feedFormat = $this->getRequest()->getVal( 'feed' );
47 if ( !$this->including() && $feedFormat ) {
48 $query = $this->getFeedQuery();
49 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
50 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
55 // 10 seconds server-side caching max
56 $this->getOutput()->setCdnMaxage( 10 );
57 // Check if the client has a cached version
58 $lastmod = $this->checkLastModified();
59 if ( $lastmod === false ) {
64 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
67 parent
::execute( $subpage );
71 * Get a FormOptions object containing the default options
75 public function getDefaultOptions() {
76 $opts = parent
::getDefaultOptions();
77 $user = $this->getUser();
79 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
80 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
81 $opts->add( 'from', '' );
83 $opts->add( 'hideminor', $user->getBoolOption( 'hideminor' ) );
84 $opts->add( 'hidebots', true );
85 $opts->add( 'hideanons', false );
86 $opts->add( 'hideliu', false );
87 $opts->add( 'hidepatrolled', $user->getBoolOption( 'hidepatrolled' ) );
88 $opts->add( 'hidemyself', false );
89 $opts->add( 'hidecategorization', $user->getBoolOption( 'hidecategorization' ) );
91 $opts->add( 'categories', '' );
92 $opts->add( 'categories_any', false );
93 $opts->add( 'tagfilter', '' );
95 $opts->add( 'userExpLevel', 'all' );
101 * Get all custom filters
103 * @return array Map of filter URL param names to properties (msg/default)
105 protected function getCustomFilters() {
106 if ( $this->customFilters
=== null ) {
107 $this->customFilters
= parent
::getCustomFilters();
108 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
111 return $this->customFilters
;
115 * Process $par and put options found in $opts. Used when including the page.
118 * @param FormOptions $opts
120 public function parseParameters( $par, FormOptions
$opts ) {
121 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
122 foreach ( $bits as $bit ) {
123 if ( 'hidebots' === $bit ) {
124 $opts['hidebots'] = true;
126 if ( 'bots' === $bit ) {
127 $opts['hidebots'] = false;
129 if ( 'hideminor' === $bit ) {
130 $opts['hideminor'] = true;
132 if ( 'minor' === $bit ) {
133 $opts['hideminor'] = false;
135 if ( 'hideliu' === $bit ) {
136 $opts['hideliu'] = true;
138 if ( 'hidepatrolled' === $bit ) {
139 $opts['hidepatrolled'] = true;
141 if ( 'hideanons' === $bit ) {
142 $opts['hideanons'] = true;
144 if ( 'hidemyself' === $bit ) {
145 $opts['hidemyself'] = true;
147 if ( 'hidecategorization' === $bit ) {
148 $opts['hidecategorization'] = true;
151 if ( is_numeric( $bit ) ) {
152 $opts['limit'] = $bit;
156 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
157 $opts['limit'] = $m[1];
159 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
160 $opts['days'] = $m[1];
162 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
163 $opts['namespace'] = $m[1];
165 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
166 $opts['tagfilter'] = $m[1];
171 public function validateOptions( FormOptions
$opts ) {
172 $opts->validateIntBounds( 'limit', 0, 5000 );
173 parent
::validateOptions( $opts );
177 * Return an array of conditions depending of options set in $opts
179 * @param FormOptions $opts
182 public function buildMainQueryConds( FormOptions
$opts ) {
183 $dbr = $this->getDB();
184 $conds = parent
::buildMainQueryConds( $opts );
187 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
188 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime %
86400 );
189 $cutoff = $dbr->timestamp( $cutoff_unixtime );
191 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
192 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
193 $cutoff = $dbr->timestamp( $opts['from'] );
195 $opts->reset( 'from' );
198 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
206 * @param array $conds
207 * @param FormOptions $opts
208 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
210 public function doMainQuery( $conds, $opts ) {
211 $dbr = $this->getDB();
212 $user = $this->getUser();
214 $tables = [ 'recentchanges' ];
215 $fields = RecentChange
::selectFields();
219 // JOIN on watchlist for users
220 if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) {
221 $tables[] = 'watchlist';
222 $fields[] = 'wl_user';
223 $fields[] = 'wl_notificationtimestamp';
224 $join_conds['watchlist'] = [ 'LEFT JOIN', [
225 'wl_user' => $user->getId(),
227 'wl_namespace=rc_namespace'
231 if ( $user->isAllowed( 'rollback' ) ) {
233 $fields[] = 'page_latest';
234 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
237 ChangeTags
::modifyDisplayQuery(
246 $this->filterOnUserExperienceLevel( $tables, $conds, $join_conds, $opts );
248 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
254 // array_merge() is used intentionally here so that hooks can, should
255 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
256 // MediaWiki 1.26 this used to use the plus operator instead, which meant
257 // that extensions weren't able to change these conditions
258 $query_options = array_merge( [
259 'ORDER BY' => 'rc_timestamp DESC',
260 'LIMIT' => $opts['limit'] ], $query_options );
261 $rows = $dbr->select(
264 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
265 // knowledge to use an index merge if it wants (it may use some other index though).
266 $conds +
[ 'rc_new' => [ 0, 1 ] ],
272 // Build the final data
273 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
274 $this->filterByCategories( $rows, $opts );
280 protected function runMainQueryHook( &$tables, &$fields, &$conds,
281 &$query_options, &$join_conds, $opts
283 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
285 'SpecialRecentChangesQuery',
286 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
291 protected function getDB() {
292 return wfGetDB( DB_REPLICA
, 'recentchanges' );
295 public function outputFeedLinks() {
296 $this->addFeedLinks( $this->getFeedQuery() );
300 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
304 protected function getFeedQuery() {
305 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
306 // API handles empty parameters in a different way
307 return $value !== '';
309 $query['action'] = 'feedrecentchanges';
310 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
311 if ( $query['limit'] > $feedLimit ) {
312 $query['limit'] = $feedLimit;
319 * Build and output the actual changes list.
321 * @param ResultWrapper $rows Database rows
322 * @param FormOptions $opts
324 public function outputChangesList( $rows, $opts ) {
325 $limit = $opts['limit'];
327 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
328 && $this->getUser()->getOption( 'shownumberswatching' );
331 $dbr = $this->getDB();
334 $list = ChangesList
::newFromContext( $this->getContext() );
335 $list->initChangesListRows( $rows );
337 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
338 $rclistOutput = $list->beginRecentChangesList();
339 foreach ( $rows as $obj ) {
343 $rc = RecentChange
::newFromRow( $obj );
345 # Skip CatWatch entries for hidden cats based on user preference
347 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
348 !$userShowHiddenCats &&
349 $rc->getParam( 'hidden-cat' )
354 $rc->counter
= $counter++
;
355 # Check if the page has been updated since the last visit
356 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
357 && !empty( $obj->wl_notificationtimestamp
)
359 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
361 $rc->notificationtimestamp
= false; // Default
363 # Check the number of users watching the page
364 $rc->numberofWatchingusers
= 0; // Default
365 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
366 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
367 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
368 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
369 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
372 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
375 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
376 if ( $changeLine !== false ) {
377 $rclistOutput .= $changeLine;
381 $rclistOutput .= $list->endRecentChangesList();
383 if ( $rows->numRows() === 0 ) {
384 $this->getOutput()->addHTML(
385 '<div class="mw-changeslist-empty">' .
386 $this->msg( 'recentchanges-noresult' )->parse() .
389 if ( !$this->including() ) {
390 $this->getOutput()->setStatusCode( 404 );
393 $this->getOutput()->addHTML( $rclistOutput );
398 * Set the text to be displayed above the changes
400 * @param FormOptions $opts
401 * @param int $numRows Number of rows in the result to show after this header
403 public function doHeader( $opts, $numRows ) {
404 $this->setTopText( $opts );
406 $defaults = $opts->getAllValues();
407 $nondefaults = $opts->getChangedValues();
410 $panel[] = $this->makeLegend();
411 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
414 $extraOpts = $this->getExtraOptions( $opts );
415 $extraOptsCount = count( $extraOpts );
417 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
419 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
420 foreach ( $extraOpts as $name => $optionRow ) {
421 # Add submit button to the last row only
423 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
425 $out .= Xml
::openElement( 'tr' );
426 if ( is_array( $optionRow ) ) {
429 [ 'class' => 'mw-label mw-' . $name . '-label' ],
434 [ 'class' => 'mw-input' ],
435 $optionRow[1] . $addSubmit
440 [ 'class' => 'mw-input', 'colspan' => 2 ],
441 $optionRow . $addSubmit
444 $out .= Xml
::closeElement( 'tr' );
446 $out .= Xml
::closeElement( 'table' );
448 $unconsumed = $opts->getUnconsumedValues();
449 foreach ( $unconsumed as $key => $value ) {
450 $out .= Html
::hidden( $key, $value );
453 $t = $this->getPageTitle();
454 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
455 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
457 $panelString = implode( "\n", $panel );
459 // Insert a placeholder for RCFilters
460 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
461 $this->getOutput()->addHTML(
464 [ 'class' => 'rcfilters-container' ]
469 $this->getOutput()->addHTML(
471 $this->msg( 'recentchanges-legend' )->text(),
473 [ 'class' => 'rcoptions' ]
477 $this->setBottomText( $opts );
481 * Send the text to be displayed above the options
483 * @param FormOptions $opts Unused
485 function setTopText( FormOptions
$opts ) {
488 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
489 if ( !$message->isDisabled() ) {
490 $this->getOutput()->addWikiText(
491 Html
::rawElement( 'div',
492 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
493 "\n" . $message->plain() . "\n"
495 /* $lineStart */ true,
496 /* $interface */ false
502 * Get options to be displayed in a form
504 * @param FormOptions $opts
507 function getExtraOptions( $opts ) {
508 $opts->consumeValues( [
509 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
513 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
515 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
516 $extraOpts['category'] = $this->categoryFilterForm( $opts );
519 $tagFilter = ChangeTags
::buildTagFilterSelector(
520 $opts['tagfilter'], false, $this->getContext() );
521 if ( count( $tagFilter ) ) {
522 $extraOpts['tagfilter'] = $tagFilter;
525 // Don't fire the hook for subclasses. (Or should we?)
526 if ( $this->getName() === 'Recentchanges' ) {
527 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
534 * Add page-specific modules.
536 protected function addModules() {
537 parent
::addModules();
538 $out = $this->getOutput();
539 $out->addModules( 'mediawiki.special.recentchanges' );
540 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
541 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
542 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
547 * Get last modified date, for client caching
548 * Don't use this if we are using the patrol feature, patrol changes don't
549 * update the timestamp
551 * @return string|bool
553 public function checkLastModified() {
554 $dbr = $this->getDB();
555 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
561 * Creates the choose namespace selection
563 * @param FormOptions $opts
566 protected function namespaceFilterForm( FormOptions
$opts ) {
567 $nsSelect = Html
::namespaceSelector(
568 [ 'selected' => $opts['namespace'], 'all' => '' ],
569 [ 'name' => 'namespace', 'id' => 'namespace' ]
571 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
572 $invert = Xml
::checkLabel(
573 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
575 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
577 $associated = Xml
::checkLabel(
578 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
580 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
583 return [ $nsLabel, "$nsSelect $invert $associated" ];
587 * Create an input to filter changes by categories
589 * @param FormOptions $opts
592 protected function categoryFilterForm( FormOptions
$opts ) {
593 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
594 'categories', 'mw-categories', false, $opts['categories'] );
596 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
597 'categories_any', 'mw-categories_any', $opts['categories_any'] );
599 return [ $label, $input ];
603 * Filter $rows by categories set in $opts
605 * @param ResultWrapper $rows Database rows
606 * @param FormOptions $opts
608 function filterByCategories( &$rows, FormOptions
$opts ) {
609 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
611 if ( !count( $categories ) ) {
617 foreach ( $categories as $cat ) {
629 foreach ( $rows as $k => $r ) {
630 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
631 $id = $nt->getArticleID();
633 continue; # Page might have been deleted...
635 if ( !in_array( $id, $articles ) ) {
638 if ( !isset( $a2r[$id] ) ) {
646 if ( !count( $articles ) ||
!count( $cats ) ) {
651 $catFind = new CategoryFinder
;
652 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
653 $match = $catFind->run();
657 foreach ( $match as $id ) {
658 foreach ( $a2r[$id] as $rev ) {
660 $newrows[$k] = $rowsarr[$k];
667 * Makes change an option link which carries all the other options
669 * @param string $title Title
670 * @param array $override Options to override
671 * @param array $options Current options
672 * @param bool $active Whether to show the link in bold
675 function makeOptionsLink( $title, $override, $options, $active = false ) {
676 $params = $override +
$options;
678 // T38524: false values have be converted to "0" otherwise
679 // wfArrayToCgi() will omit it them.
680 foreach ( $params as &$value ) {
681 if ( $value === false ) {
688 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
691 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
692 'data-params' => json_encode( $override ),
693 'data-keys' => implode( ',', array_keys( $override ) ),
698 * Creates the options panel.
700 * @param array $defaults
701 * @param array $nondefaults
702 * @param int $numRows Number of rows in the result to show after this header
705 function optionsPanel( $defaults, $nondefaults, $numRows ) {
706 $options = $nondefaults +
$defaults;
709 $msg = $this->msg( 'rclegend' );
710 if ( !$msg->isDisabled() ) {
711 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
714 $lang = $this->getLanguage();
715 $user = $this->getUser();
716 $config = $this->getConfig();
717 if ( $options['from'] ) {
718 $note .= $this->msg( 'rcnotefrom' )
719 ->numParams( $options['limit'] )
721 $lang->userTimeAndDate( $options['from'], $user ),
722 $lang->userDate( $options['from'], $user ),
723 $lang->userTime( $options['from'], $user )
725 ->numParams( $numRows )
726 ->parse() . '<br />';
729 # Sort data for display and make sure it's unique after we've added user data.
730 $linkLimits = $config->get( 'RCLinkLimits' );
731 $linkLimits[] = $options['limit'];
733 $linkLimits = array_unique( $linkLimits );
735 $linkDays = $config->get( 'RCLinkDays' );
736 $linkDays[] = $options['days'];
738 $linkDays = array_unique( $linkDays );
742 foreach ( $linkLimits as $value ) {
743 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
744 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
746 $cl = $lang->pipeList( $cl );
748 // day links, reset 'from' to none
750 foreach ( $linkDays as $value ) {
751 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
752 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
754 $dl = $lang->pipeList( $dl );
758 'hideminor' => 'rcshowhideminor',
759 'hidebots' => 'rcshowhidebots',
760 'hideanons' => 'rcshowhideanons',
761 'hideliu' => 'rcshowhideliu',
762 'hidepatrolled' => 'rcshowhidepatr',
763 'hidemyself' => 'rcshowhidemine'
766 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
767 $filters['hidecategorization'] = 'rcshowhidecategorization';
770 $showhide = [ 'show', 'hide' ];
772 foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) {
773 $filters[$key] = $params['msg'];
776 // Disable some if needed
777 if ( !$user->useRCPatrol() ) {
778 unset( $filters['hidepatrolled'] );
782 foreach ( $filters as $key => $msg ) {
783 // The following messages are used here:
784 // rcshowhideminor-show, rcshowhideminor-hide, rcshowhidebots-show, rcshowhidebots-hide,
785 // rcshowhideanons-show, rcshowhideanons-hide, rcshowhideliu-show, rcshowhideliu-hide,
786 // rcshowhidepatr-show, rcshowhidepatr-hide, rcshowhidemine-show, rcshowhidemine-hide,
787 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
788 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
789 // Extensions can define additional filters, but don't need to define the corresponding
790 // messages. If they don't exist, just fall back to 'show' and 'hide'.
791 if ( !$linkMessage->exists() ) {
792 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
795 $link = $this->makeOptionsLink( $linkMessage->text(),
796 [ $key => 1 - $options[$key] ], $nondefaults );
797 $links[] = "<span class=\"$msg rcshowhideoption\">"
798 . $this->msg( $msg )->rawParams( $link )->escaped() . '</span>';
801 // show from this onward link
802 $timestamp = wfTimestampNow();
803 $now = $lang->userTimeAndDate( $timestamp, $user );
804 $timenow = $lang->userTime( $timestamp, $user );
805 $datenow = $lang->userDate( $timestamp, $user );
806 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
808 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, $pipedLinks )
809 ->parse() . '</span>';
811 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
812 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
813 [ 'from' => $timestamp ],
817 return "{$note}$rclinks<br />$rclistfrom";
820 public function isIncludable() {
824 protected function getCacheTTL() {
828 function filterOnUserExperienceLevel( &$tables, &$conds, &$join_conds, $opts ) {
829 global $wgLearnerEdits,
830 $wgExperiencedUserEdits,
831 $wgLearnerMemberSince,
832 $wgExperiencedUserMemberSince;
834 $selectedExpLevels = explode( ',', strtolower( $opts['userExpLevel'] ) );
835 // remove values that are not recognized
836 $selectedExpLevels = array_intersect(
838 [ 'newcomer', 'learner', 'experienced' ]
840 sort( $selectedExpLevels );
842 if ( $selectedExpLevels ) {
844 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
847 $secondsPerDay = 86400;
848 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
849 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
851 $aboveNewcomer = $this->getDB()->makeList(
853 'user_editcount >= ' . intval( $wgLearnerEdits ),
854 'user_registration <= ' . $this->getDB()->timestamp( $learnerCutoff ),
859 $aboveLearner = $this->getDB()->makeList(
861 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
862 'user_registration <= ' . $this->getDB()->timestamp( $experiencedUserCutoff ),
867 if ( $selectedExpLevels === [ 'newcomer' ] ) {
868 $conds[] = "NOT ( $aboveNewcomer )";
869 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
870 $conds[] = $this->getDB()->makeList(
871 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
874 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
875 $conds[] = $aboveLearner;
876 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
877 $conds[] = "NOT ( $aboveLearner )";
878 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
879 $conds[] = $this->getDB()->makeList(
880 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
883 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
884 $conds[] = $aboveNewcomer;