Merge "RCFilters UI: Correct filter name font-size"
[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(
460 'rcenhancedfilters',
461 /*default=*/ null,
462 /*ignoreHidden=*/ true
463 )
464 ) {
465 $this->getOutput()->addHTML(
466 Html::element(
467 'div',
468 [ 'class' => 'rcfilters-container' ]
469 )
470 );
471 }
472
473 $this->getOutput()->addHTML(
474 Xml::fieldset(
475 $this->msg( 'recentchanges-legend' )->text(),
476 $panelString,
477 [ 'class' => 'rcoptions' ]
478 )
479 );
480
481 $this->setBottomText( $opts );
482 }
483
484 /**
485 * Send the text to be displayed above the options
486 *
487 * @param FormOptions $opts Unused
488 */
489 function setTopText( FormOptions $opts ) {
490 global $wgContLang;
491
492 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
493 if ( !$message->isDisabled() ) {
494 $this->getOutput()->addWikiText(
495 Html::rawElement( 'div',
496 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
497 "\n" . $message->plain() . "\n"
498 ),
499 /* $lineStart */ true,
500 /* $interface */ false
501 );
502 }
503 }
504
505 /**
506 * Get options to be displayed in a form
507 *
508 * @param FormOptions $opts
509 * @return array
510 */
511 function getExtraOptions( $opts ) {
512 $opts->consumeValues( [
513 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
514 ] );
515
516 $extraOpts = [];
517 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
518
519 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
520 $extraOpts['category'] = $this->categoryFilterForm( $opts );
521 }
522
523 $tagFilter = ChangeTags::buildTagFilterSelector(
524 $opts['tagfilter'], false, $this->getContext() );
525 if ( count( $tagFilter ) ) {
526 $extraOpts['tagfilter'] = $tagFilter;
527 }
528
529 // Don't fire the hook for subclasses. (Or should we?)
530 if ( $this->getName() === 'Recentchanges' ) {
531 Hooks::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
532 }
533
534 return $extraOpts;
535 }
536
537 /**
538 * Add page-specific modules.
539 */
540 protected function addModules() {
541 parent::addModules();
542 $out = $this->getOutput();
543 $out->addModules( 'mediawiki.special.recentchanges' );
544 if ( $this->getUser()->getOption(
545 'rcenhancedfilters',
546 /*default=*/ null,
547 /*ignoreHidden=*/ true
548 )
549 ) {
550 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
551 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
552 }
553 }
554
555 /**
556 * Get last modified date, for client caching
557 * Don't use this if we are using the patrol feature, patrol changes don't
558 * update the timestamp
559 *
560 * @return string|bool
561 */
562 public function checkLastModified() {
563 $dbr = $this->getDB();
564 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
565
566 return $lastmod;
567 }
568
569 /**
570 * Creates the choose namespace selection
571 *
572 * @param FormOptions $opts
573 * @return string
574 */
575 protected function namespaceFilterForm( FormOptions $opts ) {
576 $nsSelect = Html::namespaceSelector(
577 [ 'selected' => $opts['namespace'], 'all' => '' ],
578 [ 'name' => 'namespace', 'id' => 'namespace' ]
579 );
580 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
581 $invert = Xml::checkLabel(
582 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
583 $opts['invert'],
584 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
585 );
586 $associated = Xml::checkLabel(
587 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
588 $opts['associated'],
589 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
590 );
591
592 return [ $nsLabel, "$nsSelect $invert $associated" ];
593 }
594
595 /**
596 * Create an input to filter changes by categories
597 *
598 * @param FormOptions $opts
599 * @return array
600 */
601 protected function categoryFilterForm( FormOptions $opts ) {
602 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
603 'categories', 'mw-categories', false, $opts['categories'] );
604
605 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
606 'categories_any', 'mw-categories_any', $opts['categories_any'] );
607
608 return [ $label, $input ];
609 }
610
611 /**
612 * Filter $rows by categories set in $opts
613 *
614 * @param ResultWrapper $rows Database rows
615 * @param FormOptions $opts
616 */
617 function filterByCategories( &$rows, FormOptions $opts ) {
618 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
619
620 if ( !count( $categories ) ) {
621 return;
622 }
623
624 # Filter categories
625 $cats = [];
626 foreach ( $categories as $cat ) {
627 $cat = trim( $cat );
628 if ( $cat == '' ) {
629 continue;
630 }
631 $cats[] = $cat;
632 }
633
634 # Filter articles
635 $articles = [];
636 $a2r = [];
637 $rowsarr = [];
638 foreach ( $rows as $k => $r ) {
639 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
640 $id = $nt->getArticleID();
641 if ( $id == 0 ) {
642 continue; # Page might have been deleted...
643 }
644 if ( !in_array( $id, $articles ) ) {
645 $articles[] = $id;
646 }
647 if ( !isset( $a2r[$id] ) ) {
648 $a2r[$id] = [];
649 }
650 $a2r[$id][] = $k;
651 $rowsarr[$k] = $r;
652 }
653
654 # Shortcut?
655 if ( !count( $articles ) || !count( $cats ) ) {
656 return;
657 }
658
659 # Look up
660 $catFind = new CategoryFinder;
661 $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
662 $match = $catFind->run();
663
664 # Filter
665 $newrows = [];
666 foreach ( $match as $id ) {
667 foreach ( $a2r[$id] as $rev ) {
668 $k = $rev;
669 $newrows[$k] = $rowsarr[$k];
670 }
671 }
672 $rows = $newrows;
673 }
674
675 /**
676 * Makes change an option link which carries all the other options
677 *
678 * @param string $title Title
679 * @param array $override Options to override
680 * @param array $options Current options
681 * @param bool $active Whether to show the link in bold
682 * @return string
683 */
684 function makeOptionsLink( $title, $override, $options, $active = false ) {
685 $params = $override + $options;
686
687 // T38524: false values have be converted to "0" otherwise
688 // wfArrayToCgi() will omit it them.
689 foreach ( $params as &$value ) {
690 if ( $value === false ) {
691 $value = '0';
692 }
693 }
694 unset( $value );
695
696 if ( $active ) {
697 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
698 }
699
700 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [], $params );
701 }
702
703 /**
704 * Creates the options panel.
705 *
706 * @param array $defaults
707 * @param array $nondefaults
708 * @param int $numRows Number of rows in the result to show after this header
709 * @return string
710 */
711 function optionsPanel( $defaults, $nondefaults, $numRows ) {
712 $options = $nondefaults + $defaults;
713
714 $note = '';
715 $msg = $this->msg( 'rclegend' );
716 if ( !$msg->isDisabled() ) {
717 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
718 }
719
720 $lang = $this->getLanguage();
721 $user = $this->getUser();
722 $config = $this->getConfig();
723 if ( $options['from'] ) {
724 $note .= $this->msg( 'rcnotefrom' )
725 ->numParams( $options['limit'] )
726 ->params(
727 $lang->userTimeAndDate( $options['from'], $user ),
728 $lang->userDate( $options['from'], $user ),
729 $lang->userTime( $options['from'], $user )
730 )
731 ->numParams( $numRows )
732 ->parse() . '<br />';
733 }
734
735 # Sort data for display and make sure it's unique after we've added user data.
736 $linkLimits = $config->get( 'RCLinkLimits' );
737 $linkLimits[] = $options['limit'];
738 sort( $linkLimits );
739 $linkLimits = array_unique( $linkLimits );
740
741 $linkDays = $config->get( 'RCLinkDays' );
742 $linkDays[] = $options['days'];
743 sort( $linkDays );
744 $linkDays = array_unique( $linkDays );
745
746 // limit links
747 $cl = [];
748 foreach ( $linkLimits as $value ) {
749 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
750 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
751 }
752 $cl = $lang->pipeList( $cl );
753
754 // day links, reset 'from' to none
755 $dl = [];
756 foreach ( $linkDays as $value ) {
757 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
758 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
759 }
760 $dl = $lang->pipeList( $dl );
761
762 // show/hide links
763 $filters = [
764 'hideminor' => 'rcshowhideminor',
765 'hidebots' => 'rcshowhidebots',
766 'hideanons' => 'rcshowhideanons',
767 'hideliu' => 'rcshowhideliu',
768 'hidepatrolled' => 'rcshowhidepatr',
769 'hidemyself' => 'rcshowhidemine'
770 ];
771
772 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
773 $filters['hidecategorization'] = 'rcshowhidecategorization';
774 }
775
776 $showhide = [ 'show', 'hide' ];
777
778 foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) {
779 $filters[$key] = $params['msg'];
780 }
781
782 // Disable some if needed
783 if ( !$user->useRCPatrol() ) {
784 unset( $filters['hidepatrolled'] );
785 }
786
787 $links = [];
788 foreach ( $filters as $key => $msg ) {
789 // The following messages are used here:
790 // rcshowhideminor-show, rcshowhideminor-hide, rcshowhidebots-show, rcshowhidebots-hide,
791 // rcshowhideanons-show, rcshowhideanons-hide, rcshowhideliu-show, rcshowhideliu-hide,
792 // rcshowhidepatr-show, rcshowhidepatr-hide, rcshowhidemine-show, rcshowhidemine-hide,
793 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
794 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
795 // Extensions can define additional filters, but don't need to define the corresponding
796 // messages. If they don't exist, just fall back to 'show' and 'hide'.
797 if ( !$linkMessage->exists() ) {
798 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
799 }
800
801 $link = $this->makeOptionsLink( $linkMessage->text(),
802 [ $key => 1 - $options[$key] ], $nondefaults );
803 $links[] = "<span class=\"$msg rcshowhideoption\">"
804 . $this->msg( $msg )->rawParams( $link )->escaped() . '</span>';
805 }
806
807 // show from this onward link
808 $timestamp = wfTimestampNow();
809 $now = $lang->userTimeAndDate( $timestamp, $user );
810 $timenow = $lang->userTime( $timestamp, $user );
811 $datenow = $lang->userDate( $timestamp, $user );
812 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
813
814 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, $pipedLinks )
815 ->parse() . '</span>';
816
817 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
818 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
819 [ 'from' => $timestamp ],
820 $nondefaults
821 ) . '</span>';
822
823 return "{$note}$rclinks<br />$rclistfrom";
824 }
825
826 public function isIncludable() {
827 return true;
828 }
829
830 protected function getCacheTTL() {
831 return 60 * 5;
832 }
833
834 function filterOnUserExperienceLevel( &$tables, &$conds, &$join_conds, $opts ) {
835 global $wgLearnerEdits,
836 $wgExperiencedUserEdits,
837 $wgLearnerMemberSince,
838 $wgExperiencedUserMemberSince;
839
840 $selectedExpLevels = explode( ',', strtolower( $opts['userExpLevel'] ) );
841 // remove values that are not recognized
842 $selectedExpLevels = array_intersect(
843 $selectedExpLevels,
844 [ 'newcomer', 'learner', 'experienced' ]
845 );
846 sort( $selectedExpLevels );
847
848 if ( $selectedExpLevels ) {
849 $tables[] = 'user';
850 $join_conds['user'] = [ 'LEFT JOIN', 'rc_user = user_id' ];
851
852 $now = time();
853 $secondsPerDay = 86400;
854 $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
855 $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
856
857 $aboveNewcomer = $this->getDB()->makeList(
858 [
859 'user_editcount >= ' . intval( $wgLearnerEdits ),
860 'user_registration <= ' . $this->getDB()->timestamp( $learnerCutoff ),
861 ],
862 IDatabase::LIST_AND
863 );
864
865 $aboveLearner = $this->getDB()->makeList(
866 [
867 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
868 'user_registration <= ' . $this->getDB()->timestamp( $experiencedUserCutoff ),
869 ],
870 IDatabase::LIST_AND
871 );
872
873 if ( $selectedExpLevels === [ 'newcomer' ] ) {
874 $conds[] = "NOT ( $aboveNewcomer )";
875 } elseif ( $selectedExpLevels === [ 'learner' ] ) {
876 $conds[] = $this->getDB()->makeList(
877 [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
878 IDatabase::LIST_AND
879 );
880 } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
881 $conds[] = $aboveLearner;
882 } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
883 $conds[] = "NOT ( $aboveLearner )";
884 } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
885 $conds[] = $this->getDB()->makeList(
886 [ "NOT ( $aboveNewcomer )", $aboveLearner ],
887 IDatabase::LIST_OR
888 );
889 } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
890 $conds[] = $aboveNewcomer;
891 }
892 }
893 }
894
895 }