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