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