MediaWiki  master
SpecialRecentChanges.php
Go to the documentation of this file.
1 <?php
29 
36 
38 
41 
43  private $messageCache;
44 
46  private $loadBalancer;
47 
50 
57  public function __construct(
62  ) {
63  parent::__construct( 'Recentchanges', '' );
64  // This class is extended and therefor fallback to global state - T265310
65  $services = MediaWikiServices::getInstance();
66  $this->watchedItemStore = $watchedItemStore ?? $services->getWatchedItemStore();
67  $this->messageCache = $messageCache ?? $services->getMessageCache();
68  $this->loadBalancer = $loadBalancer ?? $services->getDBLoadBalancer();
69  $this->userOptionsLookup = $userOptionsLookup ?? $services->getUserOptionsLookup();
70 
71  $this->watchlistFilterGroupDefinition = [
72  'name' => 'watchlist',
73  'title' => 'rcfilters-filtergroup-watchlist',
74  'class' => ChangesListStringOptionsFilterGroup::class,
75  'priority' => -9,
76  'isFullCoverage' => true,
77  'filters' => [
78  [
79  'name' => 'watched',
80  'label' => 'rcfilters-filter-watchlist-watched-label',
81  'description' => 'rcfilters-filter-watchlist-watched-description',
82  'cssClassSuffix' => 'watched',
83  'isRowApplicableCallable' => static function ( IContextSource $ctx, RecentChange $rc ) {
84  return $rc->getAttribute( 'wl_user' );
85  }
86  ],
87  [
88  'name' => 'watchednew',
89  'label' => 'rcfilters-filter-watchlist-watchednew-label',
90  'description' => 'rcfilters-filter-watchlist-watchednew-description',
91  'cssClassSuffix' => 'watchednew',
92  'isRowApplicableCallable' => static function ( IContextSource $ctx, RecentChange $rc ) {
93  return $rc->getAttribute( 'wl_user' ) &&
94  $rc->getAttribute( 'rc_timestamp' ) &&
95  $rc->getAttribute( 'wl_notificationtimestamp' ) &&
96  $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
97  },
98  ],
99  [
100  'name' => 'notwatched',
101  'label' => 'rcfilters-filter-watchlist-notwatched-label',
102  'description' => 'rcfilters-filter-watchlist-notwatched-description',
103  'cssClassSuffix' => 'notwatched',
104  'isRowApplicableCallable' => static function ( IContextSource $ctx, RecentChange $rc ) {
105  return $rc->getAttribute( 'wl_user' ) === null;
106  },
107  ]
108  ],
110  'queryCallable' => function ( string $specialClassName, IContextSource $ctx,
111  IDatabase $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues
112  ) {
113  sort( $selectedValues );
114  $notwatchedCond = 'wl_user IS NULL';
115  $watchedCond = 'wl_user IS NOT NULL';
116  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
117  // Expired watchlist items stay in the DB after their expiry time until they're purged,
118  // so it's not enough to only check for wl_user.
119  $quotedNow = $dbr->addQuotes( $dbr->timestamp() );
120  $notwatchedCond = "wl_user IS NULL OR ( we_expiry IS NOT NULL AND we_expiry < $quotedNow )";
121  $watchedCond = "wl_user IS NOT NULL AND ( we_expiry IS NULL OR we_expiry >= $quotedNow )";
122  }
123  $newCond = 'rc_timestamp >= wl_notificationtimestamp';
124 
125  if ( $selectedValues === [ 'notwatched' ] ) {
126  $conds[] = $notwatchedCond;
127  return;
128  }
129 
130  if ( $selectedValues === [ 'watched' ] ) {
131  $conds[] = $watchedCond;
132  return;
133  }
134 
135  if ( $selectedValues === [ 'watchednew' ] ) {
136  $conds[] = $dbr->makeList( [
137  $watchedCond,
138  $newCond
139  ], LIST_AND );
140  return;
141  }
142 
143  if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
144  // no filters
145  return;
146  }
147 
148  if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
149  $conds[] = $dbr->makeList( [
150  $notwatchedCond,
151  $dbr->makeList( [
152  $watchedCond,
153  $newCond
154  ], LIST_AND )
155  ], LIST_OR );
156  return;
157  }
158 
159  if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
160  $conds[] = $watchedCond;
161  return;
162  }
163 
164  if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
165  // no filters
166  return;
167  }
168  }
169  ];
170  }
171 
175  public function execute( $subpage ) {
176  // Backwards-compatibility: redirect to new feed URLs
177  $feedFormat = $this->getRequest()->getVal( 'feed' );
178  if ( !$this->including() && $feedFormat ) {
179  $query = $this->getFeedQuery();
180  $query['feedformat'] = $feedFormat === 'atom' ? 'atom' : 'rss';
181  $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
182 
183  return;
184  }
185 
186  // 10 seconds server-side caching max
187  $out = $this->getOutput();
188  $out->setCdnMaxage( 10 );
189  // Check if the client has a cached version
190  $lastmod = $this->checkLastModified();
191  if ( $lastmod === false ) {
192  return;
193  }
194 
195  $this->addHelpLink(
196  'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
197  true
198  );
199  parent::execute( $subpage );
200  }
201 
205  protected function transformFilterDefinition( array $filterDefinition ) {
206  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
207  $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
208  }
209 
210  return $filterDefinition;
211  }
212 
219  private function needsWatchlistFeatures(): bool {
220  return !$this->including()
221  && $this->getUser()->isRegistered()
222  && $this->getAuthority()->isAllowed( 'viewmywatchlist' );
223  }
224 
228  protected function registerFilters() {
229  parent::registerFilters();
230 
231  if ( $this->needsWatchlistFeatures() ) {
232  $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition ] );
233  $watchlistGroup = $this->getFilterGroup( 'watchlist' );
234  $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
235  $watchlistGroup->getFilter( 'watchednew' )
236  );
237  }
238 
239  $user = $this->getUser();
240 
241  $significance = $this->getFilterGroup( 'significance' );
243  $hideMinor = $significance->getFilter( 'hideminor' );
244  '@phan-var ChangesListBooleanFilter $hideMinor';
245  $hideMinor->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'hideminor' ) );
246 
247  $automated = $this->getFilterGroup( 'automated' );
249  $hideBots = $automated->getFilter( 'hidebots' );
250  '@phan-var ChangesListBooleanFilter $hideBots';
251  $hideBots->setDefault( true );
252 
254  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
255  '@phan-var ChangesListStringOptionsFilterGroup|null $reviewStatus';
256  if ( $reviewStatus !== null ) {
257  // Conditional on feature being available and rights
258  if ( $this->userOptionsLookup->getBoolOption( $user, 'hidepatrolled' ) ) {
259  $reviewStatus->setDefault( 'unpatrolled' );
260  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
262  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
263  '@phan-var ChangesListBooleanFilter $legacyHidePatrolled';
264  $legacyHidePatrolled->setDefault( true );
265  }
266  }
267 
268  $changeType = $this->getFilterGroup( 'changeType' );
270  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
271  '@phan-var ChangesListBooleanFilter $hideCategorization';
272  if ( $hideCategorization !== null ) {
273  // Conditional on feature being available
274  $hideCategorization->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'hidecategorization' ) );
275  }
276  }
277 
284  public function parseParameters( $par, FormOptions $opts ) {
285  parent::parseParameters( $par, $opts );
286 
287  $bits = preg_split( '/\s*,\s*/', trim( $par ) );
288  foreach ( $bits as $bit ) {
289  if ( is_numeric( $bit ) ) {
290  $opts['limit'] = $bit;
291  }
292 
293  $m = [];
294  if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
295  $opts['limit'] = $m[1];
296  }
297  if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
298  $opts['days'] = $m[1];
299  }
300  if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
301  $opts['namespace'] = $m[1];
302  }
303  if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
304  $opts['tagfilter'] = $m[1];
305  }
306  }
307  }
308 
319  protected function addWatchlistJoins( IDatabase $dbr, &$tables, &$fields, &$joinConds, &$conds ) {
320  if ( !$this->needsWatchlistFeatures() ) {
321  return;
322  }
323 
324  // Join on watchlist table.
325  $tables[] = 'watchlist';
326  $fields[] = 'wl_user';
327  $fields[] = 'wl_notificationtimestamp';
328  $joinConds['watchlist'] = [ 'LEFT JOIN', [
329  'wl_user' => $this->getUser()->getId(),
330  'wl_title=rc_title',
331  'wl_namespace=rc_namespace'
332  ] ];
333 
334  // Exclude expired watchlist items.
335  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
336  $tables[] = 'watchlist_expiry';
337  $fields[] = 'we_expiry';
338  $joinConds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ];
339  }
340  }
341 
345  protected function doMainQuery( $tables, $fields, $conds, $query_options,
346  $join_conds, FormOptions $opts
347  ) {
348  $dbr = $this->getDB();
349 
350  $rcQuery = RecentChange::getQueryInfo();
351  $tables = array_merge( $rcQuery['tables'], $tables );
352  $fields = array_merge( $rcQuery['fields'], $fields );
353  $join_conds = array_merge( $rcQuery['joins'], $join_conds );
354 
355  // Join with watchlist and watchlist_expiry tables to highlight watched rows.
356  $this->addWatchlistJoins( $dbr, $tables, $fields, $join_conds, $conds );
357 
358  // JOIN on page, used for 'last revision' filter highlight
359  $tables[] = 'page';
360  $fields[] = 'page_latest';
361  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
362 
363  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
365  $tables,
366  $fields,
367  $conds,
368  $join_conds,
369  $query_options,
370  $tagFilter
371  );
372 
373  if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
374  $opts )
375  ) {
376  return false;
377  }
378 
379  if ( $this->areFiltersInConflict() ) {
380  return false;
381  }
382 
383  $orderByAndLimit = [
384  'ORDER BY' => 'rc_timestamp DESC',
385  'LIMIT' => $opts['limit']
386  ];
387  if ( in_array( 'DISTINCT', $query_options ) ) {
388  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
389  // In order to prevent DISTINCT from causing query performance problems,
390  // we have to GROUP BY the primary key. This in turn requires us to add
391  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
392  // start of the GROUP BY
393  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
394  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
395  }
396  // array_merge() is used intentionally here so that hooks can, should
397  // they so desire, override the ORDER BY / LIMIT condition(s); prior to
398  // MediaWiki 1.26 this used to use the plus operator instead, which meant
399  // that extensions weren't able to change these conditions
400  $query_options = array_merge( $orderByAndLimit, $query_options );
401  $rows = $dbr->select(
402  $tables,
403  $fields,
404  // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
405  // knowledge to use an index merge if it wants (it may use some other index though).
406  $conds + [ 'rc_new' => [ 0, 1 ] ],
407  __METHOD__,
408  $query_options,
409  $join_conds
410  );
411 
412  return $rows;
413  }
414 
415  protected function getDB() {
416  return $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA, 'recentchanges' );
417  }
418 
419  public function outputFeedLinks() {
420  $this->addFeedLinks( $this->getFeedQuery() );
421  }
422 
428  protected function getFeedQuery() {
429  $query = array_filter( $this->getOptions()->getAllValues(), static function ( $value ) {
430  // API handles empty parameters in a different way
431  return $value !== '';
432  } );
433  $query['action'] = 'feedrecentchanges';
434  $feedLimit = $this->getConfig()->get( 'FeedLimit' );
435  if ( $query['limit'] > $feedLimit ) {
436  $query['limit'] = $feedLimit;
437  }
438 
439  return $query;
440  }
441 
448  public function outputChangesList( $rows, $opts ) {
449  $limit = $opts['limit'];
450 
451  $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
452  && $this->userOptionsLookup->getBoolOption( $this->getUser(), 'shownumberswatching' );
453  $watcherCache = [];
454 
455  $counter = 1;
456  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
457  $list->initChangesListRows( $rows );
458 
459  $userShowHiddenCats = $this->userOptionsLookup->getBoolOption( $this->getUser(), 'showhiddencats' );
460  $rclistOutput = $list->beginRecentChangesList();
461  if ( $this->isStructuredFilterUiEnabled() ) {
462  $rclistOutput .= $this->makeLegend();
463  }
464 
465  foreach ( $rows as $obj ) {
466  if ( $limit == 0 ) {
467  break;
468  }
469  $rc = RecentChange::newFromRow( $obj );
470 
471  # Skip CatWatch entries for hidden cats based on user preference
472  if (
473  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
474  !$userShowHiddenCats &&
475  $rc->getParam( 'hidden-cat' )
476  ) {
477  continue;
478  }
479 
480  $rc->counter = $counter++;
481  # Check if the page has been updated since the last visit
482  if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
483  && !empty( $obj->wl_notificationtimestamp )
484  ) {
485  $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
486  } else {
487  $rc->notificationtimestamp = false; // Default
488  }
489  # Check the number of users watching the page
490  $rc->numberofWatchingusers = 0; // Default
491  if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
492  if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
493  $watcherCache[$obj->rc_namespace][$obj->rc_title] =
494  $this->watchedItemStore->countWatchers(
495  new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
496  );
497  }
498  $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
499  }
500 
501  $watched = !empty( $obj->wl_user );
502  if ( $watched && $this->getConfig()->get( 'WatchlistExpiry' ) ) {
503  $notExpired = $obj->we_expiry === null
504  || MWTimestamp::convert( TS_UNIX, $obj->we_expiry ) > wfTimestamp();
505  $watched = $watched && $notExpired;
506  }
507  $changeLine = $list->recentChangesLine( $rc, $watched, $counter );
508  if ( $changeLine !== false ) {
509  $rclistOutput .= $changeLine;
510  --$limit;
511  }
512  }
513  $rclistOutput .= $list->endRecentChangesList();
514 
515  if ( $rows->numRows() === 0 ) {
516  $this->outputNoResults();
517  if ( !$this->including() ) {
518  $this->getOutput()->setStatusCode( 404 );
519  }
520  } else {
521  $this->getOutput()->addHTML( $rclistOutput );
522  }
523  }
524 
531  public function doHeader( $opts, $numRows ) {
532  $this->setTopText( $opts );
533 
534  $defaults = $opts->getAllValues();
535  $nondefaults = $opts->getChangedValues();
536 
537  $panel = [];
538  if ( !$this->isStructuredFilterUiEnabled() ) {
539  $panel[] = $this->makeLegend();
540  }
541  $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
542  $panel[] = '<hr />';
543 
544  $extraOpts = $this->getExtraOptions( $opts );
545  $extraOptsCount = count( $extraOpts );
546  $count = 0;
547  $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
548 
549  $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
550  foreach ( $extraOpts as $name => $optionRow ) {
551  # Add submit button to the last row only
552  ++$count;
553  $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
554 
555  $out .= Xml::openElement( 'tr', [ 'class' => $name . 'Form' ] );
556  if ( is_array( $optionRow ) ) {
557  $out .= Xml::tags(
558  'td',
559  [ 'class' => 'mw-label mw-' . $name . '-label' ],
560  $optionRow[0]
561  );
562  $out .= Xml::tags(
563  'td',
564  [ 'class' => 'mw-input' ],
565  $optionRow[1] . $addSubmit
566  );
567  } else {
568  $out .= Xml::tags(
569  'td',
570  [ 'class' => 'mw-input', 'colspan' => 2 ],
571  $optionRow . $addSubmit
572  );
573  }
574  $out .= Xml::closeElement( 'tr' );
575  }
576  $out .= Xml::closeElement( 'table' );
577 
578  $unconsumed = $opts->getUnconsumedValues();
579  foreach ( $unconsumed as $key => $value ) {
580  $out .= Html::hidden( $key, $value );
581  }
582 
583  $t = $this->getPageTitle();
584  $out .= Html::hidden( 'title', $t->getPrefixedText() );
585  $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
586  $panel[] = $form;
587  $panelString = implode( "\n", $panel );
588 
589  $rcoptions = Xml::fieldset(
590  $this->msg( 'recentchanges-legend' )->text(),
591  $panelString,
592  [ 'class' => 'rcoptions cloptions' ]
593  );
594 
595  // Insert a placeholder for RCFilters
596  if ( $this->isStructuredFilterUiEnabled() ) {
597  $rcfilterContainer = Html::element(
598  'div',
599  // TODO: Remove deprecated rcfilters-container class
600  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
601  );
602 
603  $loadingContainer = Html::rawElement(
604  'div',
605  [ 'class' => 'mw-rcfilters-spinner' ],
607  'div',
608  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
609  )
610  );
611 
612  // Wrap both with rcfilters-head
613  $this->getOutput()->addHTML(
615  'div',
616  // TODO: Remove deprecated rcfilters-head class
617  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
618  $rcfilterContainer . $rcoptions
619  )
620  );
621 
622  // Add spinner
623  $this->getOutput()->addHTML( $loadingContainer );
624  } else {
625  $this->getOutput()->addHTML( $rcoptions );
626  }
627 
628  $this->setBottomText( $opts );
629  }
630 
636  public function setTopText( FormOptions $opts ) {
637  $message = $this->msg( 'recentchangestext' )->inContentLanguage();
638  if ( !$message->isDisabled() ) {
639  $contLang = $this->getContentLanguage();
640  // Parse the message in this weird ugly way to preserve the ability to include interlanguage
641  // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
642  // $message->parse() instead. This code is copied from Message::parseText().
643  $parserOutput = $this->messageCache->parse(
644  $message->plain(),
645  $this->getPageTitle(),
646  /*linestart*/true,
647  // Message class sets the interface flag to false when parsing in a language different than
648  // user language, and this is wiki content language
649  /*interface*/false,
650  $contLang
651  );
652  $content = $parserOutput->getText( [
653  'enableSectionEditLinks' => false,
654  ] );
655  // Add only metadata here (including the language links), text is added below
656  $this->getOutput()->addParserOutputMetadata( $parserOutput );
657 
658  $langAttributes = [
659  'lang' => $contLang->getHtmlCode(),
660  'dir' => $contLang->getDir(),
661  ];
662 
663  $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
664 
665  if ( $this->isStructuredFilterUiEnabled() ) {
666  // Check whether the widget is already collapsed or expanded
667  $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
668  // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
669  $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
670  ' mw-recentchanges-toplinks-collapsed' : '';
671 
672  $this->getOutput()->enableOOUI();
673  $contentTitle = new OOUI\ButtonWidget( [
674  'classes' => [ 'mw-recentchanges-toplinks-title' ],
675  'label' => new OOUI\HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
676  'framed' => false,
677  'indicator' => $collapsedState !== 'expanded' ? 'down' : 'up',
678  'flags' => [ 'progressive' ],
679  ] );
680 
681  $contentWrapper = Html::rawElement( 'div',
682  array_merge(
683  [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
684  $langAttributes
685  ),
686  $content
687  );
688  $content = $contentTitle . $contentWrapper;
689  } else {
690  // Language direction should be on the top div only
691  // if the title is not there. If it is there, it's
692  // interface direction, and the language/dir attributes
693  // should be on the content itself
694  $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
695  }
696 
697  $this->getOutput()->addHTML(
698  Html::rawElement( 'div', $topLinksAttributes, $content )
699  );
700  }
701  }
702 
709  public function getExtraOptions( $opts ) {
710  $opts->consumeValues( [
711  'namespace', 'invert', 'associated', 'tagfilter'
712  ] );
713 
714  $extraOpts = [];
715  $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
716 
718  $opts['tagfilter'], false, $this->getContext() );
719  if ( count( $tagFilter ) ) {
720  $extraOpts['tagfilter'] = $tagFilter;
721  }
722 
723  // Don't fire the hook for subclasses. (Or should we?)
724  if ( $this->getName() === 'Recentchanges' ) {
725  $this->getHookRunner()->onSpecialRecentChangesPanel( $extraOpts, $opts );
726  }
727 
728  return $extraOpts;
729  }
730 
734  protected function addModules() {
735  parent::addModules();
736  $out = $this->getOutput();
737  $out->addModules( 'mediawiki.special.recentchanges' );
738  }
739 
747  public function checkLastModified() {
748  $dbr = $this->getDB();
749  $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
750 
751  return $lastmod;
752  }
753 
760  protected function namespaceFilterForm( FormOptions $opts ) {
761  $nsSelect = Html::namespaceSelector(
762  [ 'selected' => $opts['namespace'], 'all' => '', 'in-user-lang' => true ],
763  [ 'name' => 'namespace', 'id' => 'namespace' ]
764  );
765  $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
766  $attribs = [ 'class' => [ 'mw-input-with-label' ] ];
767  // Hide the checkboxes when the namespace filter is set to 'all'.
768  if ( $opts['namespace'] === '' ) {
769  $attribs['class'][] = 'mw-input-hidden';
770  }
771  $invert = Html::rawElement( 'span', $attribs, Xml::checkLabel(
772  $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
773  $opts['invert'],
774  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
775  ) );
776  $associated = Html::rawElement( 'span', $attribs, Xml::checkLabel(
777  $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
778  $opts['associated'],
779  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
780  ) );
781 
782  return [ $nsLabel, "$nsSelect $invert $associated" ];
783  }
784 
796  private function makeOptionsLink( $title, $override, $options, $active = false ) {
797  $params = $this->convertParamsForLink( $override + $options );
798 
799  if ( $active ) {
800  $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
801  }
802 
803  return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
804  'data-params' => json_encode( $override ),
805  'data-keys' => implode( ',', array_keys( $override ) ),
806  ], $params );
807  }
808 
817  private function optionsPanel( $defaults, $nondefaults, $numRows ) {
818  $options = $nondefaults + $defaults;
819 
820  $note = '';
821  $msg = $this->msg( 'rclegend' );
822  if ( !$msg->isDisabled() ) {
823  $note .= Html::rawElement(
824  'div',
825  [ 'class' => 'mw-rclegend' ],
826  $msg->parse()
827  );
828  }
829 
830  $lang = $this->getLanguage();
831  $user = $this->getUser();
832  $config = $this->getConfig();
833  if ( $options['from'] ) {
834  $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' )->text(),
835  [ 'from' => '' ], $nondefaults );
836 
837  $noteFromMsg = $this->msg( 'rcnotefrom' )
838  ->numParams( $options['limit'] )
839  ->params(
840  $lang->userTimeAndDate( $options['from'], $user ),
841  $lang->userDate( $options['from'], $user ),
842  $lang->userTime( $options['from'], $user )
843  )
844  ->numParams( $numRows );
845  $note .= Html::rawElement(
846  'span',
847  [ 'class' => 'rcnotefrom' ],
848  $noteFromMsg->parse()
849  ) .
850  ' ' .
852  'span',
853  [ 'class' => 'rcoptions-listfromreset' ],
854  $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
855  ) .
856  '<br />';
857  }
858 
859  # Sort data for display and make sure it's unique after we've added user data.
860  $linkLimits = $config->get( 'RCLinkLimits' );
861  $linkLimits[] = $options['limit'];
862  sort( $linkLimits );
863  $linkLimits = array_unique( $linkLimits );
864 
865  $linkDays = $this->getLinkDays();
866  $linkDays[] = $options['days'];
867  sort( $linkDays );
868  $linkDays = array_unique( $linkDays );
869 
870  // limit links
871  $cl = [];
872  foreach ( $linkLimits as $value ) {
873  $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
874  [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
875  }
876  $cl = $lang->pipeList( $cl );
877 
878  // day links, reset 'from' to none
879  $dl = [];
880  foreach ( $linkDays as $value ) {
881  $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
882  [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
883  }
884  $dl = $lang->pipeList( $dl );
885 
886  $showhide = [ 'show', 'hide' ];
887 
888  $links = [];
889 
890  foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
891  $msg = $filter->getShowHide();
892  $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
893  // Extensions can define additional filters, but don't need to define the corresponding
894  // messages. If they don't exist, just fall back to 'show' and 'hide'.
895  if ( !$linkMessage->exists() ) {
896  $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
897  }
898 
899  $link = $this->makeOptionsLink( $linkMessage->text(),
900  [ $key => 1 - $options[$key] ], $nondefaults );
901 
902  $attribs = [
903  'class' => "$msg rcshowhideoption clshowhideoption",
904  'data-filter-name' => $filter->getName(),
905  ];
906 
907  if ( $filter->isFeatureAvailableOnStructuredUi() ) {
908  $attribs['data-feature-in-structured-ui'] = true;
909  }
910 
911  $links[] = Html::rawElement(
912  'span',
913  $attribs,
914  $this->msg( $msg )->rawParams( $link )->parse()
915  );
916  }
917 
918  // show from this onward link
919  $timestamp = wfTimestampNow();
920  $now = $lang->userTimeAndDate( $timestamp, $user );
921  $timenow = $lang->userTime( $timestamp, $user );
922  $datenow = $lang->userDate( $timestamp, $user );
923  $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
924 
925  $rclinks = Html::rawElement(
926  'span',
927  [ 'class' => 'rclinks' ],
928  $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )->parse()
929  );
930 
931  $rclistfrom = Html::rawElement(
932  'span',
933  [ 'class' => 'rclistfrom' ],
934  $this->makeOptionsLink(
935  $this->msg( 'rclistfrom' )->plaintextParams( $now, $timenow, $datenow )->text(),
936  [ 'from' => $timestamp, 'fromFormatted' => $now ],
937  $nondefaults
938  )
939  );
940 
941  return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
942  }
943 
944  public function isIncludable() {
945  return true;
946  }
947 
948  protected function getCacheTTL() {
949  return 60 * 5;
950  }
951 
952  public function getDefaultLimit() {
953  $systemPrefValue = $this->userOptionsLookup->getIntOption( $this->getUser(), 'rclimit' );
954  // Prefer the RCFilters-specific preference if RCFilters is enabled
955  if ( $this->isStructuredFilterUiEnabled() ) {
956  return $this->userOptionsLookup->getIntOption(
957  $this->getUser(), $this->getLimitPreferenceName(), $systemPrefValue
958  );
959  }
960 
961  // Otherwise, use the system rclimit preference value
962  return $systemPrefValue;
963  }
964 
968  protected function getLimitPreferenceName(): string {
969  return 'rcfilters-limit'; // Use RCFilters-specific preference
970  }
971 
975  protected function getSavedQueriesPreferenceName(): string {
976  return 'rcfilters-saved-queries';
977  }
978 
982  protected function getDefaultDaysPreferenceName(): string {
983  return 'rcdays'; // Use general RecentChanges preference
984  }
985 
989  protected function getCollapsedPreferenceName(): string {
990  return 'rcfilters-rc-collapsed';
991  }
992 
993 }
LIST_OR
const LIST_OR
Definition: Defines.php:46
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:744
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:257
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
SpecialRecentChanges\parseParameters
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
Definition: SpecialRecentChanges.php:284
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:345
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:199
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
SpecialRecentChanges\namespaceFilterForm
namespaceFilterForm(FormOptions $opts)
Creates the choose namespace selection.
Definition: SpecialRecentChanges.php:760
Xml\label
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:364
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1734
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:80
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1665
SpecialRecentChanges\needsWatchlistFeatures
needsWatchlistFeatures()
Whether or not the current query needs to use watchlist data: check that the current user can use the...
Definition: SpecialRecentChanges.php:219
SpecialRecentChanges\$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: SpecialRecentChanges.php:49
LIST_AND
const LIST_AND
Definition: Defines.php:43
SpecialRecentChanges\getSavedQueriesPreferenceName
getSavedQueriesPreferenceName()
Definition: SpecialRecentChanges.php:975
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:39
SpecialRecentChanges\outputChangesList
outputChangesList( $rows, $opts)
Build and output the actual changes list.
Definition: SpecialRecentChanges.php:448
SpecialRecentChanges\getCacheTTL
getCacheTTL()
Definition: SpecialRecentChanges.php:948
SpecialRecentChanges\$watchlistFilterGroupDefinition
$watchlistFilterGroupDefinition
Definition: SpecialRecentChanges.php:37
SpecialRecentChanges\addWatchlistJoins
addWatchlistJoins(IDatabase $dbr, &$tables, &$fields, &$joinConds, &$conds)
Add required values to a query's $tables, $fields, $joinConds, and $conds arrays to join to the watch...
Definition: SpecialRecentChanges.php:319
SpecialRecentChanges\registerFilters
registerFilters()
Register all filters and their groups (including those from hooks), plus handle conflicts and default...
Definition: SpecialRecentChanges.php:228
SpecialPage\getAuthority
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: SpecialPage.php:810
ChangeTags\buildTagFilterSelector
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
Definition: ChangeTags.php:1020
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
SpecialRecentChanges\isIncludable
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.
Definition: SpecialRecentChanges.php:944
SpecialRecentChanges\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialRecentChanges.php:46
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:179
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
SpecialRecentChanges\getLimitPreferenceName
getLimitPreferenceName()
Definition: SpecialRecentChanges.php:968
ChangesListSpecialPage\outputNoResults
outputNoResults()
Add the "no results" message to the output.
Definition: ChangesListSpecialPage.php:982
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
$dbr
$dbr
Definition: testCompression.php:54
Xml\fieldset
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:623
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:422
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:891
SpecialRecentChanges\addModules
addModules()
Add page-specific modules.
Definition: SpecialRecentChanges.php:734
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:948
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1095
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:930
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2282
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
ChangesListSpecialPage\convertParamsForLink
convertParamsForLink( $params)
Convert parameters values from true/false to 1/0 so they are not omitted by wfArrayToCgi() T38524.
Definition: ChangesListSpecialPage.php:1489
ChangesListSpecialPage\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: ChangesListSpecialPage.php:1627
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1960
SpecialRecentChanges\transformFilterDefinition
transformFilterDefinition(array $filterDefinition)
Transforms filter definition to prepare it for constructor.See overrides of this method as well....
Definition: SpecialRecentChanges.php:205
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:156
SpecialRecentChanges\__construct
__construct(WatchedItemStoreInterface $watchedItemStore=null, MessageCache $messageCache=null, ILoadBalancer $loadBalancer=null, UserOptionsLookup $userOptionsLookup=null)
Definition: SpecialRecentChanges.php:57
SpecialRecentChanges\getFeedQuery
getFeedQuery()
Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
Definition: SpecialRecentChanges.php:428
$title
$title
Definition: testCompression.php:38
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1694
SpecialRecentChanges\execute
execute( $subpage)
Definition: SpecialRecentChanges.php:175
SpecialRecentChanges\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialRecentChanges.php:415
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
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:98
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:831
$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:923
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
SpecialRecentChanges\$watchedItemStore
WatchedItemStoreInterface $watchedItemStore
Definition: SpecialRecentChanges.php:40
ChangesListSpecialPage\getFilterGroup
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Definition: ChangesListSpecialPage.php:1257
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:780
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:35
SpecialRecentChanges\$messageCache
MessageCache $messageCache
Definition: SpecialRecentChanges.php:43
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialRecentChanges\optionsPanel
optionsPanel( $defaults, $nondefaults, $numRows)
Creates the options panel.
Definition: SpecialRecentChanges.php:817
ChangesListSpecialPage\areFiltersInConflict
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
Definition: ChangesListSpecialPage.php:564
SpecialRecentChanges\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
Definition: SpecialRecentChanges.php:636
SpecialRecentChanges\doHeader
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
Definition: SpecialRecentChanges.php:531
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:119
SpecialRecentChanges\getExtraOptions
getExtraOptions( $opts)
Get options to be displayed in a form.
Definition: SpecialRecentChanges.php:709
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:119
SpecialRecentChanges\outputFeedLinks
outputFeedLinks()
Definition: SpecialRecentChanges.php:419
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialPage\getContentLanguage
getContentLanguage()
Shortcut to get content language.
Definition: SpecialPage.php:840
$t
$t
Definition: testCompression.php:74
ChangesListSpecialPage\registerFiltersFromDefinitions
registerFiltersFromDefinitions(array $definition)
Register filters from a definition object.
Definition: ChangesListSpecialPage.php:1131
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
WatchedItemStoreInterface
Definition: WatchedItemStoreInterface.php:31
MessageCache
Cache of messages that are defined by MediaWiki namespace pages or by hooks.
Definition: MessageCache.php:52
ChangesListSpecialPage\setBottomText
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
Definition: ChangesListSpecialPage.php:1712
SpecialRecentChanges\getDefaultLimit
getDefaultLimit()
Get the default value of the number of changes to display when loading the result set.
Definition: SpecialRecentChanges.php:952
ChangesListSpecialPage\getOptions
getOptions()
Get the current FormOptions for this request.
Definition: ChangesListSpecialPage.php:1026
ChangesListSpecialPage\getLinkDays
getLinkDays()
Definition: ChangesListSpecialPage.php:765
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:266
SpecialRecentChanges\getDefaultDaysPreferenceName
getDefaultDaysPreferenceName()
Definition: SpecialRecentChanges.php:982
SpecialRecentChanges\checkLastModified
checkLastModified()
Get last modified date, for client caching Don't use this if we are using the patrol feature,...
Definition: SpecialRecentChanges.php:747
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialRecentChanges\makeOptionsLink
makeOptionsLink( $title, $override, $options, $active=false)
Makes change an option link which carries all the other options.
Definition: SpecialRecentChanges.php:796
ChangesListSpecialPage\getLegacyShowHideFilters
getLegacyShowHideFilters()
Definition: ChangesListSpecialPage.php:1157
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:465
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:425
SpecialRecentChanges\getCollapsedPreferenceName
getCollapsedPreferenceName()
Definition: SpecialRecentChanges.php:989
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40