MediaWiki  master
SpecialRecentChanges.php
Go to the documentation of this file.
1 <?php
26 
33 
34  protected static $savedQueriesPreferenceName = 'rcfilters-saved-queries';
35  protected static $daysPreferenceName = 'rcdays'; // Use general RecentChanges preference
36  protected static $limitPreferenceName = 'rcfilters-limit'; // Use RCFilters-specific preference
37  protected static $collapsedPreferenceName = 'rcfilters-rc-collapsed';
38 
40 
41  public function __construct( $name = 'Recentchanges', $restriction = '' ) {
42  parent::__construct( $name, $restriction );
43 
44  $this->watchlistFilterGroupDefinition = [
45  'name' => 'watchlist',
46  'title' => 'rcfilters-filtergroup-watchlist',
47  'class' => ChangesListStringOptionsFilterGroup::class,
48  'priority' => -9,
49  'isFullCoverage' => true,
50  'filters' => [
51  [
52  'name' => 'watched',
53  'label' => 'rcfilters-filter-watchlist-watched-label',
54  'description' => 'rcfilters-filter-watchlist-watched-description',
55  'cssClassSuffix' => 'watched',
56  'isRowApplicableCallable' => function ( $ctx, $rc ) {
57  return $rc->getAttribute( 'wl_user' );
58  }
59  ],
60  [
61  'name' => 'watchednew',
62  'label' => 'rcfilters-filter-watchlist-watchednew-label',
63  'description' => 'rcfilters-filter-watchlist-watchednew-description',
64  'cssClassSuffix' => 'watchednew',
65  'isRowApplicableCallable' => function ( $ctx, $rc ) {
66  return $rc->getAttribute( 'wl_user' ) &&
67  $rc->getAttribute( 'rc_timestamp' ) &&
68  $rc->getAttribute( 'wl_notificationtimestamp' ) &&
69  $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
70  },
71  ],
72  [
73  'name' => 'notwatched',
74  'label' => 'rcfilters-filter-watchlist-notwatched-label',
75  'description' => 'rcfilters-filter-watchlist-notwatched-description',
76  'cssClassSuffix' => 'notwatched',
77  'isRowApplicableCallable' => function ( $ctx, $rc ) {
78  return $rc->getAttribute( 'wl_user' ) === null;
79  },
80  ]
81  ],
83  'queryCallable' => function ( $specialPageClassName, $context, $dbr,
84  &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
85  sort( $selectedValues );
86  $notwatchedCond = 'wl_user IS NULL';
87  $watchedCond = 'wl_user IS NOT NULL';
88  $newCond = 'rc_timestamp >= wl_notificationtimestamp';
89 
90  if ( $selectedValues === [ 'notwatched' ] ) {
91  $conds[] = $notwatchedCond;
92  return;
93  }
94 
95  if ( $selectedValues === [ 'watched' ] ) {
96  $conds[] = $watchedCond;
97  return;
98  }
99 
100  if ( $selectedValues === [ 'watchednew' ] ) {
101  $conds[] = $dbr->makeList( [
102  $watchedCond,
103  $newCond
104  ], LIST_AND );
105  return;
106  }
107 
108  if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
109  // no filters
110  return;
111  }
112 
113  if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
114  $conds[] = $dbr->makeList( [
115  $notwatchedCond,
116  $dbr->makeList( [
117  $watchedCond,
118  $newCond
119  ], LIST_AND )
120  ], LIST_OR );
121  return;
122  }
123 
124  if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
125  $conds[] = $watchedCond;
126  return;
127  }
128 
129  if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
130  // no filters
131  return;
132  }
133  }
134  ];
135  }
136 
140  public function execute( $subpage ) {
141  // Backwards-compatibility: redirect to new feed URLs
142  $feedFormat = $this->getRequest()->getVal( 'feed' );
143  if ( !$this->including() && $feedFormat ) {
144  $query = $this->getFeedQuery();
145  $query['feedformat'] = $feedFormat === 'atom' ? 'atom' : 'rss';
146  $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
147 
148  return;
149  }
150 
151  // 10 seconds server-side caching max
152  $out = $this->getOutput();
153  $out->setCdnMaxage( 10 );
154  // Check if the client has a cached version
155  $lastmod = $this->checkLastModified();
156  if ( $lastmod === false ) {
157  return;
158  }
159 
160  $this->addHelpLink(
161  'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
162  true
163  );
164  parent::execute( $subpage );
165  }
166 
170  protected function transformFilterDefinition( array $filterDefinition ) {
171  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
172  $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
173  }
174 
175  return $filterDefinition;
176  }
177 
181  protected function registerFilters() {
182  parent::registerFilters();
183 
184  if (
185  !$this->including() &&
186  $this->getUser()->isLoggedIn() &&
187  MediaWikiServices::getInstance()
189  ->userHasRight( $this->getUser(), 'viewmywatchlist' )
190  ) {
191  $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition ] );
192  $watchlistGroup = $this->getFilterGroup( 'watchlist' );
193  $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
194  $watchlistGroup->getFilter( 'watchednew' )
195  );
196  }
197 
198  $user = $this->getUser();
199 
200  $significance = $this->getFilterGroup( 'significance' );
202  $hideMinor = $significance->getFilter( 'hideminor' );
203  '@phan-var ChangesListBooleanFilter $hideMinor';
204  $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
205 
206  $automated = $this->getFilterGroup( 'automated' );
208  $hideBots = $automated->getFilter( 'hidebots' );
209  '@phan-var ChangesListBooleanFilter $hideBots';
210  $hideBots->setDefault( true );
211 
213  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
214  '@phan-var ChangesListStringOptionsFilterGroup|null $reviewStatus';
215  if ( $reviewStatus !== null ) {
216  // Conditional on feature being available and rights
217  if ( $user->getBoolOption( 'hidepatrolled' ) ) {
218  $reviewStatus->setDefault( 'unpatrolled' );
219  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
221  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
222  '@phan-var ChangesListBooleanFilter $legacyHidePatrolled';
223  $legacyHidePatrolled->setDefault( true );
224  }
225  }
226 
227  $changeType = $this->getFilterGroup( 'changeType' );
229  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
230  '@phan-var ChangesListBooleanFilter $hideCategorization';
231  if ( $hideCategorization !== null ) {
232  // Conditional on feature being available
233  $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
234  }
235  }
236 
243  public function parseParameters( $par, FormOptions $opts ) {
244  parent::parseParameters( $par, $opts );
245 
246  $bits = preg_split( '/\s*,\s*/', trim( $par ) );
247  foreach ( $bits as $bit ) {
248  if ( is_numeric( $bit ) ) {
249  $opts['limit'] = $bit;
250  }
251 
252  $m = [];
253  if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
254  $opts['limit'] = $m[1];
255  }
256  if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
257  $opts['days'] = $m[1];
258  }
259  if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
260  $opts['namespace'] = $m[1];
261  }
262  if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
263  $opts['tagfilter'] = $m[1];
264  }
265  }
266  }
267 
271  protected function doMainQuery( $tables, $fields, $conds, $query_options,
272  $join_conds, FormOptions $opts
273  ) {
274  $dbr = $this->getDB();
275  $user = $this->getUser();
276 
277  $rcQuery = RecentChange::getQueryInfo();
278  $tables = array_merge( $tables, $rcQuery['tables'] );
279  $fields = array_merge( $rcQuery['fields'], $fields );
280  $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
281 
282  // JOIN on watchlist for users
283  if ( $user->isLoggedIn() && MediaWikiServices::getInstance()
284  ->getPermissionManager()
285  ->userHasRight( $user, 'viewmywatchlist' )
286  ) {
287  $tables[] = 'watchlist';
288  $fields[] = 'wl_user';
289  $fields[] = 'wl_notificationtimestamp';
290  $join_conds['watchlist'] = [ 'LEFT JOIN', [
291  'wl_user' => $user->getId(),
292  'wl_title=rc_title',
293  'wl_namespace=rc_namespace'
294  ] ];
295  }
296 
297  // JOIN on page, used for 'last revision' filter highlight
298  $tables[] = 'page';
299  $fields[] = 'page_latest';
300  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
301 
302  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
304  $tables,
305  $fields,
306  $conds,
307  $join_conds,
308  $query_options,
309  $tagFilter
310  );
311 
312  if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
313  $opts )
314  ) {
315  return false;
316  }
317 
318  if ( $this->areFiltersInConflict() ) {
319  return false;
320  }
321 
322  $orderByAndLimit = [
323  'ORDER BY' => 'rc_timestamp DESC',
324  'LIMIT' => $opts['limit']
325  ];
326  if ( in_array( 'DISTINCT', $query_options ) ) {
327  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
328  // In order to prevent DISTINCT from causing query performance problems,
329  // we have to GROUP BY the primary key. This in turn requires us to add
330  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
331  // start of the GROUP BY
332  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
333  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
334  }
335  // array_merge() is used intentionally here so that hooks can, should
336  // they so desire, override the ORDER BY / LIMIT condition(s); prior to
337  // MediaWiki 1.26 this used to use the plus operator instead, which meant
338  // that extensions weren't able to change these conditions
339  $query_options = array_merge( $orderByAndLimit, $query_options );
340  $rows = $dbr->select(
341  $tables,
342  $fields,
343  // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
344  // knowledge to use an index merge if it wants (it may use some other index though).
345  $conds + [ 'rc_new' => [ 0, 1 ] ],
346  __METHOD__,
347  $query_options,
348  $join_conds
349  );
350 
351  return $rows;
352  }
353 
354  protected function getDB() {
355  return wfGetDB( DB_REPLICA, 'recentchanges' );
356  }
357 
358  public function outputFeedLinks() {
359  $this->addFeedLinks( $this->getFeedQuery() );
360  }
361 
367  protected function getFeedQuery() {
368  $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
369  // API handles empty parameters in a different way
370  return $value !== '';
371  } );
372  $query['action'] = 'feedrecentchanges';
373  $feedLimit = $this->getConfig()->get( 'FeedLimit' );
374  if ( $query['limit'] > $feedLimit ) {
375  $query['limit'] = $feedLimit;
376  }
377 
378  return $query;
379  }
380 
387  public function outputChangesList( $rows, $opts ) {
388  $limit = $opts['limit'];
389 
390  $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
391  && $this->getUser()->getOption( 'shownumberswatching' );
392  $watcherCache = [];
393 
394  $counter = 1;
395  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
396  $list->initChangesListRows( $rows );
397 
398  $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
399  $rclistOutput = $list->beginRecentChangesList();
400  if ( $this->isStructuredFilterUiEnabled() ) {
401  $rclistOutput .= $this->makeLegend();
402  }
403 
404  foreach ( $rows as $obj ) {
405  if ( $limit == 0 ) {
406  break;
407  }
408  $rc = RecentChange::newFromRow( $obj );
409 
410  # Skip CatWatch entries for hidden cats based on user preference
411  if (
412  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
413  !$userShowHiddenCats &&
414  $rc->getParam( 'hidden-cat' )
415  ) {
416  continue;
417  }
418 
419  $rc->counter = $counter++;
420  # Check if the page has been updated since the last visit
421  if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
422  && !empty( $obj->wl_notificationtimestamp )
423  ) {
424  $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
425  } else {
426  $rc->notificationtimestamp = false; // Default
427  }
428  # Check the number of users watching the page
429  $rc->numberofWatchingusers = 0; // Default
430  if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
431  if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
432  $watcherCache[$obj->rc_namespace][$obj->rc_title] =
433  MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchers(
434  new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
435  );
436  }
437  $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
438  }
439 
440  $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
441  if ( $changeLine !== false ) {
442  $rclistOutput .= $changeLine;
443  --$limit;
444  }
445  }
446  $rclistOutput .= $list->endRecentChangesList();
447 
448  if ( $rows->numRows() === 0 ) {
449  $this->outputNoResults();
450  if ( !$this->including() ) {
451  $this->getOutput()->setStatusCode( 404 );
452  }
453  } else {
454  $this->getOutput()->addHTML( $rclistOutput );
455  }
456  }
457 
464  public function doHeader( $opts, $numRows ) {
465  $this->setTopText( $opts );
466 
467  $defaults = $opts->getAllValues();
468  $nondefaults = $opts->getChangedValues();
469 
470  $panel = [];
471  if ( !$this->isStructuredFilterUiEnabled() ) {
472  $panel[] = $this->makeLegend();
473  }
474  $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
475  $panel[] = '<hr />';
476 
477  $extraOpts = $this->getExtraOptions( $opts );
478  $extraOptsCount = count( $extraOpts );
479  $count = 0;
480  $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
481 
482  $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
483  foreach ( $extraOpts as $name => $optionRow ) {
484  # Add submit button to the last row only
485  ++$count;
486  $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
487 
488  $out .= Xml::openElement( 'tr', [ 'class' => $name . 'Form' ] );
489  if ( is_array( $optionRow ) ) {
490  $out .= Xml::tags(
491  'td',
492  [ 'class' => 'mw-label mw-' . $name . '-label' ],
493  $optionRow[0]
494  );
495  $out .= Xml::tags(
496  'td',
497  [ 'class' => 'mw-input' ],
498  $optionRow[1] . $addSubmit
499  );
500  } else {
501  $out .= Xml::tags(
502  'td',
503  [ 'class' => 'mw-input', 'colspan' => 2 ],
504  $optionRow . $addSubmit
505  );
506  }
507  $out .= Xml::closeElement( 'tr' );
508  }
509  $out .= Xml::closeElement( 'table' );
510 
511  $unconsumed = $opts->getUnconsumedValues();
512  foreach ( $unconsumed as $key => $value ) {
513  $out .= Html::hidden( $key, $value );
514  }
515 
516  $t = $this->getPageTitle();
517  $out .= Html::hidden( 'title', $t->getPrefixedText() );
518  $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
519  $panel[] = $form;
520  $panelString = implode( "\n", $panel );
521 
522  $rcoptions = Xml::fieldset(
523  $this->msg( 'recentchanges-legend' )->text(),
524  $panelString,
525  [ 'class' => 'rcoptions cloptions' ]
526  );
527 
528  // Insert a placeholder for RCFilters
529  if ( $this->isStructuredFilterUiEnabled() ) {
530  $rcfilterContainer = Html::element(
531  'div',
532  // TODO: Remove deprecated rcfilters-container class
533  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
534  );
535 
536  $loadingContainer = Html::rawElement(
537  'div',
538  [ 'class' => 'mw-rcfilters-spinner' ],
540  'div',
541  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
542  )
543  );
544 
545  // Wrap both with rcfilters-head
546  $this->getOutput()->addHTML(
548  'div',
549  // TODO: Remove deprecated rcfilters-head class
550  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
551  $rcfilterContainer . $rcoptions
552  )
553  );
554 
555  // Add spinner
556  $this->getOutput()->addHTML( $loadingContainer );
557  } else {
558  $this->getOutput()->addHTML( $rcoptions );
559  }
560 
561  $this->setBottomText( $opts );
562  }
563 
569  public function setTopText( FormOptions $opts ) {
570  $message = $this->msg( 'recentchangestext' )->inContentLanguage();
571  if ( !$message->isDisabled() ) {
572  $services = MediaWikiServices::getInstance();
573  $contLang = $services->getContentLanguage();
574  // Parse the message in this weird ugly way to preserve the ability to include interlanguage
575  // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
576  // $message->parse() instead. This code is copied from Message::parseText().
577  $parserOutput = $services->getMessageCache()->parse(
578  $message->plain(),
579  $this->getPageTitle(),
580  /*linestart*/true,
581  // Message class sets the interface flag to false when parsing in a language different than
582  // user language, and this is wiki content language
583  /*interface*/false,
584  $contLang
585  );
586  $content = $parserOutput->getText( [
587  'enableSectionEditLinks' => false,
588  ] );
589  // Add only metadata here (including the language links), text is added below
590  $this->getOutput()->addParserOutputMetadata( $parserOutput );
591 
592  $langAttributes = [
593  'lang' => $contLang->getHtmlCode(),
594  'dir' => $contLang->getDir(),
595  ];
596 
597  $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
598 
599  if ( $this->isStructuredFilterUiEnabled() ) {
600  // Check whether the widget is already collapsed or expanded
601  $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
602  // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
603  $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
604  ' mw-recentchanges-toplinks-collapsed' : '';
605 
606  $this->getOutput()->enableOOUI();
607  $contentTitle = new OOUI\ButtonWidget( [
608  'classes' => [ 'mw-recentchanges-toplinks-title' ],
609  'label' => new OOUI\HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
610  'framed' => false,
611  'indicator' => $collapsedState !== 'expanded' ? 'down' : 'up',
612  'flags' => [ 'progressive' ],
613  ] );
614 
615  $contentWrapper = Html::rawElement( 'div',
616  array_merge(
617  [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
618  $langAttributes
619  ),
620  $content
621  );
622  $content = $contentTitle . $contentWrapper;
623  } else {
624  // Language direction should be on the top div only
625  // if the title is not there. If it is there, it's
626  // interface direction, and the language/dir attributes
627  // should be on the content itself
628  $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
629  }
630 
631  $this->getOutput()->addHTML(
632  Html::rawElement( 'div', $topLinksAttributes, $content )
633  );
634  }
635  }
636 
643  public function getExtraOptions( $opts ) {
644  $opts->consumeValues( [
645  'namespace', 'invert', 'associated', 'tagfilter'
646  ] );
647 
648  $extraOpts = [];
649  $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
650 
652  $opts['tagfilter'], false, $this->getContext() );
653  if ( count( $tagFilter ) ) {
654  $extraOpts['tagfilter'] = $tagFilter;
655  }
656 
657  // Don't fire the hook for subclasses. (Or should we?)
658  if ( $this->getName() === 'Recentchanges' ) {
659  $this->getHookRunner()->onSpecialRecentChangesPanel( $extraOpts, $opts );
660  }
661 
662  return $extraOpts;
663  }
664 
668  protected function addModules() {
669  parent::addModules();
670  $out = $this->getOutput();
671  $out->addModules( 'mediawiki.special.recentchanges' );
672  }
673 
681  public function checkLastModified() {
682  $dbr = $this->getDB();
683  $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
684 
685  return $lastmod;
686  }
687 
694  protected function namespaceFilterForm( FormOptions $opts ) {
695  $nsSelect = Html::namespaceSelector(
696  [ 'selected' => $opts['namespace'], 'all' => '', 'in-user-lang' => true ],
697  [ 'name' => 'namespace', 'id' => 'namespace' ]
698  );
699  $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
700  $attribs = [ 'class' => [ 'mw-input-with-label' ] ];
701  // Hide the checkboxes when the namespace filter is set to 'all'.
702  if ( $opts['namespace'] === '' ) {
703  $attribs['class'][] = 'mw-input-hidden';
704  }
705  $invert = Html::rawElement( 'span', $attribs, Xml::checkLabel(
706  $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
707  $opts['invert'],
708  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
709  ) );
710  $associated = Html::rawElement( 'span', $attribs, Xml::checkLabel(
711  $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
712  $opts['associated'],
713  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
714  ) );
715 
716  return [ $nsLabel, "$nsSelect $invert $associated" ];
717  }
718 
728  private function makeOptionsLink( $title, $override, $options, $active = false ) {
729  $params = $this->convertParamsForLink( $override + $options );
730 
731  if ( $active ) {
732  $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
733  }
734 
735  return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
736  'data-params' => json_encode( $override ),
737  'data-keys' => implode( ',', array_keys( $override ) ),
738  ], $params );
739  }
740 
749  private function optionsPanel( $defaults, $nondefaults, $numRows ) {
750  $options = $nondefaults + $defaults;
751 
752  $note = '';
753  $msg = $this->msg( 'rclegend' );
754  if ( !$msg->isDisabled() ) {
755  $note .= Html::rawElement(
756  'div',
757  [ 'class' => 'mw-rclegend' ],
758  $msg->parse()
759  );
760  }
761 
762  $lang = $this->getLanguage();
763  $user = $this->getUser();
764  $config = $this->getConfig();
765  if ( $options['from'] ) {
766  $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
767  [ 'from' => '' ], $nondefaults );
768 
769  $noteFromMsg = $this->msg( 'rcnotefrom' )
770  ->numParams( $options['limit'] )
771  ->params(
772  $lang->userTimeAndDate( $options['from'], $user ),
773  $lang->userDate( $options['from'], $user ),
774  $lang->userTime( $options['from'], $user )
775  )
776  ->numParams( $numRows );
777  $note .= Html::rawElement(
778  'span',
779  [ 'class' => 'rcnotefrom' ],
780  $noteFromMsg->parse()
781  ) .
782  ' ' .
784  'span',
785  [ 'class' => 'rcoptions-listfromreset' ],
786  $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
787  ) .
788  '<br />';
789  }
790 
791  # Sort data for display and make sure it's unique after we've added user data.
792  $linkLimits = $config->get( 'RCLinkLimits' );
793  $linkLimits[] = $options['limit'];
794  sort( $linkLimits );
795  $linkLimits = array_unique( $linkLimits );
796 
797  $linkDays = $this->getLinkDays();
798  $linkDays[] = $options['days'];
799  sort( $linkDays );
800  $linkDays = array_unique( $linkDays );
801 
802  // limit links
803  $cl = [];
804  foreach ( $linkLimits as $value ) {
805  $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
806  [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
807  }
808  $cl = $lang->pipeList( $cl );
809 
810  // day links, reset 'from' to none
811  $dl = [];
812  foreach ( $linkDays as $value ) {
813  $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
814  [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
815  }
816  $dl = $lang->pipeList( $dl );
817 
818  $showhide = [ 'show', 'hide' ];
819 
820  $links = [];
821 
822  foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
823  $msg = $filter->getShowHide();
824  $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
825  // Extensions can define additional filters, but don't need to define the corresponding
826  // messages. If they don't exist, just fall back to 'show' and 'hide'.
827  if ( !$linkMessage->exists() ) {
828  $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
829  }
830 
831  $link = $this->makeOptionsLink( $linkMessage->text(),
832  [ $key => 1 - $options[$key] ], $nondefaults );
833 
834  $attribs = [
835  'class' => "$msg rcshowhideoption clshowhideoption",
836  'data-filter-name' => $filter->getName(),
837  ];
838 
839  if ( $filter->isFeatureAvailableOnStructuredUi() ) {
840  $attribs['data-feature-in-structured-ui'] = true;
841  }
842 
843  $links[] = Html::rawElement(
844  'span',
845  $attribs,
846  $this->msg( $msg )->rawParams( $link )->parse()
847  );
848  }
849 
850  // show from this onward link
851  $timestamp = wfTimestampNow();
852  $now = $lang->userTimeAndDate( $timestamp, $user );
853  $timenow = $lang->userTime( $timestamp, $user );
854  $datenow = $lang->userDate( $timestamp, $user );
855  $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
856 
857  $rclinks = Html::rawElement(
858  'span',
859  [ 'class' => 'rclinks' ],
860  $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )->parse()
861  );
862 
863  $rclistfrom = Html::rawElement(
864  'span',
865  [ 'class' => 'rclistfrom' ],
866  $this->makeOptionsLink(
867  $this->msg( 'rclistfrom' )->plaintextParams( $now, $timenow, $datenow )->parse(),
868  [ 'from' => $timestamp, 'fromFormatted' => $now ],
869  $nondefaults
870  )
871  );
872 
873  return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
874  }
875 
876  public function isIncludable() {
877  return true;
878  }
879 
880  protected function getCacheTTL() {
881  return 60 * 5;
882  }
883 
884  public function getDefaultLimit() {
885  $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
886  // Prefer the RCFilters-specific preference if RCFilters is enabled
887  if ( $this->isStructuredFilterUiEnabled() ) {
888  return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
889  }
890 
891  // Otherwise, use the system rclimit preference value
892  return $systemPrefValue;
893  }
894 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:669
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:234
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:800
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
SpecialRecentChanges\parseParameters
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
Definition: SpecialRecentChanges.php:243
SpecialRecentChanges\doMainQuery
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
Process the query.Array of tables; see IDatabase::select $table Array of fields; see IDatabase::selec...
Definition: SpecialRecentChanges.php:271
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:716
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
SpecialRecentChanges\namespaceFilterForm
namespaceFilterForm(FormOptions $opts)
Creates the choose namespace selection.
Definition: SpecialRecentChanges.php:694
Xml\label
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:362
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1731
SpecialRecentChanges\__construct
__construct( $name='Recentchanges', $restriction='')
Definition: SpecialRecentChanges.php:41
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:37
SpecialRecentChanges\outputChangesList
outputChangesList( $rows, $opts)
Build and output the actual changes list.
Definition: SpecialRecentChanges.php:387
SpecialRecentChanges\getCacheTTL
getCacheTTL()
Definition: SpecialRecentChanges.php:880
SpecialRecentChanges\$watchlistFilterGroupDefinition
$watchlistFilterGroupDefinition
Definition: SpecialRecentChanges.php:39
SpecialRecentChanges\registerFilters
registerFilters()
Register all filters and their groups (including those from hooks), plus handle conflicts and default...
Definition: SpecialRecentChanges.php:181
SpecialRecentChanges\$daysPreferenceName
static $daysPreferenceName
Definition: SpecialRecentChanges.php:35
ChangeTags\buildTagFilterSelector
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
Definition: ChangeTags.php:886
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:746
SpecialRecentChanges\isIncludable
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.
Definition: SpecialRecentChanges.php:876
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:160
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
LIST_AND
const LIST_AND
Definition: Defines.php:48
ChangesListSpecialPage\outputNoResults
outputNoResults()
Add the "no results" message to the output.
Definition: ChangesListSpecialPage.php:990
$dbr
$dbr
Definition: testCompression.php:54
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:613
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:439
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:784
SpecialRecentChanges\addModules
addModules()
Add page-specific modules.
Definition: SpecialRecentChanges.php:668
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:836
LIST_OR
const LIST_OR
Definition: Defines.php:51
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:974
SpecialRecentChanges\$savedQueriesPreferenceName
static $savedQueriesPreferenceName
Definition: SpecialRecentChanges.php:34
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:766
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:818
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2530
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
ChangesListSpecialPage\convertParamsForLink
convertParamsForLink( $params)
Convert parameters values from true/false to 1/0 so they are not omitted by wfArrayToCgi() T38524.
Definition: ChangesListSpecialPage.php:1495
getPermissionManager
getPermissionManager()
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2463
ChangesListSpecialPage\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: ChangesListSpecialPage.php:1621
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1932
SpecialRecentChanges\transformFilterDefinition
transformFilterDefinition(array $filterDefinition)
Transforms filter definition to prepare it for constructor.See overrides of this method as well....
Definition: SpecialRecentChanges.php:170
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:138
SpecialRecentChanges\getFeedQuery
getFeedQuery()
Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
Definition: SpecialRecentChanges.php:367
$title
$title
Definition: testCompression.php:38
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:726
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1835
SpecialRecentChanges\execute
execute( $subpage)
Definition: SpecialRecentChanges.php:140
SpecialRecentChanges\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialRecentChanges.php:354
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:689
SpecialRecentChanges\$collapsedPreferenceName
static $collapsedPreferenceName
Definition: SpecialRecentChanges.php:37
ChangesList\newFromContext
static newFromContext(IContextSource $context, array $groups=[])
Fetch an appropriate changes list class for the specified context Some users might want to use an enh...
Definition: ChangesList.php:93
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:802
$content
$content
Definition: router.php:76
Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:894
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
ChangesListSpecialPage\getFilterGroup
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Definition: ChangesListSpecialPage.php:1263
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:706
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:59
SpecialRecentChanges
A special page that lists last changes made to the wiki.
Definition: SpecialRecentChanges.php:32
$context
$context
Definition: load.php:43
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:912
SpecialRecentChanges\optionsPanel
optionsPanel( $defaults, $nondefaults, $numRows)
Creates the options panel.
Definition: SpecialRecentChanges.php:749
ChangesListSpecialPage\areFiltersInConflict
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
Definition: ChangesListSpecialPage.php:582
SpecialRecentChanges\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
Definition: SpecialRecentChanges.php:569
SpecialRecentChanges\doHeader
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
Definition: SpecialRecentChanges.php:464
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
SpecialRecentChanges\getExtraOptions
getExtraOptions( $opts)
Get options to be displayed in a form.
Definition: SpecialRecentChanges.php:643
SpecialRecentChanges\outputFeedLinks
outputFeedLinks()
Output feed links.
Definition: SpecialRecentChanges.php:358
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
SpecialRecentChanges\$limitPreferenceName
static $limitPreferenceName
Definition: SpecialRecentChanges.php:36
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:135
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
$t
$t
Definition: testCompression.php:74
ChangesListSpecialPage\registerFiltersFromDefinitions
registerFiltersFromDefinitions(array $definition)
Register filters from a definition object.
Definition: ChangesListSpecialPage.php:1137
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
ChangesListSpecialPage\setBottomText
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
Definition: ChangesListSpecialPage.php:1709
SpecialRecentChanges\getDefaultLimit
getDefaultLimit()
Get the default value of the number of changes to display when loading the result set.
Definition: SpecialRecentChanges.php:884
ChangesListSpecialPage\getOptions
getOptions()
Get the current FormOptions for this request.
Definition: ChangesListSpecialPage.php:1032
ChangesListSpecialPage\getLinkDays
getLinkDays()
Definition: ChangesListSpecialPage.php:774
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:243
SpecialRecentChanges\checkLastModified
checkLastModified()
Get last modified date, for client caching Don't use this if we are using the patrol feature,...
Definition: SpecialRecentChanges.php:681
SpecialRecentChanges\makeOptionsLink
makeOptionsLink( $title, $override, $options, $active=false)
Makes change an option link which carries all the other options.
Definition: SpecialRecentChanges.php:728
ChangesListSpecialPage\getLegacyShowHideFilters
getLegacyShowHideFilters()
Definition: ChangesListSpecialPage.php:1163
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:463
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:423
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:37