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