a2e643bf6b04cf5f902b58a03d6206b7a827b9e8
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
1 <?php
2 /**
3 * Implements Special:Recentchanges
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 use MediaWiki\MediaWikiServices;
25
26 /**
27 * A special page that lists last changes made to the wiki
28 *
29 * @ingroup SpecialPage
30 */
31 class SpecialRecentChanges extends ChangesListSpecialPage {
32 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
33 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
34 parent::__construct( $name, $restriction );
35 }
36 // @codingStandardsIgnoreEnd
37
38 /**
39 * Main execution point
40 *
41 * @param string $subpage
42 */
43 public function execute( $subpage ) {
44 // Backwards-compatibility: redirect to new feed URLs
45 $feedFormat = $this->getRequest()->getVal( 'feed' );
46 if ( !$this->including() && $feedFormat ) {
47 $query = $this->getFeedQuery();
48 $query['feedformat'] = $feedFormat === 'atom' ? 'atom' : 'rss';
49 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
50
51 return;
52 }
53
54 // 10 seconds server-side caching max
55 $this->getOutput()->setCdnMaxage( 10 );
56 // Check if the client has a cached version
57 $lastmod = $this->checkLastModified();
58 if ( $lastmod === false ) {
59 return;
60 }
61
62 $this->addHelpLink(
63 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
64 true
65 );
66 parent::execute( $subpage );
67 }
68
69 /**
70 * Get a FormOptions object containing the default options
71 *
72 * @return FormOptions
73 */
74 public function getDefaultOptions() {
75 $opts = parent::getDefaultOptions();
76 $user = $this->getUser();
77
78 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
79 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
80 $opts->add( 'from', '' );
81
82 $opts->add( 'hideminor', $user->getBoolOption( 'hideminor' ) );
83 $opts->add( 'hidebots', true );
84 $opts->add( 'hideanons', false );
85 $opts->add( 'hideliu', false );
86 $opts->add( 'hidepatrolled', $user->getBoolOption( 'hidepatrolled' ) );
87 $opts->add( 'hidemyself', false );
88 $opts->add( 'hidecategorization', $user->getBoolOption( 'hidecategorization' ) );
89
90 $opts->add( 'categories', '' );
91 $opts->add( 'categories_any', false );
92 $opts->add( 'tagfilter', '' );
93
94 $opts->add( 'userExpLevel', 'all' );
95
96 return $opts;
97 }
98
99 /**
100 * Get all custom filters
101 *
102 * @return array Map of filter URL param names to properties (msg/default)
103 */
104 protected function getCustomFilters() {
105 if ( $this->customFilters === null ) {
106 $this->customFilters = parent::getCustomFilters();
107 Hooks::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters ], '1.23' );
108 }
109
110 return $this->customFilters;
111 }
112
113 /**
114 * Process $par and put options found in $opts. Used when including the page.
115 *
116 * @param string $par
117 * @param FormOptions $opts
118 */
119 public function parseParameters( $par, FormOptions $opts ) {
120 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
121 foreach ( $bits as $bit ) {
122 if ( 'hidebots' === $bit ) {
123 $opts['hidebots'] = true;
124 }
125 if ( 'bots' === $bit ) {
126 $opts['hidebots'] = false;
127 }
128 if ( 'hideminor' === $bit ) {
129 $opts['hideminor'] = true;
130 }
131 if ( 'minor' === $bit ) {
132 $opts['hideminor'] = false;
133 }
134 if ( 'hideliu' === $bit ) {
135 $opts['hideliu'] = true;
136 }
137 if ( 'hidepatrolled' === $bit ) {
138 $opts['hidepatrolled'] = true;
139 }
140 if ( 'hideanons' === $bit ) {
141 $opts['hideanons'] = true;
142 }
143 if ( 'hidemyself' === $bit ) {
144 $opts['hidemyself'] = true;
145 }
146 if ( 'hidecategorization' === $bit ) {
147 $opts['hidecategorization'] = true;
148 }
149
150 if ( is_numeric( $bit ) ) {
151 $opts['limit'] = $bit;
152 }
153
154 $m = [];
155 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
156 $opts['limit'] = $m[1];
157 }
158 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
159 $opts['days'] = $m[1];
160 }
161 if ( preg_match( '/^namespace=(\d+)$/', $bit, $m ) ) {
162 $opts['namespace'] = $m[1];
163 }
164 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
165 $opts['tagfilter'] = $m[1];
166 }
167 }
168 }
169
170 public function validateOptions( FormOptions $opts ) {
171 $opts->validateIntBounds( 'limit', 0, 5000 );
172 parent::validateOptions( $opts );
173 }
174
175 /**
176 * Return an array of conditions depending of options set in $opts
177 *
178 * @param FormOptions $opts
179 * @return array
180 */
181 public function buildMainQueryConds( FormOptions $opts ) {
182 $dbr = $this->getDB();
183 $conds = parent::buildMainQueryConds( $opts );
184
185 // Calculate cutoff
186 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
187 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime % 86400 );
188 $cutoff = $dbr->timestamp( $cutoff_unixtime );
189
190 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
191 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
192 $cutoff = $dbr->timestamp( $opts['from'] );
193 } else {
194 $opts->reset( 'from' );
195 }
196
197 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
198
199 return $conds;
200 }
201
202 /**
203 * Process the query
204 *
205 * @param array $conds
206 * @param FormOptions $opts
207 * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
208 */
209 public function doMainQuery( $conds, $opts ) {
210 $dbr = $this->getDB();
211 $user = $this->getUser();
212
213 $tables = [ 'recentchanges' ];
214 $fields = RecentChange::selectFields();
215 $query_options = [];
216 $join_conds = [];
217
218 // JOIN on watchlist for users
219 if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) {
220 $tables[] = 'watchlist';
221 $fields[] = 'wl_user';
222 $fields[] = 'wl_notificationtimestamp';
223 $join_conds['watchlist'] = [ 'LEFT JOIN', [
224 'wl_user' => $user->getId(),
225 'wl_title=rc_title',
226 'wl_namespace=rc_namespace'
227 ] ];
228 }
229
230 if ( $user->isAllowed( 'rollback' ) ) {
231 $tables[] = 'page';
232 $fields[] = 'page_latest';
233 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
234 }
235
236 ChangeTags::modifyDisplayQuery(
237 $tables,
238 $fields,
239 $conds,
240 $join_conds,
241 $query_options,
242 $opts['tagfilter']
243 );
244
245 $this->filterOnUserExperienceLevel( $tables, $conds, $join_conds, $opts );
246
247 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
248 $opts )
249 ) {
250 return false;
251 }
252
253 // array_merge() is used intentionally here so that hooks can, should
254 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
255 // MediaWiki 1.26 this used to use the plus operator instead, which meant
256 // that extensions weren't able to change these conditions
257 $query_options = array_merge( [
258 'ORDER BY' => 'rc_timestamp DESC',
259 'LIMIT' => $opts['limit'] ], $query_options );
260 $rows = $dbr->select(
261 $tables,
262 $fields,
263 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
264 // knowledge to use an index merge if it wants (it may use some other index though).
265 $conds + [ 'rc_new' => [ 0, 1 ] ],
266 __METHOD__,
267 $query_options,
268 $join_conds
269 );
270
271 // Build the final data
272 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
273 $this->filterByCategories( $rows, $opts );
274 }
275
276 return $rows;
277 }
278
279 protected function runMainQueryHook( &$tables, &$fields, &$conds,
280 &$query_options, &$join_conds, $opts
281 ) {
282 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
283 && Hooks::run(
284 'SpecialRecentChangesQuery',
285 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
286 '1.23'
287 );
288 }
289
290 protected function getDB() {
291 return wfGetDB( DB_REPLICA, 'recentchanges' );
292 }
293
294 public function outputFeedLinks() {
295 $this->addFeedLinks( $this->getFeedQuery() );
296 }
297
298 /**
299 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
300 *
301 * @return array
302 */
303 protected function getFeedQuery() {
304 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
305 // API handles empty parameters in a different way
306 return $value !== '';
307 } );
308 $query['action'] = 'feedrecentchanges';
309 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
310 if ( $query['limit'] > $feedLimit ) {
311 $query['limit'] = $feedLimit;
312 }
313
314 return $query;
315 }
316
317 /**
318 * Build and output the actual changes list.
319 *
320 * @param ResultWrapper $rows Database rows
321 * @param FormOptions $opts
322 */
323 public function outputChangesList( $rows, $opts ) {
324 $limit = $opts['limit'];
325
326 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
327 && $this->getUser()->getOption( 'shownumberswatching' );
328 $watcherCache = [];
329
330 $dbr = $this->getDB();
331
332 $counter = 1;
333 $list = ChangesList::newFromContext( $this->getContext() );
334 $list->initChangesListRows( $rows );
335
336 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
337 $rclistOutput = $list->beginRecentChangesList();
338 foreach ( $rows as $obj ) {
339 if ( $limit == 0 ) {
340 break;
341 }
342 $rc = RecentChange::newFromRow( $obj );
343
344 # Skip CatWatch entries for hidden cats based on user preference
345 if (
346 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
347 !$userShowHiddenCats &&
348 $rc->getParam( 'hidden-cat' )
349 ) {
350 continue;
351 }
352
353 $rc->counter = $counter++;
354 # Check if the page has been updated since the last visit
355 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
356 && !empty( $obj->wl_notificationtimestamp )
357 ) {
358 $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
359 } else {
360 $rc->notificationtimestamp = false; // Default
361 }
362 # Check the number of users watching the page
363 $rc->numberofWatchingusers = 0; // Default
364 if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
365 if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
366 $watcherCache[$obj->rc_namespace][$obj->rc_title] =
367 MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchers(
368 new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
369 );
370 }
371 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
372 }
373
374 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
375 if ( $changeLine !== false ) {
376 $rclistOutput .= $changeLine;
377 --$limit;
378 }
379 }
380 $rclistOutput .= $list->endRecentChangesList();
381
382 if ( $rows->numRows() === 0 ) {
383 $this->getOutput()->addHTML(
384 '<div class="mw-changeslist-empty">' .
385 $this->msg( 'recentchanges-noresult' )->parse() .
386 '</div>'
387 );
388 if ( !$this->including() ) {
389 $this->getOutput()->setStatusCode( 404 );
390 }
391 } else {
392 $this->getOutput()->addHTML( $rclistOutput );
393 }
394 }
395
396 /**
397 * Set the text to be displayed above the changes
398 *
399 * @param FormOptions $opts
400 * @param int $numRows Number of rows in the result to show after this header
401 */
402 public function doHeader( $opts, $numRows ) {
403 $this->setTopText( $opts );
404
405 $defaults = $opts->getAllValues();
406 $nondefaults = $opts->getChangedValues();
407
408 $panel = [];
409 $panel[] = $this->makeLegend();
410 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
411 $panel[] = '<hr />';
412
413 $extraOpts = $this->getExtraOptions( $opts );
414 $extraOptsCount = count( $extraOpts );
415 $count = 0;
416 $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
417
418 $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
419 foreach ( $extraOpts as $name => $optionRow ) {
420 # Add submit button to the last row only
421 ++$count;
422 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
423
424 $out .= Xml::openElement( 'tr' );
425 if ( is_array( $optionRow ) ) {
426 $out .= Xml::tags(
427 'td',
428 [ 'class' => 'mw-label mw-' . $name . '-label' ],
429 $optionRow[0]
430 );
431 $out .= Xml::tags(
432 'td',
433 [ 'class' => 'mw-input' ],
434 $optionRow[1] . $addSubmit
435 );
436 } else {
437 $out .= Xml::tags(
438 'td',
439 [ 'class' => 'mw-input', 'colspan' => 2 ],
440 $optionRow . $addSubmit
441 );
442 }
443 $out .= Xml::closeElement( 'tr' );
444 }
445 $out .= Xml::closeElement( 'table' );
446
447 $unconsumed = $opts->getUnconsumedValues();
448 foreach ( $unconsumed as $key => $value ) {
449 $out .= Html::hidden( $key, $value );
450 }
451
452 $t = $this->getPageTitle();
453 $out .= Html::hidden( 'title', $t->getPrefixedText() );
454 $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
455 $panel[] = $form;
456 $panelString = implode( "\n", $panel );
457
458 // Insert a placeholder for RCFilters
459 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
460 $this->getOutput()->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
461 $this->getOutput()->addHTML(
462 Html::element(
463 'div',
464 [ 'class' => 'rcfilters-container' ]
465 )
466 );
467 }
468
469 $this->getOutput()->addHTML(
470 Xml::fieldset(
471 $this->msg( 'recentchanges-legend' )->text(),
472 $panelString,
473 [ 'class' => 'rcoptions' ]
474 )
475 );
476
477 $this->setBottomText( $opts );
478 }
479
480 /**
481 * Send the text to be displayed above the options
482 *
483 * @param FormOptions $opts Unused
484 */
485 function setTopText( FormOptions $opts ) {
486 global $wgContLang;
487
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"
494 ),
495 /* $lineStart */ true,
496 /* $interface */ false
497 );
498 }
499 }
500
501 /**
502 * Get options to be displayed in a form
503 *
504 * @param FormOptions $opts
505 * @return array
506 */
507 function getExtraOptions( $opts ) {
508 $opts->consumeValues( [
509 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
510 ] );
511
512 $extraOpts = [];
513 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
514
515 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
516 $extraOpts['category'] = $this->categoryFilterForm( $opts );
517 }
518
519 $tagFilter = ChangeTags::buildTagFilterSelector(
520 $opts['tagfilter'], false, $this->getContext() );
521 if ( count( $tagFilter ) ) {
522 $extraOpts['tagfilter'] = $tagFilter;
523 }
524
525 // Don't fire the hook for subclasses. (Or should we?)
526 if ( $this->getName() === 'Recentchanges' ) {
527 Hooks::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
528 }
529
530 return $extraOpts;
531 }
532
533 /**
534 * Add page-specific modules.
535 */
536 protected function addModules() {
537 parent::addModules();
538 $out = $this->getOutput();
539 $out->addModules( 'mediawiki.special.recentchanges' );
540 if ( $this->getUser()->getOption(
541 'rcenhancedfilters',
542 /*default=*/ null,
543 /*ignoreHidden=*/ true
544 )
545 ) {
546 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
547 }
548 }
549
550 /**
551 * Get last modified date, for client caching
552 * Don't use this if we are using the patrol feature, patrol changes don't
553 * update the timestamp
554 *
555 * @return string|bool
556 */
557 public function checkLastModified() {
558 $dbr = $this->getDB();
559 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
560
561 return $lastmod;
562 }
563
564 /**
565 * Creates the choose namespace selection
566 *
567 * @param FormOptions $opts
568 * @return string
569 */
570 protected function namespaceFilterForm( FormOptions $opts ) {
571 $nsSelect = Html::namespaceSelector(
572 [ 'selected' => $opts['namespace'], 'all' => '' ],
573 [ 'name' => 'namespace', 'id' => 'namespace' ]
574 );
575 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
576 $invert = Xml::checkLabel(
577 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
578 $opts['invert'],
579 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
580 );
581 $associated = Xml::checkLabel(
582 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
583 $opts['associated'],
584 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
585 );
586
587 return [ $nsLabel, "$nsSelect $invert $associated" ];
588 }
589
590 /**
591 * Create an input to filter changes by categories
592 *
593 * @param FormOptions $opts
594 * @return array
595 */
596 protected function categoryFilterForm( FormOptions $opts ) {
597 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
598 'categories', 'mw-categories', false, $opts['categories'] );
599
600 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
601 'categories_any', 'mw-categories_any', $opts['categories_any'] );
602
603 return [ $label, $input ];
604 }
605
606 /**
607 * Filter $rows by categories set in $opts
608 *
609 * @param ResultWrapper $rows Database rows
610 * @param FormOptions $opts
611 */
612 function filterByCategories( &$rows, FormOptions $opts ) {
613 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
614
615 if ( !count( $categories ) ) {
616 return;
617 }
618
619 # Filter categories
620 $cats = [];
621 foreach ( $categories as $cat ) {
622 $cat = trim( $cat );
623 if ( $cat == '' ) {
624 continue;
625 }
626 $cats[] = $cat;
627 }
628
629 # Filter articles
630 $articles = [];
631 $a2r = [];
632 $rowsarr = [];
633 foreach ( $rows as $k => $r ) {
634 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
635 $id = $nt->getArticleID();
636 if ( $id == 0 ) {
637 continue; # Page might have been deleted...
638 }
639 if ( !in_array( $id, $articles ) ) {
640 $articles[] = $id;
641 }
642 if ( !isset( $a2r[$id] ) ) {
643 $a2r[$id] = [];
644 }
645 $a2r[$id][] = $k;
646 $rowsarr[$k] = $r;
647 }
648
649 # Shortcut?
650 if ( !count( $articles ) || !count( $cats ) ) {
651 return;
652 }
653
654 # Look up
655 $catFind = new CategoryFinder;
656 $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
657 $match = $catFind->run();
658
659 # Filter
660 $newrows = [];
661 foreach ( $match as $id ) {
662 foreach ( $a2r[$id] as $rev ) {
663 $k = $rev;
664 $newrows[$k] = $rowsarr[$k];
665 }
666 }
667 $rows = $newrows;
668 }
669
670 /**
671 * Makes change an option link which carries all the other options
672 *
673 * @param string $title Title
674 * @param array $override Options to override
675 * @param array $options Current options
676 * @param bool $active Whether to show the link in bold
677 * @return string
678 */
679 function makeOptionsLink( $title, $override, $options, $active = false ) {
680 $params = $override + $options;
681
682 // T38524: false values have be converted to "0" otherwise
683 // wfArrayToCgi() will omit it them.
684 foreach ( $params as &$value ) {
685 if ( $value === false ) {
686 $value = '0';
687 }
688 }
689 unset( $value );
690
691 if ( $active ) {
692 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
693 }
694
695 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [], $params );
696 }
697
698 /**
699 * Creates the options panel.
700 *
701 * @param array $defaults
702 * @param array $nondefaults
703 * @param int $numRows Number of rows in the result to show after this header
704 * @return string
705 */
706 function optionsPanel( $defaults, $nondefaults, $numRows ) {
707 $options = $nondefaults + $defaults;
708
709 $note = '';
710 $msg = $this->msg( 'rclegend' );
711 if ( !$msg->isDisabled() ) {
712 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
713 }
714
715 $lang = $this->getLanguage();
716 $user = $this->getUser();
717 $config = $this->getConfig();
718 if ( $options['from'] ) {
719 $note .= $this->msg( 'rcnotefrom' )
720 ->numParams( $options['limit'] )
721 ->params(
722 $lang->userTimeAndDate( $options['from'], $user ),
723 $lang->userDate( $options['from'], $user ),
724 $lang->userTime( $options['from'], $user )
725 )
726 ->numParams( $numRows )
727 ->parse() . '<br />';
728 }
729
730 # Sort data for display and make sure it's unique after we've added user data.
731 $linkLimits = $config->get( 'RCLinkLimits' );
732 $linkLimits[] = $options['limit'];
733 sort( $linkLimits );
734 $linkLimits = array_unique( $linkLimits );
735
736 $linkDays = $config->get( 'RCLinkDays' );
737 $linkDays[] = $options['days'];
738 sort( $linkDays );
739 $linkDays = array_unique( $linkDays );
740
741 // limit links
742 $cl = [];
743 foreach ( $linkLimits as $value ) {
744 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
745 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
746 }
747 $cl = $lang->pipeList( $cl );
748
749 // day links, reset 'from' to none
750 $dl = [];
751 foreach ( $linkDays as $value ) {
752 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
753 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
754 }
755 $dl = $lang->pipeList( $dl );
756
757 // show/hide links
758 $filters = [
759 'hideminor' => 'rcshowhideminor',
760 'hidebots' => 'rcshowhidebots',
761 'hideanons' => 'rcshowhideanons',
762 'hideliu' => 'rcshowhideliu',
763 'hidepatrolled' => 'rcshowhidepatr',
764 'hidemyself' => 'rcshowhidemine'
765 ];
766
767 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
768 $filters['hidecategorization'] = 'rcshowhidecategorization';
769 }
770
771 $showhide = [ 'show', 'hide' ];
772
773 foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) {
774 $filters[$key] = $params['msg'];
775 }
776
777 // Disable some if needed
778 if ( !$user->useRCPatrol() ) {
779 unset( $filters['hidepatrolled'] );
780 }
781
782 $links = [];
783 foreach ( $filters as $key => $msg ) {
784 // The following messages are used here:
785 // rcshowhideminor-show, rcshowhideminor-hide, rcshowhidebots-show, rcshowhidebots-hide,
786 // rcshowhideanons-show, rcshowhideanons-hide, rcshowhideliu-show, rcshowhideliu-hide,
787 // rcshowhidepatr-show, rcshowhidepatr-hide, rcshowhidemine-show, rcshowhidemine-hide,
788 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
789 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
790 // Extensions can define additional filters, but don't need to define the corresponding
791 // messages. If they don't exist, just fall back to 'show' and 'hide'.
792 if ( !$linkMessage->exists() ) {
793 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
794 }
795
796 $link = $this->makeOptionsLink( $linkMessage->text(),
797 [ $key => 1 - $options[$key] ], $nondefaults );
798 $links[] = "<span class=\"$msg rcshowhideoption\">"
799 . $this->msg( $msg )->rawParams( $link )->escaped() . '</span>';
800 }
801
802 // show from this onward link
803 $timestamp = wfTimestampNow();
804 $now = $lang->userTimeAndDate( $timestamp, $user );
805 $timenow = $lang->userTime( $timestamp, $user );
806 $datenow = $lang->userDate( $timestamp, $user );
807 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
808
809 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, $pipedLinks )
810 ->parse() . '</span>';
811
812 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
813 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
814 [ 'from' => $timestamp ],
815 $nondefaults
816 ) . '</span>';
817
818 return "{$note}$rclinks<br />$rclistfrom";
819 }
820
821 public function isIncludable() {
822 return true;
823 }
824
825 protected function getCacheTTL() {
826 return 60 * 5;
827 }
828
829 function filterOnUserExperienceLevel( &$tables, &$conds, &$join_conds, $opts ) {
830 global $wgLearnerEdits,
831 $wgExperiencedUserEdits,
832 $wgLearnerMemberSince,
833 $wgExperiencedUserMemberSince;
834
835 $selectedExpLevels = explode( ',', strtolower( $opts['userExpLevel'] ) );
836 // remove values that are not recognized
837 $selectedExpLevels = array_intersect(
838 $selectedExpLevels,
839 [ 'newcomer', 'learner', 'experienced' ]
840 );
841 sort( $selectedExpLevels );
842
843 if ( $selectedExpLevels ) {
844 $tables[] = 'user';
845 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
846
847 $now = time();
848 $secondsPerDay = 86400;
849 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
850 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
851
852 $aboveNewcomer = $this->getDB()->makeList(
853 [
854 'user_editcount >= ' . intval( $wgLearnerEdits ),
855 'user_registration <= ' . $this->getDB()->timestamp( $learnerCutoff ),
856 ],
857 IDatabase::LIST_AND
858 );
859
860 $aboveLearner = $this->getDB()->makeList(
861 [
862 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
863 'user_registration <= ' . $this->getDB()->timestamp( $experiencedUserCutoff ),
864 ],
865 IDatabase::LIST_AND
866 );
867
868 if ( $selectedExpLevels === [ 'newcomer' ] ) {
869 $conds[] = "NOT ( $aboveNewcomer )";
870 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
871 $conds[] = $this->getDB()->makeList(
872 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
873 IDatabase::LIST_AND
874 );
875 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
876 $conds[] = $aboveLearner;
877 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
878 $conds[] = "NOT ( $aboveLearner )";
879 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
880 $conds[] = $this->getDB()->makeList(
881 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
882 IDatabase::LIST_OR
883 );
884 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
885 $conds[] = $aboveNewcomer;
886 }
887 }
888 }
889
890 }