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 ( $this->permissionManager->userHasRight( $user, 'markbotedits' ) && $request->getBool( 'bot' ) ) {
174  $this->opts['bot'] = '1';
175  }
176 
177  $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
178  # Offset overrides year/month selection
179  if ( !$skip ) {
180  $this->opts['year'] = $request->getVal( 'year' );
181  $this->opts['month'] = $request->getVal( 'month' );
182 
183  $this->opts['start'] = $request->getVal( 'start' );
184  $this->opts['end'] = $request->getVal( 'end' );
185  }
186 
187  $id = 0;
188  if ( ExternalUserNames::isExternal( $target ) ) {
189  $userObj = User::newFromName( $target, false );
190  if ( !$userObj ) {
191  $out->addHTML( $this->getForm( $this->opts ) );
192  return;
193  }
194 
195  $out->addSubtitle( $this->contributionsSub( $userObj, $target ) );
196  $out->setPageTitle( $this->msg( 'contributions-title', $target ) );
197  } else {
198  $nt = Title::makeTitleSafe( NS_USER, $target );
199  if ( !$nt ) {
200  $out->addHTML( $this->getForm( $this->opts ) );
201  return;
202  }
203  $userObj = User::newFromName( $nt->getText(), false );
204  if ( !$userObj ) {
205  $out->addHTML( $this->getForm( $this->opts ) );
206  return;
207  }
208  $id = $userObj->getId();
209 
210  $target = $nt->getText();
211  $out->addSubtitle( $this->contributionsSub( $userObj, $target ) );
212  $out->setPageTitle( $this->msg( 'contributions-title', $target ) );
213 
214  # For IP ranges, we want the contributionsSub, but not the skin-dependent
215  # links under 'Tools', which may include irrelevant links like 'Logs'.
216  if ( !IPUtils::isValidRange( $target ) &&
217  ( $this->userNameUtils->isIP( $target ) || $userObj->isRegistered() )
218  ) {
219  // Don't add non-existent users, because hidden users
220  // that we add here will be removed later to pretend
221  // that they don't exist, and if users that actually don't
222  // exist are added here and then not removed, it exposes
223  // which users exist and are hidden vs. which actually don't
224  // exist. But, do set the relevant user for single IPs.
225  $this->getSkin()->setRelevantUser( $userObj );
226  }
227  }
228 
229  $this->opts = ContribsPager::processDateFilter( $this->opts );
230 
231  if ( $this->opts['namespace'] !== '' && $this->opts['namespace'] < NS_MAIN ) {
232  $this->getOutput()->wrapWikiMsg(
233  "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
234  [ 'negative-namespace-not-supported' ]
235  );
236  $out->addHTML( $this->getForm( $this->opts ) );
237  return;
238  }
239 
240  $feedType = $request->getVal( 'feed' );
241 
242  $feedParams = [
243  'action' => 'feedcontributions',
244  'user' => $target,
245  ];
246  if ( $this->opts['topOnly'] ) {
247  $feedParams['toponly'] = true;
248  }
249  if ( $this->opts['newOnly'] ) {
250  $feedParams['newonly'] = true;
251  }
252  if ( $this->opts['hideMinor'] ) {
253  $feedParams['hideminor'] = true;
254  }
255  if ( $this->opts['deletedOnly'] ) {
256  $feedParams['deletedonly'] = true;
257  }
258  if ( $this->opts['tagfilter'] !== '' ) {
259  $feedParams['tagfilter'] = $this->opts['tagfilter'];
260  }
261  if ( $this->opts['namespace'] !== '' ) {
262  $feedParams['namespace'] = $this->opts['namespace'];
263  }
264  // Don't use year and month for the feed URL, but pass them on if
265  // we redirect to API (if $feedType is specified)
266  if ( $feedType && isset( $this->opts['year'] ) ) {
267  $feedParams['year'] = $this->opts['year'];
268  }
269  if ( $feedType && isset( $this->opts['month'] ) ) {
270  $feedParams['month'] = $this->opts['month'];
271  }
272 
273  if ( $feedType ) {
274  // Maintain some level of backwards compatibility
275  // If people request feeds using the old parameters, redirect to API
276  $feedParams['feedformat'] = $feedType;
277  $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
278 
279  $out->redirect( $url, '301' );
280 
281  return;
282  }
283 
284  // Add RSS/atom links
285  $this->addFeedLinks( $feedParams );
286 
287  if ( $this->getHookRunner()->onSpecialContributionsBeforeMainOutput(
288  $id, $userObj, $this )
289  ) {
290  if ( !$this->including() ) {
291  $out->addHTML( $this->getForm( $this->opts ) );
292  }
293  $pager = $this->getPager( $userObj );
294  if ( IPUtils::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
295  // Valid range, but outside CIDR limit.
296  $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
297  $limit = $limits[ IPUtils::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
298  $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
299  } elseif ( !$pager->getNumRows() ) {
300  $out->addWikiMsg( 'nocontribs', $target );
301  } else {
302  // @todo We just want a wiki ID here, not a "DB domain", but
303  // current status of MediaWiki conflates the two. See T235955.
304  $poolKey = $this->loadBalancer->getLocalDomainID() . ':SpecialContributions:';
305  if ( $this->getUser()->isAnon() ) {
306  $poolKey .= 'a:' . $this->getUser()->getName();
307  } else {
308  $poolKey .= 'u:' . $this->getUser()->getId();
309  }
310  $work = new PoolCounterWorkViaCallback( 'SpecialContributions', $poolKey, [
311  'doWork' => function () use ( $pager, $out ) {
312  # Show a message about replica DB lag, if applicable
313  $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
314  if ( $lag > 0 ) {
315  $out->showLagWarning( $lag );
316  }
317 
318  $output = $pager->getBody();
319  if ( !$this->including() ) {
320  $output = $pager->getNavigationBar() .
321  $output .
323  }
324  $out->addHTML( $output );
325  },
326  'error' => function () use ( $out ) {
327  $msg = $this->getUser()->isAnon()
328  ? 'sp-contributions-concurrency-ip'
329  : 'sp-contributions-concurrency-user';
330  $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>", $msg );
331  }
332  ] );
333  $work->execute();
334  }
335 
336  $out->preventClickjacking( $pager->getPreventClickjacking() );
337 
338  # Show the appropriate "footer" message - WHOIS tools, etc.
339  if ( IPUtils::isValidRange( $target ) && $pager->isQueryableRange( $target ) ) {
340  $message = 'sp-contributions-footer-anon-range';
341  } elseif ( IPUtils::isIPAddress( $target ) ) {
342  $message = 'sp-contributions-footer-anon';
343  } elseif ( $userObj->isAnon() ) {
344  // No message for non-existing users
345  $message = '';
346  } elseif ( $userObj->isHidden() &&
347  !$this->permissionManager->userHasRight( $this->getUser(), 'hideuser' )
348  ) {
349  // User is registered, but make sure that the viewer can see them, to avoid
350  // having different behavior for missing and hidden users; see T120883
351  $message = '';
352  } else {
353  // Not hidden, or hidden but the viewer can still see it
354  $message = 'sp-contributions-footer';
355  }
356 
357  if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
358  $out->wrapWikiMsg(
359  "<div class='mw-contributions-footer'>\n$1\n</div>",
360  [ $message, $target ] );
361  }
362  }
363  }
364 
374  protected function contributionsSub( $userObj, $targetName ) {
375  $isAnon = $userObj->isAnon();
376  if ( !$isAnon && $userObj->isHidden() &&
377  !$this->permissionManager->userHasRight( $this->getUser(), 'hideuser' )
378  ) {
379  // T120883 if the user is hidden and the viewer cannot see hidden
380  // users, pretend like it does not exist at all.
381  $isAnon = true;
382  }
383 
384  if ( $isAnon ) {
385  // Show a warning message that the user being searched for doesn't exist.
386  // UserNameUtils::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
387  // but returns false for IP ranges. We don't want to suggest either of these are
388  // valid usernames which we would with the 'contributions-userdoesnotexist' message.
389  if ( !$this->userNameUtils->isIP( $userObj->getName() )
390  && !IPUtils::isValidRange( $userObj->getName() )
391  ) {
392  $this->getOutput()->wrapWikiMsg(
393  "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
394  [
395  'contributions-userdoesnotexist',
396  wfEscapeWikiText( $userObj->getName() ),
397  ]
398  );
399  if ( !$this->including() ) {
400  $this->getOutput()->setStatusCode( 404 );
401  }
402  }
403  $user = htmlspecialchars( $userObj->getName() );
404  } else {
405  $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
406  }
407  $nt = $userObj->getUserPage();
408  $talk = $userObj->getTalkPage();
409  $links = '';
410 
411  // T211910. Don't show action links if a range is outside block limit
412  $showForIp = IPUtils::isValid( $userObj ) ||
413  ( IPUtils::isValidRange( $userObj ) && $this->getPager( $userObj )->isQueryableRange( $userObj ) );
414 
415  // T276306. if the user is hidden and the viewer cannot see hidden, pretend that it does not exist
416  $registeredAndVisible = $userObj->isRegistered() && ( !$userObj->isHidden()
417  || $this->permissionManager->userHasRight( $this->getUser(), 'hideuser' ) );
418 
419  if ( $talk && ( $registeredAndVisible || $showForIp ) ) {
420  $tools = self::getUserLinks(
421  $this,
422  $userObj,
423  $this->permissionManager,
424  $this->getHookRunner()
425  );
426  $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
427  foreach ( $tools as $tool ) {
428  $links .= Html::rawElement( 'span', [], $tool ) . ' ';
429  }
430  $links = trim( $links ) . Html::closeElement( 'span' );
431 
432  // Show a note if the user is blocked and display the last block log entry.
433  // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
434  // and also this will display a totally irrelevant log entry as a current block.
435  if ( !$this->including() ) {
436  // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
437  // and not a user object.
438  if ( IPUtils::isValidRange( $userObj->getName() ) ) {
439  $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
440  } else {
441  $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
442  }
443 
444  if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
445  if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
446  $nt = $this->namespaceInfo->getCanonicalName( NS_USER )
447  . ':' . $block->getTargetName();
448  }
449 
450  $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
451  if ( $userObj->isAnon() ) {
452  $msgKey = $block->isSitewide() ?
453  'sp-contributions-blocked-notice-anon' :
454  'sp-contributions-blocked-notice-anon-partial';
455  } else {
456  $msgKey = $block->isSitewide() ?
457  'sp-contributions-blocked-notice' :
458  'sp-contributions-blocked-notice-partial';
459  }
460  // Allow local styling overrides for different types of block
461  $class = $block->isSitewide() ?
462  'mw-contributions-blocked-notice' :
463  'mw-contributions-blocked-notice-partial';
465  $out,
466  'block',
467  $nt,
468  '',
469  [
470  'lim' => 1,
471  'showIfEmpty' => false,
472  'msgKey' => [
473  $msgKey,
474  $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
475  ],
476  'offset' => '', # don't use WebRequest parameter offset
477  'wrap' => Html::rawElement(
478  'div',
479  [ 'class' => $class ],
480  '$1'
481  ),
482  ]
483  );
484  }
485  }
486  }
487 
488  return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
489  $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
490  . ' ' . $links
491  );
492  }
493 
504  public static function getUserLinks(
505  SpecialPage $sp,
506  User $target,
507  PermissionManager $permissionManager = null,
508  HookRunner $hookRunner = null
509  ) {
510  // Fallback to global state, if not provided
511  $permissionManager = $permissionManager ?? MediaWikiServices::getInstance()->getPermissionManager();
512  $hookRunner = $hookRunner ?? Hooks::runner();
513 
514  $id = $target->getId();
515  $username = $target->getName();
516  $userpage = $target->getUserPage();
517  $talkpage = $target->getTalkPage();
518  $isIP = IPUtils::isValid( $username );
519  $isRange = IPUtils::isValidRange( $username );
520 
521  $linkRenderer = $sp->getLinkRenderer();
522 
523  $tools = [];
524  # No talk pages for IP ranges.
525  if ( !$isRange ) {
526  $tools['user-talk'] = $linkRenderer->makeLink(
527  $talkpage,
528  $sp->msg( 'sp-contributions-talk' )->text()
529  );
530  }
531 
532  # Block / Change block / Unblock links
533  if ( $permissionManager->userHasRight( $sp->getUser(), 'block' ) ) {
534  if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
535  $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
536  SpecialPage::getTitleFor( 'Block', $username ),
537  $sp->msg( 'change-blocklink' )->text()
538  );
539  $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
540  SpecialPage::getTitleFor( 'Unblock', $username ),
541  $sp->msg( 'unblocklink' )->text()
542  );
543  } else { # User is not blocked
544  $tools['block'] = $linkRenderer->makeKnownLink( # Block link
545  SpecialPage::getTitleFor( 'Block', $username ),
546  $sp->msg( 'blocklink' )->text()
547  );
548  }
549  }
550 
551  # Block log link
552  $tools['log-block'] = $linkRenderer->makeKnownLink(
553  SpecialPage::getTitleFor( 'Log', 'block' ),
554  $sp->msg( 'sp-contributions-blocklog' )->text(),
555  [],
556  [ 'page' => $userpage->getPrefixedText() ]
557  );
558 
559  # Suppression log link (T61120)
560  if ( $permissionManager->userHasRight( $sp->getUser(), 'suppressionlog' ) ) {
561  $tools['log-suppression'] = $linkRenderer->makeKnownLink(
562  SpecialPage::getTitleFor( 'Log', 'suppress' ),
563  $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
564  [],
565  [ 'offender' => $username ]
566  );
567  }
568 
569  # Don't show some links for IP ranges
570  if ( !$isRange ) {
571  # Uploads: hide if IPs cannot upload (T220674)
572  if ( !$isIP || $permissionManager->userHasRight( $target, 'upload' ) ) {
573  $tools['uploads'] = $linkRenderer->makeKnownLink(
574  SpecialPage::getTitleFor( 'Listfiles', $username ),
575  $sp->msg( 'sp-contributions-uploads' )->text()
576  );
577  }
578 
579  # Other logs link
580  # Todo: T146628
581  $tools['logs'] = $linkRenderer->makeKnownLink(
582  SpecialPage::getTitleFor( 'Log', $username ),
583  $sp->msg( 'sp-contributions-logs' )->text()
584  );
585 
586  # Add link to deleted user contributions for priviledged users
587  # Todo: T183457
588  if ( $permissionManager->userHasRight( $sp->getUser(), 'deletedhistory' ) ) {
589  $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
590  SpecialPage::getTitleFor( 'DeletedContributions', $username ),
591  $sp->msg( 'sp-contributions-deleted', $username )->text()
592  );
593  }
594  }
595 
596  # Add a link to change user rights for privileged users
597  $userrightsPage = new UserrightsPage();
598  $userrightsPage->setContext( $sp->getContext() );
599  if ( $userrightsPage->userCanChangeRights( $target ) ) {
600  $tools['userrights'] = $linkRenderer->makeKnownLink(
601  SpecialPage::getTitleFor( 'Userrights', $username ),
602  $sp->msg( 'sp-contributions-userrights', $username )->text()
603  );
604  }
605 
606  $hookRunner->onContributionsToolLinks( $id, $userpage, $tools, $sp );
607 
608  return $tools;
609  }
610 
617  protected function getForm( array $pagerOptions ) {
618  $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
619  // Modules required only for the form
620  $this->getOutput()->addModules( [
621  'mediawiki.special.contributions',
622  ] );
623  $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
624  $this->getOutput()->enableOOUI();
625  $fields = [];
626 
627  # Add hidden params for tracking except for parameters in $skipParameters
628  $skipParameters = [
629  'namespace',
630  'nsInvert',
631  'deletedOnly',
632  'target',
633  'year',
634  'month',
635  'start',
636  'end',
637  'topOnly',
638  'newOnly',
639  'hideMinor',
640  'associated',
641  'tagfilter'
642  ];
643 
644  foreach ( $this->opts as $name => $value ) {
645  if ( in_array( $name, $skipParameters ) ) {
646  continue;
647  }
648 
649  $fields[$name] = [
650  'name' => $name,
651  'type' => 'hidden',
652  'default' => $value,
653  ];
654  }
655 
656  $target = $this->opts['target'] ?? null;
657  $fields['target'] = [
658  'type' => 'user',
659  'default' => $target ?
660  str_replace( '_', ' ', $target ) : '' ,
661  'label' => $this->msg( 'sp-contributions-username' )->text(),
662  'name' => 'target',
663  'id' => 'mw-target-user-or-ip',
664  'size' => 40,
665  'autofocus' => !$target,
666  'section' => 'contribs-top',
667  ];
668 
669  $ns = $this->opts['namespace'] ?? null;
670  $fields['namespace'] = [
671  'type' => 'namespaceselect',
672  'label' => $this->msg( 'namespace' )->text(),
673  'name' => 'namespace',
674  'cssclass' => 'namespaceselector',
675  'default' => $ns,
676  'id' => 'namespace',
677  'section' => 'contribs-top',
678  ];
679  $fields['nsFilters'] = [
680  'class' => HTMLMultiSelectField::class,
681  'label' => '',
682  'name' => 'wpfilters',
683  'flatlist' => true,
684  // Only shown when namespaces are selected.
685  'cssclass' => $ns === '' ?
686  'contribs-ns-filters mw-input-with-label mw-input-hidden' :
687  'contribs-ns-filters mw-input-with-label',
688  // `contribs-ns-filters` class allows these fields to be toggled on/off by JavaScript.
689  // See resources/src/mediawiki.special.recentchanges.js
690  'infusable' => true,
691  'options-messages' => [
692  'invert' => 'nsInvert',
693  'namespace_association' => 'associated',
694  ],
695  'section' => 'contribs-top',
696  ];
697  $fields['tagfilter'] = [
698  'type' => 'tagfilter',
699  'cssclass' => 'mw-tagfilter-input',
700  'id' => 'tagfilter',
701  'label-message' => [ 'tag-filter', 'parse' ],
702  'name' => 'tagfilter',
703  'size' => 20,
704  'section' => 'contribs-top',
705  ];
706 
707  if ( $this->permissionManager->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
708  $fields['deletedOnly'] = [
709  'type' => 'check',
710  'id' => 'mw-show-deleted-only',
711  'label' => $this->msg( 'history-show-deleted' )->text(),
712  'name' => 'deletedOnly',
713  'section' => 'contribs-top',
714  ];
715  }
716 
717  $fields['topOnly'] = [
718  'type' => 'check',
719  'id' => 'mw-show-top-only',
720  'label' => $this->msg( 'sp-contributions-toponly' )->text(),
721  'name' => 'topOnly',
722  'section' => 'contribs-top',
723  ];
724  $fields['newOnly'] = [
725  'type' => 'check',
726  'id' => 'mw-show-new-only',
727  'label' => $this->msg( 'sp-contributions-newonly' )->text(),
728  'name' => 'newOnly',
729  'section' => 'contribs-top',
730  ];
731  $fields['hideMinor'] = [
732  'type' => 'check',
733  'cssclass' => 'mw-hide-minor-edits',
734  'id' => 'mw-show-new-only',
735  'label' => $this->msg( 'sp-contributions-hideminor' )->text(),
736  'name' => 'hideMinor',
737  'section' => 'contribs-top',
738  ];
739 
740  // Allow additions at this point to the filters.
741  $rawFilters = [];
742  $this->getHookRunner()->onSpecialContributions__getForm__filters(
743  $this, $rawFilters );
744  foreach ( $rawFilters as $filter ) {
745  // Backwards compatibility support for previous hook function signature.
746  if ( is_string( $filter ) ) {
747  $fields[] = [
748  'type' => 'info',
749  'default' => $filter,
750  'raw' => true,
751  'section' => 'contribs-top',
752  ];
753  wfDeprecated(
754  'A SpecialContributions::getForm::filters hook handler returned ' .
755  'an array of strings, this is deprecated since MediaWiki 1.33',
756  '1.33', false, false
757  );
758  } else {
759  // Preferred append method.
760  $fields[] = $filter;
761  }
762  }
763 
764  $fields['start'] = [
765  'type' => 'date',
766  'default' => '',
767  'id' => 'mw-date-start',
768  'label' => $this->msg( 'date-range-from' )->text(),
769  'name' => 'start',
770  'section' => 'contribs-date',
771  ];
772  $fields['end'] = [
773  'type' => 'date',
774  'default' => '',
775  'id' => 'mw-date-end',
776  'label' => $this->msg( 'date-range-to' )->text(),
777  'name' => 'end',
778  'section' => 'contribs-date',
779  ];
780 
781  $htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
782  $htmlForm
783  ->setMethod( 'get' )
784  // When offset is defined, the user is paging through results
785  // so we hide the form by default to allow users to focus on browsing
786  // rather than defining search parameters
787  ->setCollapsibleOptions(
788  ( $pagerOptions['target'] ?? null ) ||
789  ( $pagerOptions['start'] ?? null ) ||
790  ( $pagerOptions['end'] ?? null )
791  )
792  ->setAction( wfScript() )
793  ->setSubmitTextMsg( 'sp-contributions-submit' )
794  ->setWrapperLegendMsg( 'sp-contributions-search' );
795 
796  $explain = $this->msg( 'sp-contributions-explain' );
797  if ( !$explain->isBlank() ) {
798  $htmlForm->addFooterText( "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>" );
799  }
800 
801  $htmlForm->loadData();
802 
803  return $htmlForm->getHTML( false );
804  }
805 
814  public function prefixSearchSubpages( $search, $limit, $offset ) {
815  $search = $this->userNameUtils->getCanonical( $search );
816  if ( !$search ) {
817  // No prefix suggestion for invalid user
818  return [];
819  }
820  // Autocomplete subpage as user list - public to allow caching
821  return $this->userNamePrefixSearch
822  ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
823  }
824 
829  private function getPager( $targetUser ) {
830  if ( $this->pager === null ) {
831  $options = [
832  'namespace' => $this->opts['namespace'],
833  'tagfilter' => $this->opts['tagfilter'],
834  'start' => $this->opts['start'] ?? '',
835  'end' => $this->opts['end'] ?? '',
836  'deletedOnly' => $this->opts['deletedOnly'],
837  'topOnly' => $this->opts['topOnly'],
838  'newOnly' => $this->opts['newOnly'],
839  'hideMinor' => $this->opts['hideMinor'],
840  'nsInvert' => $this->opts['nsInvert'],
841  'associated' => $this->opts['associated'],
842  ];
843 
844  $this->pager = new ContribsPager(
845  $this->getContext(),
846  $options,
847  $this->getLinkRenderer(),
848  $this->linkBatchFactory,
849  $this->getHookContainer(),
850  $this->loadBalancer,
851  $this->actorMigration,
852  $this->revisionStore,
853  $this->namespaceInfo,
854  $targetUser
855  );
856  }
857 
858  return $this->pager;
859  }
860 
861  protected function getGroupName() {
862  return 'users';
863  }
864 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialContributions\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition: SpecialContributions.php:814
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:744
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:191
if
if(ini_get( 'mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:88
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
MediaWiki\Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:88
SpecialContributions\$userNameUtils
UserNameUtils $userNameUtils
Definition: SpecialContributions.php:63
IndexPager\getDatabase
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:246
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:1366
SpecialContributions\$revisionStore
RevisionStore $revisionStore
Definition: SpecialContributions.php:57
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:606
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:107
SpecialPage\getHookContainer
getHookContainer()
Definition: SpecialPage.php:1082
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:820
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 is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
Definition: ActorMigration.php:15
SpecialContributions\getUserLinks
static getUserLinks(SpecialPage $sp, User $target, PermissionManager $permissionManager=null, HookRunner $hookRunner=null)
Links to different places.
Definition: SpecialContributions.php:504
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:1297
ContribsPager\processDateFilter
static processDateFilter(array $opts)
Set up date filter options, given request data.
Definition: ContribsPager.php:865
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
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:422
ContribsPager\getPreventClickjacking
getPreventClickjacking()
Definition: ContribsPager.php:855
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:316
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:52
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:948
SpecialContributions\$actorMigration
ActorMigration $actorMigration
Definition: SpecialContributions.php:54
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1095
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:878
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:930
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2307
SpecialContributions\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: SpecialContributions.php:45
SpecialContributions\getForm
getForm(array $pagerOptions)
Generates the namespace selector form with hidden attributes.
Definition: SpecialContributions.php:617
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:39
SpecialContributions\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialContributions.php:60
MediaWiki\User\UserNamePrefixSearch
Handles searching prefixes of user names.
Definition: UserNamePrefixSearch.php:39
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:618
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:597
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
SpecialContributions\$userNamePrefixSearch
UserNamePrefixSearch $userNamePrefixSearch
Definition: SpecialContributions.php:66
ContribsPager
Pager for Special:Contributions.
Definition: ContribsPager.php:41
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:677
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:53
ContribsPager\isQueryableRange
isQueryableRange( $ipRange)
Is the given IP a range and within the CIDR limit?
Definition: ContribsPager.php:474
ContribsPager\getNavigationBar
getNavigationBar()
Wrap the navigation bar in a p element with identifying class.
Definition: ContribsPager.php:244
SpecialContributions\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialContributions.php:861
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:780
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1455
SpecialContributions\$opts
$opts
Definition: SpecialContributions.php:42
NS_USER
const NS_USER
Definition: Defines.php:66
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialPage\$hookRunner
HookRunner null $hookRunner
Definition: SpecialPage.php:85
SpecialContributions\getPager
getPager( $targetUser)
Definition: SpecialContributions.php:829
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
SpecialContributions\contributionsSub
contributionsSub( $userObj, $targetName)
Generates the subheading with links.
Definition: SpecialContributions.php:374
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:252
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
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:558
IndexPager\getBody
getBody()
Get the formatted result list.
Definition: IndexPager.php:588
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:149
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:326
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:709
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:266
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:733