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