Merge "Http::getProxy() method to get proxy configuration"
[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 $dbr->selectField(
348 'watchlist',
349 'COUNT(*)',
350 [
351 'wl_namespace' => $obj->rc_namespace,
352 'wl_title' => $obj->rc_title,
353 ],
354 __METHOD__ . '-watchers'
355 );
356 }
357 $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
358 }
359
360 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
361 if ( $changeLine !== false ) {
362 $rclistOutput .= $changeLine;
363 --$limit;
364 }
365 }
366 $rclistOutput .= $list->endRecentChangesList();
367
368 if ( $rows->numRows() === 0 ) {
369 $this->getOutput()->addHTML(
370 '<div class="mw-changeslist-empty">' .
371 $this->msg( 'recentchanges-noresult' )->parse() .
372 '</div>'
373 );
374 if ( !$this->including() ) {
375 $this->getOutput()->setStatusCode( 404 );
376 }
377 } else {
378 $this->getOutput()->addHTML( $rclistOutput );
379 }
380 }
381
382 /**
383 * Set the text to be displayed above the changes
384 *
385 * @param FormOptions $opts
386 * @param int $numRows Number of rows in the result to show after this header
387 */
388 public function doHeader( $opts, $numRows ) {
389 $this->setTopText( $opts );
390
391 $defaults = $opts->getAllValues();
392 $nondefaults = $opts->getChangedValues();
393
394 $panel = [];
395 $panel[] = $this->makeLegend();
396 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
397 $panel[] = '<hr />';
398
399 $extraOpts = $this->getExtraOptions( $opts );
400 $extraOptsCount = count( $extraOpts );
401 $count = 0;
402 $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
403
404 $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
405 foreach ( $extraOpts as $name => $optionRow ) {
406 # Add submit button to the last row only
407 ++$count;
408 $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
409
410 $out .= Xml::openElement( 'tr' );
411 if ( is_array( $optionRow ) ) {
412 $out .= Xml::tags(
413 'td',
414 [ 'class' => 'mw-label mw-' . $name . '-label' ],
415 $optionRow[0]
416 );
417 $out .= Xml::tags(
418 'td',
419 [ 'class' => 'mw-input' ],
420 $optionRow[1] . $addSubmit
421 );
422 } else {
423 $out .= Xml::tags(
424 'td',
425 [ 'class' => 'mw-input', 'colspan' => 2 ],
426 $optionRow . $addSubmit
427 );
428 }
429 $out .= Xml::closeElement( 'tr' );
430 }
431 $out .= Xml::closeElement( 'table' );
432
433 $unconsumed = $opts->getUnconsumedValues();
434 foreach ( $unconsumed as $key => $value ) {
435 $out .= Html::hidden( $key, $value );
436 }
437
438 $t = $this->getPageTitle();
439 $out .= Html::hidden( 'title', $t->getPrefixedText() );
440 $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
441 $panel[] = $form;
442 $panelString = implode( "\n", $panel );
443
444 $this->getOutput()->addHTML(
445 Xml::fieldset(
446 $this->msg( 'recentchanges-legend' )->text(),
447 $panelString,
448 [ 'class' => 'rcoptions' ]
449 )
450 );
451
452 $this->setBottomText( $opts );
453 }
454
455 /**
456 * Send the text to be displayed above the options
457 *
458 * @param FormOptions $opts Unused
459 */
460 function setTopText( FormOptions $opts ) {
461 global $wgContLang;
462
463 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
464 if ( !$message->isDisabled() ) {
465 $this->getOutput()->addWikiText(
466 Html::rawElement( 'div',
467 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
468 "\n" . $message->plain() . "\n"
469 ),
470 /* $lineStart */ true,
471 /* $interface */ false
472 );
473 }
474 }
475
476 /**
477 * Get options to be displayed in a form
478 *
479 * @param FormOptions $opts
480 * @return array
481 */
482 function getExtraOptions( $opts ) {
483 $opts->consumeValues( [
484 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
485 ] );
486
487 $extraOpts = [];
488 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
489
490 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
491 $extraOpts['category'] = $this->categoryFilterForm( $opts );
492 }
493
494 $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
495 if ( count( $tagFilter ) ) {
496 $extraOpts['tagfilter'] = $tagFilter;
497 }
498
499 // Don't fire the hook for subclasses. (Or should we?)
500 if ( $this->getName() === 'Recentchanges' ) {
501 Hooks::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
502 }
503
504 return $extraOpts;
505 }
506
507 /**
508 * Add page-specific modules.
509 */
510 protected function addModules() {
511 parent::addModules();
512 $out = $this->getOutput();
513 $out->addModules( 'mediawiki.special.recentchanges' );
514 }
515
516 /**
517 * Get last modified date, for client caching
518 * Don't use this if we are using the patrol feature, patrol changes don't
519 * update the timestamp
520 *
521 * @return string|bool
522 */
523 public function checkLastModified() {
524 $dbr = $this->getDB();
525 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
526
527 return $lastmod;
528 }
529
530 /**
531 * Creates the choose namespace selection
532 *
533 * @param FormOptions $opts
534 * @return string
535 */
536 protected function namespaceFilterForm( FormOptions $opts ) {
537 $nsSelect = Html::namespaceSelector(
538 [ 'selected' => $opts['namespace'], 'all' => '' ],
539 [ 'name' => 'namespace', 'id' => 'namespace' ]
540 );
541 $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
542 $invert = Xml::checkLabel(
543 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
544 $opts['invert'],
545 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
546 );
547 $associated = Xml::checkLabel(
548 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
549 $opts['associated'],
550 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
551 );
552
553 return [ $nsLabel, "$nsSelect $invert $associated" ];
554 }
555
556 /**
557 * Create an input to filter changes by categories
558 *
559 * @param FormOptions $opts
560 * @return array
561 */
562 protected function categoryFilterForm( FormOptions $opts ) {
563 list( $label, $input ) = Xml::inputLabelSep( $this->msg( 'rc_categories' )->text(),
564 'categories', 'mw-categories', false, $opts['categories'] );
565
566 $input .= ' ' . Xml::checkLabel( $this->msg( 'rc_categories_any' )->text(),
567 'categories_any', 'mw-categories_any', $opts['categories_any'] );
568
569 return [ $label, $input ];
570 }
571
572 /**
573 * Filter $rows by categories set in $opts
574 *
575 * @param ResultWrapper $rows Database rows
576 * @param FormOptions $opts
577 */
578 function filterByCategories( &$rows, FormOptions $opts ) {
579 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
580
581 if ( !count( $categories ) ) {
582 return;
583 }
584
585 # Filter categories
586 $cats = [];
587 foreach ( $categories as $cat ) {
588 $cat = trim( $cat );
589 if ( $cat == '' ) {
590 continue;
591 }
592 $cats[] = $cat;
593 }
594
595 # Filter articles
596 $articles = [];
597 $a2r = [];
598 $rowsarr = [];
599 foreach ( $rows as $k => $r ) {
600 $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
601 $id = $nt->getArticleID();
602 if ( $id == 0 ) {
603 continue; # Page might have been deleted...
604 }
605 if ( !in_array( $id, $articles ) ) {
606 $articles[] = $id;
607 }
608 if ( !isset( $a2r[$id] ) ) {
609 $a2r[$id] = [];
610 }
611 $a2r[$id][] = $k;
612 $rowsarr[$k] = $r;
613 }
614
615 # Shortcut?
616 if ( !count( $articles ) || !count( $cats ) ) {
617 return;
618 }
619
620 # Look up
621 $catFind = new CategoryFinder;
622 $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
623 $match = $catFind->run();
624
625 # Filter
626 $newrows = [];
627 foreach ( $match as $id ) {
628 foreach ( $a2r[$id] as $rev ) {
629 $k = $rev;
630 $newrows[$k] = $rowsarr[$k];
631 }
632 }
633 $rows = $newrows;
634 }
635
636 /**
637 * Makes change an option link which carries all the other options
638 *
639 * @param string $title Title
640 * @param array $override Options to override
641 * @param array $options Current options
642 * @param bool $active Whether to show the link in bold
643 * @return string
644 */
645 function makeOptionsLink( $title, $override, $options, $active = false ) {
646 $params = $override + $options;
647
648 // Bug 36524: false values have be converted to "0" otherwise
649 // wfArrayToCgi() will omit it them.
650 foreach ( $params as &$value ) {
651 if ( $value === false ) {
652 $value = '0';
653 }
654 }
655 unset( $value );
656
657 $text = htmlspecialchars( $title );
658 if ( $active ) {
659 $text = '<strong>' . $text . '</strong>';
660 }
661
662 return Linker::linkKnown( $this->getPageTitle(), $text, [], $params );
663 }
664
665 /**
666 * Creates the options panel.
667 *
668 * @param array $defaults
669 * @param array $nondefaults
670 * @param int $numRows Number of rows in the result to show after this header
671 * @return string
672 */
673 function optionsPanel( $defaults, $nondefaults, $numRows ) {
674 $options = $nondefaults + $defaults;
675
676 $note = '';
677 $msg = $this->msg( 'rclegend' );
678 if ( !$msg->isDisabled() ) {
679 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
680 }
681
682 $lang = $this->getLanguage();
683 $user = $this->getUser();
684 $config = $this->getConfig();
685 if ( $options['from'] ) {
686 $note .= $this->msg( 'rcnotefrom' )
687 ->numParams( $options['limit'] )
688 ->params(
689 $lang->userTimeAndDate( $options['from'], $user ),
690 $lang->userDate( $options['from'], $user ),
691 $lang->userTime( $options['from'], $user )
692 )
693 ->numParams( $numRows )
694 ->parse() . '<br />';
695 }
696
697 # Sort data for display and make sure it's unique after we've added user data.
698 $linkLimits = $config->get( 'RCLinkLimits' );
699 $linkLimits[] = $options['limit'];
700 sort( $linkLimits );
701 $linkLimits = array_unique( $linkLimits );
702
703 $linkDays = $config->get( 'RCLinkDays' );
704 $linkDays[] = $options['days'];
705 sort( $linkDays );
706 $linkDays = array_unique( $linkDays );
707
708 // limit links
709 $cl = [];
710 foreach ( $linkLimits as $value ) {
711 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
712 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
713 }
714 $cl = $lang->pipeList( $cl );
715
716 // day links, reset 'from' to none
717 $dl = [];
718 foreach ( $linkDays as $value ) {
719 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
720 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
721 }
722 $dl = $lang->pipeList( $dl );
723
724 // show/hide links
725 $filters = [
726 'hideminor' => 'rcshowhideminor',
727 'hidebots' => 'rcshowhidebots',
728 'hideanons' => 'rcshowhideanons',
729 'hideliu' => 'rcshowhideliu',
730 'hidepatrolled' => 'rcshowhidepatr',
731 'hidemyself' => 'rcshowhidemine'
732 ];
733
734 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
735 $filters['hidecategorization'] = 'rcshowhidecategorization';
736 }
737
738 $showhide = [ 'show', 'hide' ];
739
740 foreach ( $this->getCustomFilters() as $key => $params ) {
741 $filters[$key] = $params['msg'];
742 }
743 // Disable some if needed
744 if ( !$user->useRCPatrol() ) {
745 unset( $filters['hidepatrolled'] );
746 }
747
748 $links = [];
749 foreach ( $filters as $key => $msg ) {
750 // The following messages are used here:
751 // rcshowhideminor-show, rcshowhideminor-hide, rcshowhidebots-show, rcshowhidebots-hide,
752 // rcshowhideanons-show, rcshowhideanons-hide, rcshowhideliu-show, rcshowhideliu-hide,
753 // rcshowhidepatr-show, rcshowhidepatr-hide, rcshowhidemine-show, rcshowhidemine-hide,
754 // rcshowhidecategorization-show, rcshowhidecategorization-hide.
755 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
756 // Extensions can define additional filters, but don't need to define the corresponding
757 // messages. If they don't exist, just fall back to 'show' and 'hide'.
758 if ( !$linkMessage->exists() ) {
759 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
760 }
761
762 $link = $this->makeOptionsLink( $linkMessage->text(),
763 [ $key => 1 - $options[$key] ], $nondefaults );
764 $links[] = "<span class=\"$msg rcshowhideoption\">"
765 . $this->msg( $msg )->rawParams( $link )->escaped() . '</span>';
766 }
767
768 // show from this onward link
769 $timestamp = wfTimestampNow();
770 $now = $lang->userTimeAndDate( $timestamp, $user );
771 $timenow = $lang->userTime( $timestamp, $user );
772 $datenow = $lang->userDate( $timestamp, $user );
773 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
774
775 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, $pipedLinks )
776 ->parse() . '</span>';
777
778 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
779 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
780 [ 'from' => $timestamp ],
781 $nondefaults
782 ) . '</span>';
783
784 return "{$note}$rclinks<br />$rclistfrom";
785 }
786
787 public function isIncludable() {
788 return true;
789 }
790 }