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