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