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 $rcoptions = Xml
::fieldset(
460 $this->msg( 'recentchanges-legend' )->text(),
462 [ 'class' => 'rcoptions' ]
465 // Insert a placeholder for RCFilters
466 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
467 $rcfilterContainer = Html
::element(
469 [ 'class' => 'rcfilters-container' ]
472 // Wrap both with rcfilters-head
473 $this->getOutput()->addHTML(
476 [ 'class' => 'rcfilters-head' ],
477 $rcfilterContainer . $rcoptions
481 $this->getOutput()->addHTML( $rcoptions );
484 $this->setBottomText( $opts );
488 * Send the text to be displayed above the options
490 * @param FormOptions $opts Unused
492 function setTopText( FormOptions
$opts ) {
495 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
496 if ( !$message->isDisabled() ) {
497 $this->getOutput()->addWikiText(
498 Html
::rawElement( 'div',
499 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
500 "\n" . $message->plain() . "\n"
502 /* $lineStart */ true,
503 /* $interface */ false
509 * Get options to be displayed in a form
511 * @param FormOptions $opts
514 function getExtraOptions( $opts ) {
515 $opts->consumeValues( [
516 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
520 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
522 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
523 $extraOpts['category'] = $this->categoryFilterForm( $opts );
526 $tagFilter = ChangeTags
::buildTagFilterSelector(
527 $opts['tagfilter'], false, $this->getContext() );
528 if ( count( $tagFilter ) ) {
529 $extraOpts['tagfilter'] = $tagFilter;
532 // Don't fire the hook for subclasses. (Or should we?)
533 if ( $this->getName() === 'Recentchanges' ) {
534 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
541 * Add page-specific modules.
543 protected function addModules() {
544 parent
::addModules();
545 $out = $this->getOutput();
546 $out->addModules( 'mediawiki.special.recentchanges' );
547 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
548 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
549 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
554 * Get last modified date, for client caching
555 * Don't use this if we are using the patrol feature, patrol changes don't
556 * update the timestamp
558 * @return string|bool
560 public function checkLastModified() {
561 $dbr = $this->getDB();
562 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
568 * Creates the choose namespace selection
570 * @param FormOptions $opts
573 protected function namespaceFilterForm( FormOptions
$opts ) {
574 $nsSelect = Html
::namespaceSelector(
575 [ 'selected' => $opts['namespace'], 'all' => '' ],
576 [ 'name' => 'namespace', 'id' => 'namespace' ]
578 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
579 $invert = Xml
::checkLabel(
580 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
582 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
584 $associated = Xml
::checkLabel(
585 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
587 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
590 return [ $nsLabel, "$nsSelect $invert $associated" ];
594 * Create an input to filter changes by categories
596 * @param FormOptions $opts
599 protected function categoryFilterForm( FormOptions
$opts ) {
600 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
601 'categories', 'mw-categories', false, $opts['categories'] );
603 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
604 'categories_any', 'mw-categories_any', $opts['categories_any'] );
606 return [ $label, $input ];
610 * Filter $rows by categories set in $opts
612 * @param ResultWrapper $rows Database rows
613 * @param FormOptions $opts
615 function filterByCategories( &$rows, FormOptions
$opts ) {
616 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
618 if ( !count( $categories ) ) {
624 foreach ( $categories as $cat ) {
636 foreach ( $rows as $k => $r ) {
637 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
638 $id = $nt->getArticleID();
640 continue; # Page might have been deleted...
642 if ( !in_array( $id, $articles ) ) {
645 if ( !isset( $a2r[$id] ) ) {
653 if ( !count( $articles ) ||
!count( $cats ) ) {
658 $catFind = new CategoryFinder
;
659 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
660 $match = $catFind->run();
664 foreach ( $match as $id ) {
665 foreach ( $a2r[$id] as $rev ) {
667 $newrows[$k] = $rowsarr[$k];
674 * Makes change an option link which carries all the other options
676 * @param string $title Title
677 * @param array $override Options to override
678 * @param array $options Current options
679 * @param bool $active Whether to show the link in bold
682 function makeOptionsLink( $title, $override, $options, $active = false ) {
683 $params = $override +
$options;
685 // T38524: false values have be converted to "0" otherwise
686 // wfArrayToCgi() will omit it them.
687 foreach ( $params as &$value ) {
688 if ( $value === false ) {
695 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
698 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
699 'data-params' => json_encode( $override ),
700 'data-keys' => implode( ',', array_keys( $override ) ),
705 * Creates the options panel.
707 * @param array $defaults
708 * @param array $nondefaults
709 * @param int $numRows Number of rows in the result to show after this header
712 function optionsPanel( $defaults, $nondefaults, $numRows ) {
713 $options = $nondefaults +
$defaults;
716 $msg = $this->msg( 'rclegend' );
717 if ( !$msg->isDisabled() ) {
718 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
721 $lang = $this->getLanguage();
722 $user = $this->getUser();
723 $config = $this->getConfig();
724 if ( $options['from'] ) {
725 $note .= $this->msg( 'rcnotefrom' )
726 ->numParams( $options['limit'] )
728 $lang->userTimeAndDate( $options['from'], $user ),
729 $lang->userDate( $options['from'], $user ),
730 $lang->userTime( $options['from'], $user )
732 ->numParams( $numRows )
733 ->parse() . '<br />';
736 # Sort data for display and make sure it's unique after we've added user data.
737 $linkLimits = $config->get( 'RCLinkLimits' );
738 $linkLimits[] = $options['limit'];
740 $linkLimits = array_unique( $linkLimits );
742 $linkDays = $config->get( 'RCLinkDays' );
743 $linkDays[] = $options['days'];
745 $linkDays = array_unique( $linkDays );
749 foreach ( $linkLimits as $value ) {
750 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
751 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
753 $cl = $lang->pipeList( $cl );
755 // day links, reset 'from' to none
757 foreach ( $linkDays as $value ) {
758 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
759 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
761 $dl = $lang->pipeList( $dl );
765 'hideminor' => 'rcshowhideminor',
766 'hidebots' => 'rcshowhidebots',
767 'hideanons' => 'rcshowhideanons',
768 'hideliu' => 'rcshowhideliu',
769 'hidepatrolled' => 'rcshowhidepatr',
770 'hidemyself' => 'rcshowhidemine'
773 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
774 $filters['hidecategorization'] = 'rcshowhidecategorization';
777 $showhide = [ 'show', 'hide' ];
779 foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) {
780 $filters[$key] = $params['msg'];
783 // Disable some if needed
784 if ( !$user->useRCPatrol() ) {
785 unset( $filters['hidepatrolled'] );
789 foreach ( $filters as $key => $msg ) {
790 // The following messages are used here:
791 // rcshowhideminor-show, rcshowhideminor-hide, rcshowhidebots-show, rcshowhidebots-hide,
792 // rcshowhideanons-show, rcshowhideanons-hide, rcshowhideliu-show, rcshowhideliu-hide,
793 // rcshowhidepatr-show, rcshowhidepatr-hide, rcshowhidemine-show, rcshowhidemine-hide,
794 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
795 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
796 // Extensions can define additional filters, but don't need to define the corresponding
797 // messages. If they don't exist, just fall back to 'show' and 'hide'.
798 if ( !$linkMessage->exists() ) {
799 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
802 $link = $this->makeOptionsLink( $linkMessage->text(),
803 [ $key => 1 - $options[$key] ], $nondefaults );
804 $links[] = "<span class=\"$msg rcshowhideoption\">"
805 . $this->msg( $msg )->rawParams( $link )->escaped() . '</span>';
808 // show from this onward link
809 $timestamp = wfTimestampNow();
810 $now = $lang->userTimeAndDate( $timestamp, $user );
811 $timenow = $lang->userTime( $timestamp, $user );
812 $datenow = $lang->userDate( $timestamp, $user );
813 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
815 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, $pipedLinks )
816 ->parse() . '</span>';
818 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
819 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
820 [ 'from' => $timestamp ],
824 return "{$note}$rclinks<br />$rclistfrom";
827 public function isIncludable() {
831 protected function getCacheTTL() {
835 function filterOnUserExperienceLevel( &$tables, &$conds, &$join_conds, $opts ) {
836 global $wgLearnerEdits,
837 $wgExperiencedUserEdits,
838 $wgLearnerMemberSince,
839 $wgExperiencedUserMemberSince;
841 $selectedExpLevels = explode( ',', strtolower( $opts['userExpLevel'] ) );
842 // remove values that are not recognized
843 $selectedExpLevels = array_intersect(
845 [ 'newcomer', 'learner', 'experienced' ]
847 sort( $selectedExpLevels );
849 if ( $selectedExpLevels ) {
851 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
854 $secondsPerDay = 86400;
855 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
856 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
858 $aboveNewcomer = $this->getDB()->makeList(
860 'user_editcount >= ' . intval( $wgLearnerEdits ),
861 'user_registration <= ' . $this->getDB()->timestamp( $learnerCutoff ),
866 $aboveLearner = $this->getDB()->makeList(
868 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
869 'user_registration <= ' . $this->getDB()->timestamp( $experiencedUserCutoff ),
874 if ( $selectedExpLevels === [ 'newcomer' ] ) {
875 $conds[] = "NOT ( $aboveNewcomer )";
876 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
877 $conds[] = $this->getDB()->makeList(
878 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
881 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
882 $conds[] = $aboveLearner;
883 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
884 $conds[] = "NOT ( $aboveLearner )";
885 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
886 $conds[] = $this->getDB()->makeList(
887 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
890 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
891 $conds[] = $aboveNewcomer;