MediaWiki  master
SpecialContributions.php
Go to the documentation of this file.
1 <?php
33 use Wikimedia\IPUtils;
35 
42  protected $opts;
43 
46 
49 
51  private $loadBalancer;
52 
54  private $actorMigration;
55 
57  private $revisionStore;
58 
60  private $namespaceInfo;
61 
63  private $userNameUtils;
64 
67 
70 
72  private $pager = null;
73 
85  public function __construct(
95  ) {
96  parent::__construct( 'Contributions' );
97  // This class is extended and therefore falls back to global state - T269521
98  $services = MediaWikiServices::getInstance();
99  $this->linkBatchFactory = $linkBatchFactory ?? $services->getLinkBatchFactory();
100  $this->permissionManager = $permissionManager ?? $services->getPermissionManager();
101  $this->loadBalancer = $loadBalancer ?? $services->getDBLoadBalancer();
102  $this->actorMigration = $actorMigration ?? $services->getActorMigration();
103  $this->revisionStore = $revisionStore ?? $services->getRevisionStore();
104  $this->namespaceInfo = $namespaceInfo ?? $services->getNamespaceInfo();
105  $this->userNameUtils = $userNameUtils ?? $services->getUserNameUtils();
106  $this->userNamePrefixSearch = $userNamePrefixSearch ?? $services->getUserNamePrefixSearch();
107  $this->userOptionsLookup = $userOptionsLookup ?? $services->getUserOptionsLookup();
108  }
109 
110  public function execute( $par ) {
111  $this->setHeaders();
112  $this->outputHeader();
113  $out = $this->getOutput();
114  // Modules required for viewing the list of contributions (also when included on other pages)
115  $out->addModuleStyles( [
116  'jquery.makeCollapsible.styles',
117  'mediawiki.interface.helpers.styles',
118  'mediawiki.special',
119  'mediawiki.special.changeslist',
120  ] );
121  $out->addModules( [
122  'mediawiki.special.recentchanges',
123  // Certain skins e.g. Minerva might have disabled this module.
124  'mediawiki.page.ready'
125  ] );
126  $this->addHelpLink( 'Help:User contributions' );
127 
128  $this->opts = [];
129  $request = $this->getRequest();
130 
131  $target = $par ?? $request->getVal( 'target' );
132 
133  $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
134 
135  if ( !strlen( $target ) ) {
136  if ( !$this->including() ) {
137  $out->addHTML( $this->getForm( $this->opts ) );
138  }
139 
140  return;
141  }
142 
143  $user = $this->getUser();
144 
145  $this->opts['limit'] = $request->getInt( 'limit', $this->userOptionsLookup->getIntOption( $user, 'rclimit' ) );
146  $this->opts['target'] = $target;
147  $this->opts['topOnly'] = $request->getBool( 'topOnly' );
148  $this->opts['newOnly'] = $request->getBool( 'newOnly' );
149  $this->opts['hideMinor'] = $request->getBool( 'hideMinor' );
150 
151  $ns = $request->getVal( 'namespace', null );
152  if ( $ns !== null && $ns !== '' && $ns !== 'all' ) {
153  $this->opts['namespace'] = intval( $ns );
154  } else {
155  $this->opts['namespace'] = '';
156  }
157 
158  // Backwards compatibility: Before using OOUI form the old HTML form had
159  // fields for nsInvert and associated. These have now been replaced with the
160  // wpFilters query string parameters. These are retained to keep old URIs working.
161  $this->opts['associated'] = $request->getBool( 'associated' );
162  $this->opts['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
163  $nsFilters = $request->getArray( 'wpfilters', null );
164  if ( $nsFilters !== null ) {
165  $this->opts['associated'] = in_array( 'associated', $nsFilters );
166  $this->opts['nsInvert'] = in_array( 'nsInvert', $nsFilters );
167  }
168 
169  $this->opts['tagfilter'] = (string)$request->getVal( 'tagfilter' );
170 
171  // Allows reverts to have the bot flag in recent changes. It is just here to
172  // be passed in the form at the top of the page
173  if ( MediaWikiServices::getInstance()
174  ->getPermissionManager()
175  ->userHasRight( $user, 'markbotedits' ) && $request->getBool( 'bot' )
176  ) {
177  $this->opts['bot'] = '1';
178  }
179 
180  $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
181  # Offset overrides year/month selection
182  if ( !$skip ) {
183  $this->opts['year'] = $request->getVal( 'year' );
184  $this->opts['month'] = $request->getVal( 'month' );
185 
186  $this->opts['start'] = $request->getVal( 'start' );
187  $this->opts['end'] = $request->getVal( 'end' );
188  }
189 
190  $id = 0;
191  if ( ExternalUserNames::isExternal( $target ) ) {
192  $userObj = User::newFromName( $target, false );
193  if ( !$userObj ) {
194  $out->addHTML( $this->getForm( $this->opts ) );
195  return;
196  }
197 
198  $out->addSubtitle( $this->contributionsSub( $userObj ) );
199  $out->setHTMLTitle( $this->msg(
200  'pagetitle',
201  $this->msg( 'contributions-title', $target )->plain()
202  )->inContentLanguage() );
203  } else {
204  $nt = Title::makeTitleSafe( NS_USER, $target );
205  if ( !$nt ) {
206  $out->addHTML( $this->getForm( $this->opts ) );
207  return;
208  }
209  $userObj = User::newFromName( $nt->getText(), false );
210  if ( !$userObj ) {
211  $out->addHTML( $this->getForm( $this->opts ) );
212  return;
213  }
214  $id = $userObj->getId();
215 
216  $target = $nt->getText();
217  $out->addSubtitle( $this->contributionsSub( $userObj ) );
218  $out->setHTMLTitle( $this->msg(
219  'pagetitle',
220  $this->msg( 'contributions-title', $target )->plain()
221  )->inContentLanguage() );
222 
223  # For IP ranges, we want the contributionsSub, but not the skin-dependent
224  # links under 'Tools', which may include irrelevant links like 'Logs'.
225  if ( !IPUtils::isValidRange( $target ) &&
226  ( User::isIP( $target ) || $userObj->isRegistered() )
227  ) {
228  // Don't add non-existent users, because hidden users
229  // that we add here will be removed later to pretend
230  // that they don't exist, and if users that actually don't
231  // exist are added here and then not removed, it exposes
232  // which users exist and are hidden vs. which actually don't
233  // exist. But, do set the relevant user for single IPs.
234  $this->getSkin()->setRelevantUser( $userObj );
235  }
236  }
237 
238  $this->opts = ContribsPager::processDateFilter( $this->opts );
239 
240  if ( $this->opts['namespace'] < NS_MAIN ) {
241  $this->getOutput()->wrapWikiMsg(
242  "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
243  [ 'negative-namespace-not-supported' ]
244  );
245  $out->addHTML( $this->getForm( $this->opts ) );
246  return;
247  }
248 
249  $feedType = $request->getVal( 'feed' );
250 
251  $feedParams = [
252  'action' => 'feedcontributions',
253  'user' => $target,
254  ];
255  if ( $this->opts['topOnly'] ) {
256  $feedParams['toponly'] = true;
257  }
258  if ( $this->opts['newOnly'] ) {
259  $feedParams['newonly'] = true;
260  }
261  if ( $this->opts['hideMinor'] ) {
262  $feedParams['hideminor'] = true;
263  }
264  if ( $this->opts['deletedOnly'] ) {
265  $feedParams['deletedonly'] = true;
266  }
267  if ( $this->opts['tagfilter'] !== '' ) {
268  $feedParams['tagfilter'] = $this->opts['tagfilter'];
269  }
270  if ( $this->opts['namespace'] !== '' ) {
271  $feedParams['namespace'] = $this->opts['namespace'];
272  }
273  // Don't use year and month for the feed URL, but pass them on if
274  // we redirect to API (if $feedType is specified)
275  if ( $feedType && isset( $this->opts['year'] ) ) {
276  $feedParams['year'] = $this->opts['year'];
277  }
278  if ( $feedType && isset( $this->opts['month'] ) ) {
279  $feedParams['month'] = $this->opts['month'];
280  }
281 
282  if ( $feedType ) {
283  // Maintain some level of backwards compatibility
284  // If people request feeds using the old parameters, redirect to API
285  $feedParams['feedformat'] = $feedType;
286  $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
287 
288  $out->redirect( $url, '301' );
289 
290  return;
291  }
292 
293  // Add RSS/atom links
294  $this->addFeedLinks( $feedParams );
295 
296  if ( $this->getHookRunner()->onSpecialContributionsBeforeMainOutput(
297  $id, $userObj, $this )
298  ) {
299  if ( !$this->including() ) {
300  $out->addHTML( $this->getForm( $this->opts ) );
301  }
302  $pager = $this->getPager();
303  if ( IPUtils::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
304  // Valid range, but outside CIDR limit.
305  $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
306  $limit = $limits[ IPUtils::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
307  $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
308  } elseif ( !$pager->getNumRows() ) {
309  $out->addWikiMsg( 'nocontribs', $target );
310  } else {
311  // @todo We just want a wiki ID here, not a "DB domain", but
312  // current status of MediaWiki conflates the two. See T235955.
313  $poolKey = $this->loadBalancer->getLocalDomainID() . ':SpecialContributions:';
314  if ( $this->getUser()->isAnon() ) {
315  $poolKey .= 'a:' . $this->getUser()->getName();
316  } else {
317  $poolKey .= 'u:' . $this->getUser()->getId();
318  }
319  $work = new PoolCounterWorkViaCallback( 'SpecialContributions', $poolKey, [
320  'doWork' => function () use ( $pager, $out ) {
321  # Show a message about replica DB lag, if applicable
322  $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
323  if ( $lag > 0 ) {
324  $out->showLagWarning( $lag );
325  }
326 
327  $output = $pager->getBody();
328  if ( !$this->including() ) {
329  $output = $pager->getNavigationBar() .
330  $output .
332  }
333  $out->addHTML( $output );
334  },
335  'error' => function () use ( $out ) {
336  $msg = $this->getUser()->isAnon()
337  ? 'sp-contributions-concurrency-ip'
338  : 'sp-contributions-concurrency-user';
339  $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>", $msg );
340  }
341  ] );
342  $work->execute();
343  }
344 
345  $out->preventClickjacking( $pager->getPreventClickjacking() );
346 
347  # Show the appropriate "footer" message - WHOIS tools, etc.
348  if ( IPUtils::isValidRange( $target ) && $pager->isQueryableRange( $target ) ) {
349  $message = 'sp-contributions-footer-anon-range';
350  } elseif ( IPUtils::isIPAddress( $target ) ) {
351  $message = 'sp-contributions-footer-anon';
352  } elseif ( $userObj->isAnon() ) {
353  // No message for non-existing users
354  $message = '';
355  } elseif ( $userObj->isHidden() &&
356  !$this->permissionManager->userHasRight( $this->getUser(), 'hideuser' )
357  ) {
358  // User is registered, but make sure that the viewer can see them, to avoid
359  // having different behavior for missing and hidden users; see T120883
360  $message = '';
361  } else {
362  // Not hidden, or hidden but the viewer can still see it
363  $message = 'sp-contributions-footer';
364  }
365 
366  if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
367  $out->wrapWikiMsg(
368  "<div class='mw-contributions-footer'>\n$1\n</div>",
369  [ $message, $target ] );
370  }
371  }
372  }
373 
381  protected function contributionsSub( $userObj ) {
382  $isAnon = $userObj->isAnon();
383  if ( !$isAnon && $userObj->isHidden() &&
384  !$this->permissionManager->userHasRight( $this->getUser(), 'hideuser' )
385  ) {
386  // T120883 if the user is hidden and the viewer cannot see hidden
387  // users, pretend like it does not exist at all.
388  $isAnon = true;
389  }
390 
391  if ( $isAnon ) {
392  // Show a warning message that the user being searched for doesn't exist.
393  // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
394  // but returns false for IP ranges. We don't want to suggest either of these are
395  // valid usernames which we would with the 'contributions-userdoesnotexist' message.
396  if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
397  $this->getOutput()->wrapWikiMsg(
398  "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
399  [
400  'contributions-userdoesnotexist',
401  wfEscapeWikiText( $userObj->getName() ),
402  ]
403  );
404  if ( !$this->including() ) {
405  $this->getOutput()->setStatusCode( 404 );
406  }
407  }
408  $user = htmlspecialchars( $userObj->getName() );
409  } else {
410  $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
411  }
412  $nt = $userObj->getUserPage();
413  $talk = $userObj->getTalkPage();
414  $links = '';
415 
416  // T211910. Don't show action links if a range is outside block limit
417  $showForIp = IPUtils::isValid( $userObj ) ||
418  ( IPUtils::isValidRange( $userObj ) && $this->getPager()->isQueryableRange( $userObj ) );
419 
420  if ( $talk && ( $userObj->isRegistered() || $showForIp ) ) {
421  $tools = self::getUserLinks( $this, $userObj );
422  $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
423  foreach ( $tools as $tool ) {
424  $links .= Html::rawElement( 'span', [], $tool ) . ' ';
425  }
426  $links = trim( $links ) . Html::closeElement( 'span' );
427 
428  // Show a note if the user is blocked and display the last block log entry.
429  // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
430  // and also this will display a totally irrelevant log entry as a current block.
431  if ( !$this->including() ) {
432  // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
433  // and not a user object.
434  if ( $userObj->isIPRange() ) {
435  $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
436  } else {
437  $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
438  }
439 
440  if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
441  if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
442  $nt = $this->namespaceInfo->getCanonicalName( NS_USER ) . ':' . $block->getTarget();
443  }
444 
445  $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
446  if ( $userObj->isAnon() ) {
447  $msgKey = $block->isSitewide() ?
448  'sp-contributions-blocked-notice-anon' :
449  'sp-contributions-blocked-notice-anon-partial';
450  } else {
451  $msgKey = $block->isSitewide() ?
452  'sp-contributions-blocked-notice' :
453  'sp-contributions-blocked-notice-partial';
454  }
455  // Allow local styling overrides for different types of block
456  $class = $block->isSitewide() ?
457  'mw-contributions-blocked-notice' :
458  'mw-contributions-blocked-notice-partial';
460  $out,
461  'block',
462  $nt,
463  '',
464  [
465  'lim' => 1,
466  'showIfEmpty' => false,
467  'msgKey' => [
468  $msgKey,
469  $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
470  ],
471  'offset' => '', # don't use WebRequest parameter offset
472  'wrap' => Html::rawElement(
473  'div',
474  [ 'class' => $class ],
475  '$1'
476  ),
477  ]
478  );
479  }
480  }
481  }
482 
483  return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
484  $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
485  . ' ' . $links
486  );
487  }
488 
499  public static function getUserLinks(
500  SpecialPage $sp,
501  User $target,
502  PermissionManager $permissionManager = null,
503  HookRunner $hookRunner = null
504  ) {
505  // Fallback to global state, if not provided
506  $permissionManager = $permissionManager ?? MediaWikiServices::getInstance()->getPermissionManager();
507  $hookRunner = $hookRunner ?? Hooks::runner();
508 
509  $id = $target->getId();
510  $username = $target->getName();
511  $userpage = $target->getUserPage();
512  $talkpage = $target->getTalkPage();
513  $isIP = IPUtils::isValid( $username );
514  $isRange = IPUtils::isValidRange( $username );
515 
516  $linkRenderer = $sp->getLinkRenderer();
517 
518  $tools = [];
519  # No talk pages for IP ranges.
520  if ( !$isRange ) {
521  $tools['user-talk'] = $linkRenderer->makeLink(
522  $talkpage,
523  $sp->msg( 'sp-contributions-talk' )->text()
524  );
525  }
526 
527  # Block / Change block / Unblock links
528  if ( $permissionManager->userHasRight( $sp->getUser(), 'block' ) ) {
529  if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
530  $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
531  SpecialPage::getTitleFor( 'Block', $username ),
532  $sp->msg( 'change-blocklink' )->text()
533  );
534  $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
535  SpecialPage::getTitleFor( 'Unblock', $username ),
536  $sp->msg( 'unblocklink' )->text()
537  );
538  } else { # User is not blocked
539  $tools['block'] = $linkRenderer->makeKnownLink( # Block link
540  SpecialPage::getTitleFor( 'Block', $username ),
541  $sp->msg( 'blocklink' )->text()
542  );
543  }
544  }
545 
546  # Block log link
547  $tools['log-block'] = $linkRenderer->makeKnownLink(
548  SpecialPage::getTitleFor( 'Log', 'block' ),
549  $sp->msg( 'sp-contributions-blocklog' )->text(),
550  [],
551  [ 'page' => $userpage->getPrefixedText() ]
552  );
553 
554  # Suppression log link (T61120)
555  if ( $permissionManager->userHasRight( $sp->getUser(), 'suppressionlog' ) ) {
556  $tools['log-suppression'] = $linkRenderer->makeKnownLink(
557  SpecialPage::getTitleFor( 'Log', 'suppress' ),
558  $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
559  [],
560  [ 'offender' => $username ]
561  );
562  }
563 
564  # Don't show some links for IP ranges
565  if ( !$isRange ) {
566  # Uploads: hide if IPs cannot upload (T220674)
567  if ( !$isIP || $permissionManager->userHasRight( $target, 'upload' ) ) {
568  $tools['uploads'] = $linkRenderer->makeKnownLink(
569  SpecialPage::getTitleFor( 'Listfiles', $username ),
570  $sp->msg( 'sp-contributions-uploads' )->text()
571  );
572  }
573 
574  # Other logs link
575  # Todo: T146628
576  $tools['logs'] = $linkRenderer->makeKnownLink(
577  SpecialPage::getTitleFor( 'Log', $username ),
578  $sp->msg( 'sp-contributions-logs' )->text()
579  );
580 
581  # Add link to deleted user contributions for priviledged users
582  # Todo: T183457
583  if ( $permissionManager->userHasRight( $sp->getUser(), 'deletedhistory' ) ) {
584  $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
585  SpecialPage::getTitleFor( 'DeletedContributions', $username ),
586  $sp->msg( 'sp-contributions-deleted', $username )->text()
587  );
588  }
589  }
590 
591  # Add a link to change user rights for privileged users
592  $userrightsPage = new UserrightsPage();
593  $userrightsPage->setContext( $sp->getContext() );
594  if ( $userrightsPage->userCanChangeRights( $target ) ) {
595  $tools['userrights'] = $linkRenderer->makeKnownLink(
596  SpecialPage::getTitleFor( 'Userrights', $username ),
597  $sp->msg( 'sp-contributions-userrights', $username )->text()
598  );
599  }
600 
601  $hookRunner->onContributionsToolLinks( $id, $userpage, $tools, $sp );
602 
603  return $tools;
604  }
605 
612  protected function getForm( array $pagerOptions ) {
613  $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
614  // Modules required only for the form
615  $this->getOutput()->addModules( [
616  'mediawiki.special.contributions',
617  ] );
618  $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
619  $this->getOutput()->enableOOUI();
620  $fields = [];
621 
622  # Add hidden params for tracking except for parameters in $skipParameters
623  $skipParameters = [
624  'namespace',
625  'nsInvert',
626  'deletedOnly',
627  'target',
628  'year',
629  'month',
630  'start',
631  'end',
632  'topOnly',
633  'newOnly',
634  'hideMinor',
635  'associated',
636  'tagfilter'
637  ];
638 
639  foreach ( $this->opts as $name => $value ) {
640  if ( in_array( $name, $skipParameters ) ) {
641  continue;
642  }
643 
644  $fields[$name] = [
645  'name' => $name,
646  'type' => 'hidden',
647  'default' => $value,
648  ];
649  }
650 
651  $target = $this->opts['target'] ?? null;
652  $fields['target'] = [
653  'type' => 'user',
654  'default' => $target ?
655  str_replace( '_', ' ', $target ) : '' ,
656  'label' => $this->msg( 'sp-contributions-username' )->text(),
657  'name' => 'target',
658  'id' => 'mw-target-user-or-ip',
659  'size' => 40,
660  'autofocus' => !$target,
661  'section' => 'contribs-top',
662  ];
663 
664  $ns = $this->opts['namespace'] ?? null;
665  $fields['namespace'] = [
666  'type' => 'namespaceselect',
667  'label' => $this->msg( 'namespace' )->text(),
668  'name' => 'namespace',
669  'cssclass' => 'namespaceselector',
670  'default' => $ns,
671  'id' => 'namespace',
672  'section' => 'contribs-top',
673  ];
674  $request = $this->getRequest();
675  $nsFilters = $request->getArray( 'wpfilters' );
676  $fields['nsFilters'] = [
677  'class' => HTMLMultiSelectField::class,
678  'label' => '',
679  'name' => 'wpfilters',
680  'flatlist' => true,
681  // Only shown when namespaces are selected.
682  'cssclass' => $ns === '' ?
683  'contribs-ns-filters mw-input-with-label mw-input-hidden' :
684  'contribs-ns-filters mw-input-with-label',
685  // `contribs-ns-filters` class allows these fields to be toggled on/off by JavaScript.
686  // See resources/src/mediawiki.special.recentchanges.js
687  'infusable' => true,
688  'options-messages' => [
689  'invert' => 'nsInvert',
690  'namespace_association' => 'associated',
691  ],
692  'default' => $nsFilters,
693  'section' => 'contribs-top',
694  ];
695  $fields['tagfilter'] = [
696  'type' => 'tagfilter',
697  'cssclass' => 'mw-tagfilter-input',
698  'id' => 'tagfilter',
699  'label-message' => [ 'tag-filter', 'parse' ],
700  'name' => 'tagfilter',
701  'size' => 20,
702  'section' => 'contribs-top',
703  ];
704 
705  if ( $this->permissionManager->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
706  $fields['deletedOnly'] = [
707  'type' => 'check',
708  'id' => 'mw-show-deleted-only',
709  'label' => $this->msg( 'history-show-deleted' )->text(),
710  'name' => 'deletedOnly',
711  'section' => 'contribs-top',
712  ];
713  }
714 
715  $fields['topOnly'] = [
716  'type' => 'check',
717  'id' => 'mw-show-top-only',
718  'label' => $this->msg( 'sp-contributions-toponly' )->text(),
719  'name' => 'topOnly',
720  'section' => 'contribs-top',
721  ];
722  $fields['newOnly'] = [
723  'type' => 'check',
724  'id' => 'mw-show-new-only',
725  'label' => $this->msg( 'sp-contributions-newonly' )->text(),
726  'name' => 'newOnly',
727  'section' => 'contribs-top',
728  ];
729  $fields['hideMinor'] = [
730  'type' => 'check',
731  'cssclass' => 'mw-hide-minor-edits',
732  'id' => 'mw-show-new-only',
733  'label' => $this->msg( 'sp-contributions-hideminor' )->text(),
734  'name' => 'hideMinor',
735  'section' => 'contribs-top',
736  ];
737 
738  // Allow additions at this point to the filters.
739  $rawFilters = [];
740  $this->getHookRunner()->onSpecialContributions__getForm__filters(
741  $this, $rawFilters );
742  foreach ( $rawFilters as $filter ) {
743  // Backwards compatibility support for previous hook function signature.
744  if ( is_string( $filter ) ) {
745  $fields[] = [
746  'type' => 'info',
747  'default' => $filter,
748  'raw' => true,
749  'section' => 'contribs-top',
750  ];
751  wfDeprecated(
752  'A SpecialContributions::getForm::filters hook handler returned ' .
753  'an array of strings, this is deprecated since MediaWiki 1.33',
754  '1.33', false, false
755  );
756  } else {
757  // Preferred append method.
758  $fields[] = $filter;
759  }
760  }
761 
762  $fields['start'] = [
763  'type' => 'date',
764  'default' => '',
765  'id' => 'mw-date-start',
766  'label' => $this->msg( 'date-range-from' )->text(),
767  'name' => 'start',
768  'section' => 'contribs-date',
769  ];
770  $fields['end'] = [
771  'type' => 'date',
772  'default' => '',
773  'id' => 'mw-date-end',
774  'label' => $this->msg( 'date-range-to' )->text(),
775  'name' => 'end',
776  'section' => 'contribs-date',
777  ];
778 
779  $htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
780  $htmlForm
781  ->setMethod( 'get' )
782  // When offset is defined, the user is paging through results
783  // so we hide the form by default to allow users to focus on browsing
784  // rather than defining search parameters
785  ->setCollapsibleOptions(
786  ( $pagerOptions['target'] ?? null ) ||
787  ( $pagerOptions['start'] ?? null ) ||
788  ( $pagerOptions['end'] ?? null )
789  )
790  ->setAction( wfScript() )
791  ->setSubmitText( $this->msg( 'sp-contributions-submit' )->text() )
792  ->setWrapperLegend( $this->msg( 'sp-contributions-search' )->text() );
793 
794  $explain = $this->msg( 'sp-contributions-explain' );
795  if ( !$explain->isBlank() ) {
796  $htmlForm->addFooterText( "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>" );
797  }
798 
799  $htmlForm->loadData();
800 
801  return $htmlForm->getHTML( false );
802  }
803 
812  public function prefixSearchSubpages( $search, $limit, $offset ) {
813  $search = $this->userNameUtils->getCanonical( $search );
814  if ( !$search ) {
815  // No prefix suggestion for invalid user
816  return [];
817  }
818  // Autocomplete subpage as user list - public to allow caching
819  return $this->userNamePrefixSearch
820  ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
821  }
822 
823  private function getPager() {
824  if ( $this->pager === null ) {
825  $options = [
826  'target' => $this->opts['target'],
827  'namespace' => $this->opts['namespace'],
828  'tagfilter' => $this->opts['tagfilter'],
829  'start' => $this->opts['start'] ?? '',
830  'end' => $this->opts['end'] ?? '',
831  'deletedOnly' => $this->opts['deletedOnly'],
832  'topOnly' => $this->opts['topOnly'],
833  'newOnly' => $this->opts['newOnly'],
834  'hideMinor' => $this->opts['hideMinor'],
835  'nsInvert' => $this->opts['nsInvert'],
836  'associated' => $this->opts['associated'],
837  ];
838 
839  $this->pager = new ContribsPager(
840  $this->getContext(),
841  $options,
842  $this->getLinkRenderer()
843  );
844  }
845 
846  return $this->pager;
847  }
848 
849  protected function getGroupName() {
850  return 'users';
851  }
852 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:79
SpecialContributions\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition: SpecialContributions.php:812
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:742
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:900
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
if
if(ini_get( 'mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:85
SpecialContributions\__construct
__construct(LinkBatchFactory $linkBatchFactory=null, PermissionManager $permissionManager=null, ILoadBalancer $loadBalancer=null, ActorMigration $actorMigration=null, RevisionStore $revisionStore=null, NamespaceInfo $namespaceInfo=null, UserNameUtils $userNameUtils=null, UserNamePrefixSearch $userNamePrefixSearch=null, UserOptionsLookup $userOptionsLookup=null)
Definition: SpecialContributions.php:85
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:80
SpecialContributions\$userNameUtils
UserNameUtils $userNameUtils
Definition: SpecialContributions.php:63
IndexPager\getDatabase
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:244
IP
Pre-librarized class name for IPUtils.
Definition: IP.php:80
SpecialContributions\$pager
ContribsPager null $pager
Definition: SpecialContributions.php:72
MediaWiki\Permissions\PermissionManager\userHasRight
userHasRight(UserIdentity $user, $action='')
Testing a permission.
Definition: PermissionManager.php:1280
SpecialContributions\$revisionStore
RevisionStore $revisionStore
Definition: SpecialContributions.php:57
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:548
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:106
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:808
IncludableSpecialPage
Shortcut to construct an includable special page.
Definition: IncludableSpecialPage.php:29
PoolCounterWorkViaCallback
Convenience class for dealing with PoolCounters using callbacks.
Definition: PoolCounterWorkViaCallback.php:31
ActorMigration
This class handles the logic for the actor table migration and should always be used in lieu of direc...
Definition: ActorMigration.php:41
SpecialContributions\getPager
getPager()
Definition: SpecialContributions.php:823
SpecialContributions\getUserLinks
static getUserLinks(SpecialPage $sp, User $target, PermissionManager $permissionManager=null, HookRunner $hookRunner=null)
Links to different places.
Definition: SpecialContributions.php:499
MediaWiki\HookContainer\HookRunner\onContributionsToolLinks
onContributionsToolLinks( $id, Title $title, array &$tools, SpecialPage $specialPage)
Use this hook to change the tool links above Special:Contributions.
Definition: HookRunner.php:1351
ContribsPager\processDateFilter
static processDateFilter(array $opts)
Set up date filter options, given request data.
Definition: ContribsPager.php:870
NS_MAIN
const NS_MAIN
Definition: Defines.php:63
SpecialContributions\$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: SpecialContributions.php:69
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
ContribsPager\getPreventClickjacking
getPreventClickjacking()
Definition: ContribsPager.php:860
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:318
SpecialContributions\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialContributions.php:110
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:50
UserrightsPage
Special page to allow managing user group membership.
Definition: SpecialUserrights.php:36
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:936
SpecialContributions\$actorMigration
ActorMigration $actorMigration
Definition: SpecialContributions.php:54
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1083
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
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1033
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
SpecialContributions\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialContributions.php:45
SpecialContributions\getForm
getForm(array $pagerOptions)
Generates the namespace selector form with hidden attributes.
Definition: SpecialContributions.php:612
PoolCounterWork\execute
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
Definition: PoolCounterWork.php:127
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:38
SpecialContributions\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialContributions.php:60
MediaWiki\User\UserNamePrefixSearch
Handles searching prefixes of user names.
Definition: UserNamePrefixSearch.php:39
User\isIP
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:958
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
Definition: SpecialPage.php:616
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:798
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:618
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:762
SpecialContributions\$userNamePrefixSearch
UserNamePrefixSearch $userNamePrefixSearch
Definition: SpecialContributions.php:66
ContribsPager
Pager for Special:Contributions.
Definition: ContribsPager.php:40
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:51
ContribsPager\isQueryableRange
isQueryableRange( $ipRange)
Is the given IP a range and within the CIDR limit?
Definition: ContribsPager.php:456
ContribsPager\getNavigationBar
getNavigationBar()
Wrap the navigation bar in a p element with identifying class.
Definition: ContribsPager.php:223
SpecialContributions\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialContributions.php:849
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:778
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1504
SpecialContributions\$opts
$opts
Definition: SpecialContributions.php:42
NS_USER
const NS_USER
Definition: Defines.php:65
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1016
SpecialPage\$hookRunner
HookRunner null $hookRunner
Definition: SpecialPage.php:84
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:254
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
SpecialContributions\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialContributions.php:51
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:571
IndexPager\getBody
getBody()
Get the formatted result list.
Definition: IndexPager.php:586
SpecialContributions\contributionsSub
contributionsSub( $userObj)
Generates the subheading with links.
Definition: SpecialContributions.php:381
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:137
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:321
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:707
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:265
SpecialContributions\$permissionManager
PermissionManager $permissionManager
Definition: SpecialContributions.php:48
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialContributions
Special:Contributions, show user contributions in a paged list.
Definition: SpecialContributions.php:41
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:731