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',
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, $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  $newCond = 'rc_timestamp >= wl_notificationtimestamp';
90 
91  if ( $selectedValues === [ 'notwatched' ] ) {
92  $conds[] = $notwatchedCond;
93  return;
94  }
95 
96  if ( $selectedValues === [ 'watched' ] ) {
97  $conds[] = $watchedCond;
98  return;
99  }
100 
101  if ( $selectedValues === [ 'watchednew' ] ) {
102  $conds[] = $dbr->makeList( [
103  $watchedCond,
104  $newCond
105  ], LIST_AND );
106  return;
107  }
108 
109  if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
110  // no filters
111  return;
112  }
113 
114  if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
115  $conds[] = $dbr->makeList( [
116  $notwatchedCond,
117  $dbr->makeList( [
118  $watchedCond,
119  $newCond
120  ], LIST_AND )
121  ], LIST_OR );
122  return;
123  }
124 
125  if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
126  $conds[] = $watchedCond;
127  return;
128  }
129 
130  if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
131  // no filters
132  return;
133  }
134  }
135  ];
136  }
137 
141  public function execute( $subpage ) {
142  // Backwards-compatibility: redirect to new feed URLs
143  $feedFormat = $this->getRequest()->getVal( 'feed' );
144  if ( !$this->including() && $feedFormat ) {
145  $query = $this->getFeedQuery();
146  $query['feedformat'] = $feedFormat === 'atom' ? 'atom' : 'rss';
147  $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
148 
149  return;
150  }
151 
152  // 10 seconds server-side caching max
153  $out = $this->getOutput();
154  $out->setCdnMaxage( 10 );
155  // Check if the client has a cached version
156  $lastmod = $this->checkLastModified();
157  if ( $lastmod === false ) {
158  return;
159  }
160 
161  $this->addHelpLink(
162  'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
163  true
164  );
165  parent::execute( $subpage );
166  }
167 
171  protected function transformFilterDefinition( array $filterDefinition ) {
172  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
173  $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
174  }
175 
176  return $filterDefinition;
177  }
178 
182  protected function registerFilters() {
183  parent::registerFilters();
184 
185  if (
186  !$this->including() &&
187  $this->getUser()->isLoggedIn() &&
188  $this->getUser()->isAllowed( 'viewmywatchlist' )
189  ) {
190  $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition ] );
191  $watchlistGroup = $this->getFilterGroup( 'watchlist' );
192  $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
193  $watchlistGroup->getFilter( 'watchednew' )
194  );
195  }
196 
197  $user = $this->getUser();
198 
199  $significance = $this->getFilterGroup( 'significance' );
200  $hideMinor = $significance->getFilter( 'hideminor' );
201  $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
202 
203  $automated = $this->getFilterGroup( 'automated' );
204  $hideBots = $automated->getFilter( 'hidebots' );
205  $hideBots->setDefault( true );
206 
207  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
208  if ( $reviewStatus !== null ) {
209  // Conditional on feature being available and rights
210  if ( $user->getBoolOption( 'hidepatrolled' ) ) {
211  $reviewStatus->setDefault( 'unpatrolled' );
212  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
213  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
214  $legacyHidePatrolled->setDefault( true );
215  }
216  }
217 
218  $changeType = $this->getFilterGroup( 'changeType' );
219  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
220  if ( $hideCategorization !== null ) {
221  // Conditional on feature being available
222  $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
223  }
224  }
225 
232  public function parseParameters( $par, FormOptions $opts ) {
233  parent::parseParameters( $par, $opts );
234 
235  $bits = preg_split( '/\s*,\s*/', trim( $par ) );
236  foreach ( $bits as $bit ) {
237  if ( is_numeric( $bit ) ) {
238  $opts['limit'] = $bit;
239  }
240 
241  $m = [];
242  if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
243  $opts['limit'] = $m[1];
244  }
245  if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
246  $opts['days'] = $m[1];
247  }
248  if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
249  $opts['namespace'] = $m[1];
250  }
251  if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
252  $opts['tagfilter'] = $m[1];
253  }
254  }
255  }
256 
260  protected function doMainQuery( $tables, $fields, $conds, $query_options,
261  $join_conds, FormOptions $opts
262  ) {
263  $dbr = $this->getDB();
264  $user = $this->getUser();
265 
266  $rcQuery = RecentChange::getQueryInfo();
267  $tables = array_merge( $tables, $rcQuery['tables'] );
268  $fields = array_merge( $rcQuery['fields'], $fields );
269  $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
270 
271  // JOIN on watchlist for users
272  if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
273  $tables[] = 'watchlist';
274  $fields[] = 'wl_user';
275  $fields[] = 'wl_notificationtimestamp';
276  $join_conds['watchlist'] = [ 'LEFT JOIN', [
277  'wl_user' => $user->getId(),
278  'wl_title=rc_title',
279  'wl_namespace=rc_namespace'
280  ] ];
281  }
282 
283  // JOIN on page, used for 'last revision' filter highlight
284  $tables[] = 'page';
285  $fields[] = 'page_latest';
286  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
287 
288  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
290  $tables,
291  $fields,
292  $conds,
293  $join_conds,
294  $query_options,
295  $tagFilter
296  );
297 
298  if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
299  $opts )
300  ) {
301  return false;
302  }
303 
304  if ( $this->areFiltersInConflict() ) {
305  return false;
306  }
307 
308  $orderByAndLimit = [
309  'ORDER BY' => 'rc_timestamp DESC',
310  'LIMIT' => $opts['limit']
311  ];
312  if ( in_array( 'DISTINCT', $query_options ) ) {
313  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
314  // In order to prevent DISTINCT from causing query performance problems,
315  // we have to GROUP BY the primary key. This in turn requires us to add
316  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
317  // start of the GROUP BY
318  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
319  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
320  }
321  // array_merge() is used intentionally here so that hooks can, should
322  // they so desire, override the ORDER BY / LIMIT condition(s); prior to
323  // MediaWiki 1.26 this used to use the plus operator instead, which meant
324  // that extensions weren't able to change these conditions
325  $query_options = array_merge( $orderByAndLimit, $query_options );
326  $rows = $dbr->select(
327  $tables,
328  $fields,
329  // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
330  // knowledge to use an index merge if it wants (it may use some other index though).
331  $conds + [ 'rc_new' => [ 0, 1 ] ],
332  __METHOD__,
333  $query_options,
334  $join_conds
335  );
336 
337  return $rows;
338  }
339 
340  protected function getDB() {
341  return wfGetDB( DB_REPLICA, 'recentchanges' );
342  }
343 
344  public function outputFeedLinks() {
345  $this->addFeedLinks( $this->getFeedQuery() );
346  }
347 
353  protected function getFeedQuery() {
354  $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
355  // API handles empty parameters in a different way
356  return $value !== '';
357  } );
358  $query['action'] = 'feedrecentchanges';
359  $feedLimit = $this->getConfig()->get( 'FeedLimit' );
360  if ( $query['limit'] > $feedLimit ) {
361  $query['limit'] = $feedLimit;
362  }
363 
364  return $query;
365  }
366 
373  public function outputChangesList( $rows, $opts ) {
374  $limit = $opts['limit'];
375 
376  $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
377  && $this->getUser()->getOption( 'shownumberswatching' );
378  $watcherCache = [];
379 
380  $counter = 1;
381  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
382  $list->initChangesListRows( $rows );
383 
384  $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
385  $rclistOutput = $list->beginRecentChangesList();
386  if ( $this->isStructuredFilterUiEnabled() ) {
387  $rclistOutput .= $this->makeLegend();
388  }
389 
390  foreach ( $rows as $obj ) {
391  if ( $limit == 0 ) {
392  break;
393  }
394  $rc = RecentChange::newFromRow( $obj );
395 
396  # Skip CatWatch entries for hidden cats based on user preference
397  if (
398  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
399  !$userShowHiddenCats &&
400  $rc->getParam( 'hidden-cat' )
401  ) {
402  continue;
403  }
404 
405  $rc->counter = $counter++;
406  # Check if the page has been updated since the last visit
407  if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
408  && !empty( $obj->wl_notificationtimestamp )
409  ) {
410  $rc->notificationtimestamp = ( $obj->rc_timestamp >= $obj->wl_notificationtimestamp );
411  } else {
412  $rc->notificationtimestamp = false; // Default
413  }
414  # Check the number of users watching the page
415  $rc->numberofWatchingusers = 0; // Default
416  if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
417  if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
418  $watcherCache[$obj->rc_namespace][$obj->rc_title] =
419  MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchers(
420  new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
421  );
422  }
423  $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
424  }
425 
426  $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user ), $counter );
427  if ( $changeLine !== false ) {
428  $rclistOutput .= $changeLine;
429  --$limit;
430  }
431  }
432  $rclistOutput .= $list->endRecentChangesList();
433 
434  if ( $rows->numRows() === 0 ) {
435  $this->outputNoResults();
436  if ( !$this->including() ) {
437  $this->getOutput()->setStatusCode( 404 );
438  }
439  } else {
440  $this->getOutput()->addHTML( $rclistOutput );
441  }
442  }
443 
450  public function doHeader( $opts, $numRows ) {
451  $this->setTopText( $opts );
452 
453  $defaults = $opts->getAllValues();
454  $nondefaults = $opts->getChangedValues();
455 
456  $panel = [];
457  if ( !$this->isStructuredFilterUiEnabled() ) {
458  $panel[] = $this->makeLegend();
459  }
460  $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
461  $panel[] = '<hr />';
462 
463  $extraOpts = $this->getExtraOptions( $opts );
464  $extraOptsCount = count( $extraOpts );
465  $count = 0;
466  $submit = ' ' . Xml::submitButton( $this->msg( 'recentchanges-submit' )->text() );
467 
468  $out = Xml::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
469  foreach ( $extraOpts as $name => $optionRow ) {
470  # Add submit button to the last row only
471  ++$count;
472  $addSubmit = ( $count === $extraOptsCount ) ? $submit : '';
473 
474  $out .= Xml::openElement( 'tr', [ 'class' => $name . 'Form' ] );
475  if ( is_array( $optionRow ) ) {
476  $out .= Xml::tags(
477  'td',
478  [ 'class' => 'mw-label mw-' . $name . '-label' ],
479  $optionRow[0]
480  );
481  $out .= Xml::tags(
482  'td',
483  [ 'class' => 'mw-input' ],
484  $optionRow[1] . $addSubmit
485  );
486  } else {
487  $out .= Xml::tags(
488  'td',
489  [ 'class' => 'mw-input', 'colspan' => 2 ],
490  $optionRow . $addSubmit
491  );
492  }
493  $out .= Xml::closeElement( 'tr' );
494  }
495  $out .= Xml::closeElement( 'table' );
496 
497  $unconsumed = $opts->getUnconsumedValues();
498  foreach ( $unconsumed as $key => $value ) {
499  $out .= Html::hidden( $key, $value );
500  }
501 
502  $t = $this->getPageTitle();
503  $out .= Html::hidden( 'title', $t->getPrefixedText() );
504  $form = Xml::tags( 'form', [ 'action' => wfScript() ], $out );
505  $panel[] = $form;
506  $panelString = implode( "\n", $panel );
507 
508  $rcoptions = Xml::fieldset(
509  $this->msg( 'recentchanges-legend' )->text(),
510  $panelString,
511  [ 'class' => 'rcoptions cloptions' ]
512  );
513 
514  // Insert a placeholder for RCFilters
515  if ( $this->isStructuredFilterUiEnabled() ) {
516  $rcfilterContainer = Html::element(
517  'div',
518  // TODO: Remove deprecated rcfilters-container class
519  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
520  );
521 
522  $loadingContainer = Html::rawElement(
523  'div',
524  [ 'class' => 'mw-rcfilters-spinner' ],
526  'div',
527  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
528  )
529  );
530 
531  // Wrap both with rcfilters-head
532  $this->getOutput()->addHTML(
534  'div',
535  // TODO: Remove deprecated rcfilters-head class
536  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
537  $rcfilterContainer . $rcoptions
538  )
539  );
540 
541  // Add spinner
542  $this->getOutput()->addHTML( $loadingContainer );
543  } else {
544  $this->getOutput()->addHTML( $rcoptions );
545  }
546 
547  $this->setBottomText( $opts );
548  }
549 
555  function setTopText( FormOptions $opts ) {
556  $message = $this->msg( 'recentchangestext' )->inContentLanguage();
557  if ( !$message->isDisabled() ) {
558  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
559  // Parse the message in this weird ugly way to preserve the ability to include interlanguage
560  // links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
561  // $message->parse() instead. This code is copied from Message::parseText().
562  $parserOutput = MessageCache::singleton()->parse(
563  $message->plain(),
564  $this->getPageTitle(),
565  /*linestart*/true,
566  // Message class sets the interface flag to false when parsing in a language different than
567  // user language, and this is wiki content language
568  /*interface*/false,
569  $contLang
570  );
571  $content = $parserOutput->getText( [
572  'enableSectionEditLinks' => false,
573  ] );
574  // Add only metadata here (including the language links), text is added below
575  $this->getOutput()->addParserOutputMetadata( $parserOutput );
576 
577  $langAttributes = [
578  'lang' => $contLang->getHtmlCode(),
579  'dir' => $contLang->getDir(),
580  ];
581 
582  $topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
583 
584  if ( $this->isStructuredFilterUiEnabled() ) {
585  // Check whether the widget is already collapsed or expanded
586  $collapsedState = $this->getRequest()->getCookie( 'rcfilters-toplinks-collapsed-state' );
587  // Note that an empty/unset cookie means collapsed, so check for !== 'expanded'
588  $topLinksAttributes[ 'class' ] .= $collapsedState !== 'expanded' ?
589  ' mw-recentchanges-toplinks-collapsed' : '';
590 
591  $this->getOutput()->enableOOUI();
592  $contentTitle = new OOUI\ButtonWidget( [
593  'classes' => [ 'mw-recentchanges-toplinks-title' ],
594  'label' => new OOUI\HtmlSnippet( $this->msg( 'rcfilters-other-review-tools' )->parse() ),
595  'framed' => false,
596  'indicator' => $collapsedState !== 'expanded' ? 'down' : 'up',
597  'flags' => [ 'progressive' ],
598  ] );
599 
600  $contentWrapper = Html::rawElement( 'div',
601  array_merge(
602  [ 'class' => 'mw-recentchanges-toplinks-content mw-collapsible-content' ],
603  $langAttributes
604  ),
605  $content
606  );
607  $content = $contentTitle . $contentWrapper;
608  } else {
609  // Language direction should be on the top div only
610  // if the title is not there. If it is there, it's
611  // interface direction, and the language/dir attributes
612  // should be on the content itself
613  $topLinksAttributes = array_merge( $topLinksAttributes, $langAttributes );
614  }
615 
616  $this->getOutput()->addHTML(
617  Html::rawElement( 'div', $topLinksAttributes, $content )
618  );
619  }
620  }
621 
628  function getExtraOptions( $opts ) {
629  $opts->consumeValues( [
630  'namespace', 'invert', 'associated', 'tagfilter'
631  ] );
632 
633  $extraOpts = [];
634  $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
635 
637  $opts['tagfilter'], false, $this->getContext() );
638  if ( count( $tagFilter ) ) {
639  $extraOpts['tagfilter'] = $tagFilter;
640  }
641 
642  // Don't fire the hook for subclasses. (Or should we?)
643  if ( $this->getName() === 'Recentchanges' ) {
644  Hooks::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
645  }
646 
647  return $extraOpts;
648  }
649 
653  protected function addModules() {
654  parent::addModules();
655  $out = $this->getOutput();
656  $out->addModules( 'mediawiki.special.recentchanges' );
657  }
658 
666  public function checkLastModified() {
667  $dbr = $this->getDB();
668  $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
669 
670  return $lastmod;
671  }
672 
679  protected function namespaceFilterForm( FormOptions $opts ) {
680  $nsSelect = Html::namespaceSelector(
681  [ 'selected' => $opts['namespace'], 'all' => '', 'in-user-lang' => true ],
682  [ 'name' => 'namespace', 'id' => 'namespace' ]
683  );
684  $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' );
685  $attribs = [ 'class' => [ 'mw-input-with-label' ] ];
686  // Hide the checkboxes when the namespace filter is set to 'all'.
687  if ( $opts['namespace'] === '' ) {
688  $attribs['class'][] = 'mw-input-hidden';
689  }
690  $invert = Html::rawElement( 'span', $attribs, Xml::checkLabel(
691  $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
692  $opts['invert'],
693  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
694  ) );
695  $associated = Html::rawElement( 'span', $attribs, Xml::checkLabel(
696  $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
697  $opts['associated'],
698  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
699  ) );
700 
701  return [ $nsLabel, "$nsSelect $invert $associated" ];
702  }
703 
712  function filterByCategories( &$rows, FormOptions $opts ) {
713  wfDeprecated( __METHOD__, '1.31' );
714 
715  $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
716 
717  if ( $categories === [] ) {
718  return;
719  }
720 
721  # Filter categories
722  $cats = [];
723  foreach ( $categories as $cat ) {
724  $cat = trim( $cat );
725  if ( $cat == '' ) {
726  continue;
727  }
728  $cats[] = $cat;
729  }
730 
731  # Filter articles
732  $articles = [];
733  $a2r = [];
734  $rowsarr = [];
735  foreach ( $rows as $k => $r ) {
736  $nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
737  $id = $nt->getArticleID();
738  if ( $id == 0 ) {
739  continue; # Page might have been deleted...
740  }
741  if ( !in_array( $id, $articles ) ) {
742  $articles[] = $id;
743  }
744  if ( !isset( $a2r[$id] ) ) {
745  $a2r[$id] = [];
746  }
747  $a2r[$id][] = $k;
748  $rowsarr[$k] = $r;
749  }
750 
751  # Shortcut?
752  if ( $articles === [] || $cats === [] ) {
753  return;
754  }
755 
756  # Look up
757  $catFind = new CategoryFinder;
758  $catFind->seed( $articles, $cats, $opts['categories_any'] ? 'OR' : 'AND' );
759  $match = $catFind->run();
760 
761  # Filter
762  $newrows = [];
763  foreach ( $match as $id ) {
764  foreach ( $a2r[$id] as $rev ) {
765  $k = $rev;
766  $newrows[$k] = $rowsarr[$k];
767  }
768  }
769  $rows = new FakeResultWrapper( array_values( $newrows ) );
770  }
771 
781  function makeOptionsLink( $title, $override, $options, $active = false ) {
782  $params = $this->convertParamsForLink( $override + $options );
783 
784  if ( $active ) {
785  $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
786  }
787 
788  return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
789  'data-params' => json_encode( $override ),
790  'data-keys' => implode( ',', array_keys( $override ) ),
791  ], $params );
792  }
793 
802  function optionsPanel( $defaults, $nondefaults, $numRows ) {
803  $options = $nondefaults + $defaults;
804 
805  $note = '';
806  $msg = $this->msg( 'rclegend' );
807  if ( !$msg->isDisabled() ) {
808  $note .= Html::rawElement(
809  'div',
810  [ 'class' => 'mw-rclegend' ],
811  $msg->parse()
812  );
813  }
814 
815  $lang = $this->getLanguage();
816  $user = $this->getUser();
817  $config = $this->getConfig();
818  if ( $options['from'] ) {
819  $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
820  [ 'from' => '' ], $nondefaults );
821 
822  $noteFromMsg = $this->msg( 'rcnotefrom' )
823  ->numParams( $options['limit'] )
824  ->params(
825  $lang->userTimeAndDate( $options['from'], $user ),
826  $lang->userDate( $options['from'], $user ),
827  $lang->userTime( $options['from'], $user )
828  )
829  ->numParams( $numRows );
830  $note .= Html::rawElement(
831  'span',
832  [ 'class' => 'rcnotefrom' ],
833  $noteFromMsg->parse()
834  ) .
835  ' ' .
837  'span',
838  [ 'class' => 'rcoptions-listfromreset' ],
839  $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
840  ) .
841  '<br />';
842  }
843 
844  # Sort data for display and make sure it's unique after we've added user data.
845  $linkLimits = $config->get( 'RCLinkLimits' );
846  $linkLimits[] = $options['limit'];
847  sort( $linkLimits );
848  $linkLimits = array_unique( $linkLimits );
849 
850  $linkDays = $config->get( 'RCLinkDays' );
851  $linkDays[] = $options['days'];
852  sort( $linkDays );
853  $linkDays = array_unique( $linkDays );
854 
855  // limit links
856  $cl = [];
857  foreach ( $linkLimits as $value ) {
858  $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
859  [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
860  }
861  $cl = $lang->pipeList( $cl );
862 
863  // day links, reset 'from' to none
864  $dl = [];
865  foreach ( $linkDays as $value ) {
866  $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
867  [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
868  }
869  $dl = $lang->pipeList( $dl );
870 
871  $showhide = [ 'show', 'hide' ];
872 
873  $links = [];
874 
875  foreach ( $this->getLegacyShowHideFilters() as $key => $filter ) {
876  $msg = $filter->getShowHide();
877  $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
878  // Extensions can define additional filters, but don't need to define the corresponding
879  // messages. If they don't exist, just fall back to 'show' and 'hide'.
880  if ( !$linkMessage->exists() ) {
881  $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
882  }
883 
884  $link = $this->makeOptionsLink( $linkMessage->text(),
885  [ $key => 1 - $options[$key] ], $nondefaults );
886 
887  $attribs = [
888  'class' => "$msg rcshowhideoption clshowhideoption",
889  'data-filter-name' => $filter->getName(),
890  ];
891 
892  if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
893  $attribs['data-feature-in-structured-ui'] = true;
894  }
895 
896  $links[] = Html::rawElement(
897  'span',
898  $attribs,
899  $this->msg( $msg )->rawParams( $link )->parse()
900  );
901  }
902 
903  // show from this onward link
904  $timestamp = wfTimestampNow();
905  $now = $lang->userTimeAndDate( $timestamp, $user );
906  $timenow = $lang->userTime( $timestamp, $user );
907  $datenow = $lang->userDate( $timestamp, $user );
908  $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
909 
910  $rclinks = Html::rawElement(
911  'span',
912  [ 'class' => 'rclinks' ],
913  $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )->parse()
914  );
915 
916  $rclistfrom = Html::rawElement(
917  'span',
918  [ 'class' => 'rclistfrom' ],
919  $this->makeOptionsLink(
920  $this->msg( 'rclistfrom' )->plaintextParams( $now, $timenow, $datenow )->parse(),
921  [ 'from' => $timestamp, 'fromFormatted' => $now ],
922  $nondefaults
923  )
924  );
925 
926  return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
927  }
928 
929  public function isIncludable() {
930  return true;
931  }
932 
933  protected function getCacheTTL() {
934  return 60 * 5;
935  }
936 
937  public function getDefaultLimit() {
938  $systemPrefValue = $this->getUser()->getIntOption( 'rclimit' );
939  // Prefer the RCFilters-specific preference if RCFilters is enabled
940  if ( $this->isStructuredFilterUiEnabled() ) {
941  return $this->getUser()->getIntOption( static::$limitPreferenceName, $systemPrefValue );
942  }
943 
944  // Otherwise, use the system rclimit preference value
945  return $systemPrefValue;
946  }
947 }
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:756
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
namespaceFilterForm(FormOptions $opts)
Creates the choose namespace selection.
const RC_CATEGORIZE
Definition: Defines.php:126
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition: hooks.txt:2621
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used $groups Array of ChangesListFilterGroup objects(added in 1.34) 'FileDeleteComplete' null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1529
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
getContext()
Gets the context this SpecialPage is executed in.
$batch execute()
The "CategoryFinder" class takes a list of articles, creates an internal representation of all their ...
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
including( $x=null)
Whether the special page is being evaluated via transclusion.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
static array static newFromRow( $row)
if(!isset( $args[0])) $lang
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$value
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists last changes made to the wiki.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
registerFiltersFromDefinitions(array $definition)
Register filters from a definition object.
getOutput()
Get the OutputPage being used for this instance.
getOptions()
Get the current FormOptions for this request.
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:960
optionsPanel( $defaults, $nondefaults, $numRows)
Creates the options panel.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3039
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:767
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:24
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
const LIST_AND
Definition: Defines.php:39
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:609
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
$params
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1972
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1972
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
$filter
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1748
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:358
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:87
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
const LIST_OR
Definition: Defines.php:42
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:591
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
addFeedLinks( $params)
Adds RSS/atom links.
outputNoResults()
Add the "no results" message to the output.
outputChangesList( $rows, $opts)
Build and output the actual changes list.
convertParamsForLink( $params)
Convert parameters values from true/false to 1/0 so they are not omitted by wfArrayToCgi() T38524...
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
getName()
Get the name of this Special Page.
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Special page which uses a ChangesList to show query results.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
seed( $articleIds, $categories, $mode='AND', $maxdepth=-1)
Initializes the instance.
Overloads the relevant methods of the real ResultsWrapper so it doesn&#39;t go anywhere near an actual da...
__construct( $name='Recentchanges', $restriction='')
getUser()
Shortcut to get the User executing this instance.
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:796
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getConfig()
Shortcut to get main config object.
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2621
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object...
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
const DB_REPLICA
Definition: defines.php:25
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:419
getRequest()
Get the WebRequest being used for this instance.
getFeedQuery()
Get URL query parameters for action=feedrecentchanges API feed of current recent changes view...
makeLegend()
Return the legend displayed within the fieldset.
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
Definition: ChangeTags.php:858
getExtraOptions( $opts)
Get options to be displayed in a form.
$content
Definition: pageupdater.txt:72
filterByCategories(&$rows, FormOptions $opts)
Filter $rows by categories set in $opts.
addModules()
Add page-specific modules.
transformFilterDefinition(array $filterDefinition)
getPageTitle( $subpage=false)
Get a self-referential title object.
static singleton()
Get the signleton instance of this class.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
checkLastModified()
Get last modified date, for client caching Don&#39;t use this if we are using the patrol feature...
makeOptionsLink( $title, $override, $options, $active=false)
Makes change an option link which carries all the other options.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:886