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