36 parent::__construct(
'Contributions' );
44 $out->addModuleStyles( [
45 'jquery.makeCollapsible.styles',
46 'mediawiki.interface.helpers.styles',
48 'mediawiki.special.changeslist',
51 'mediawiki.special.recentchanges',
53 'mediawiki.page.ready'
60 $target = $par ?? $request->getVal(
'target' );
62 $this->opts[
'deletedOnly'] = $request->getBool(
'deletedOnly' );
64 if ( !strlen( $target ) ) {
66 $out->addHTML( $this->
getForm( $this->opts ) );
74 $this->opts[
'limit'] = $request->getInt(
'limit', $user->getOption(
'rclimit' ) );
75 $this->opts[
'target'] = $target;
76 $this->opts[
'topOnly'] = $request->getBool(
'topOnly' );
77 $this->opts[
'newOnly'] = $request->getBool(
'newOnly' );
78 $this->opts[
'hideMinor'] = $request->getBool(
'hideMinor' );
84 $out->addHTML( $this->
getForm( $this->opts ) );
89 $out->setHTMLTitle( $this->
msg(
91 $this->
msg(
'contributions-title', $target )->plain()
92 )->inContentLanguage() );
96 $out->addHTML( $this->
getForm( $this->opts ) );
101 $out->addHTML( $this->
getForm( $this->opts ) );
104 $id = $userObj->getId();
106 $target = $nt->getText();
108 $out->setHTMLTitle( $this->
msg(
110 $this->
msg(
'contributions-title', $target )->plain()
111 )->inContentLanguage() );
113 # For IP ranges, we want the contributionsSub, but not the skin-dependent
114 # links under 'Tools', which may include irrelevant links like 'Logs'.
116 $this->
getSkin()->setRelevantUser( $userObj );
120 $ns = $request->getVal(
'namespace',
null );
121 if ( $ns !==
null && $ns !==
'' && $ns !==
'all' ) {
122 $this->opts[
'namespace'] = intval( $ns );
124 $this->opts[
'namespace'] =
'';
130 $this->opts[
'associated'] = $request->getBool(
'associated' );
131 $this->opts[
'nsInvert'] = (bool)$request->getVal(
'nsInvert' );
132 $nsFilters = $request->getArray(
'wpfilters',
null );
133 if ( $nsFilters !==
null ) {
134 $this->opts[
'associated'] = in_array(
'associated', $nsFilters );
135 $this->opts[
'nsInvert'] = in_array(
'nsInvert', $nsFilters );
138 $this->opts[
'tagfilter'] = (string)$request->getVal(
'tagfilter' );
142 if ( MediaWikiServices::getInstance()
144 ->userHasRight( $user,
'markbotedits' ) && $request->getBool(
'bot' )
146 $this->opts[
'bot'] =
'1';
149 $skip = $request->getText(
'offset' ) || $request->getText(
'dir' ) ==
'prev';
150 # Offset overrides year/month selection
152 $this->opts[
'year'] = $request->getVal(
'year' );
153 $this->opts[
'month'] = $request->getVal(
'month' );
155 $this->opts[
'start'] = $request->getVal(
'start' );
156 $this->opts[
'end'] = $request->getVal(
'end' );
160 if ( $this->opts[
'namespace'] <
NS_MAIN ) {
162 "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
163 [
'negative-namespace-not-supported' ]
165 $out->addHTML( $this->
getForm( $this->opts ) );
169 $feedType = $request->getVal(
'feed' );
172 'action' =>
'feedcontributions',
175 if ( $this->opts[
'topOnly'] ) {
176 $feedParams[
'toponly'] =
true;
178 if ( $this->opts[
'newOnly'] ) {
179 $feedParams[
'newonly'] =
true;
181 if ( $this->opts[
'hideMinor'] ) {
182 $feedParams[
'hideminor'] =
true;
184 if ( $this->opts[
'deletedOnly'] ) {
185 $feedParams[
'deletedonly'] =
true;
187 if ( $this->opts[
'tagfilter'] !==
'' ) {
188 $feedParams[
'tagfilter'] = $this->opts[
'tagfilter'];
190 if ( $this->opts[
'namespace'] !==
'' ) {
191 $feedParams[
'namespace'] = $this->opts[
'namespace'];
195 if ( $feedType && $this->opts[
'year'] !==
null ) {
196 $feedParams[
'year'] = $this->opts[
'year'];
198 if ( $feedType && $this->opts[
'month'] !==
null ) {
199 $feedParams[
'month'] = $this->opts[
'month'];
205 $feedParams[
'feedformat'] = $feedType;
208 $out->redirect( $url,
'301' );
216 if (
Hooks::run(
'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) {
219 'namespace' => $this->opts[
'namespace'],
220 'tagfilter' => $this->opts[
'tagfilter'],
221 'start' => $this->opts[
'start'],
222 'end' => $this->opts[
'end'],
223 'deletedOnly' => $this->opts[
'deletedOnly'],
224 'topOnly' => $this->opts[
'topOnly'],
225 'newOnly' => $this->opts[
'newOnly'],
226 'hideMinor' => $this->opts[
'hideMinor'],
227 'nsInvert' => $this->opts[
'nsInvert'],
228 'associated' => $this->opts[
'associated'],
231 $out->addHTML( $this->
getForm( $this->opts ) );
234 if (
IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
236 $limits = $this->
getConfig()->get(
'RangeContributionsCIDRLimit' );
237 $limit = $limits[
IP::isIPv4( $target ) ?
'IPv4' :
'IPv6' ];
238 $out->addWikiMsg(
'sp-contributions-outofrange', $limit );
239 } elseif ( !$pager->getNumRows() ) {
240 $out->addWikiMsg(
'nocontribs', $target );
242 # Show a message about replica DB lag, if applicable
243 $lag = $pager->getDatabase()->getSessionLagStatus()[
'lag'];
245 $out->showLagWarning( $lag );
250 $output = $pager->getNavigationBar() .
252 $pager->getNavigationBar();
257 $out->preventClickjacking( $pager->getPreventClickjacking() );
259 # Show the appropriate "footer" message - WHOIS tools, etc.
261 $message =
'sp-contributions-footer-anon-range';
263 $message =
'sp-contributions-footer-anon';
264 } elseif ( $userObj->isAnon() ) {
268 $message =
'sp-contributions-footer';
271 if ( $message && !$this->
including() && !$this->
msg( $message, $target )->isDisabled() ) {
273 "<div class='mw-contributions-footer'>\n$1\n</div>",
274 [ $message, $target ] );
287 if ( $userObj->isAnon() ) {
292 if ( !
User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
294 "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
296 'contributions-userdoesnotexist',
301 $this->
getOutput()->setStatusCode( 404 );
304 $user = htmlspecialchars( $userObj->getName() );
306 $user = $this->
getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
308 $nt = $userObj->getUserPage();
309 $talk = $userObj->getTalkPage();
313 $links = Html::openElement(
'span', [
'class' =>
'mw-changeslist-links' ] );
314 foreach ( $tools as $tool ) {
315 $links .= Html::rawElement(
'span', [], $tool ) .
' ';
317 $links = trim( $links ) . Html::closeElement(
'span' );
325 if ( $userObj->isIPRange() ) {
326 $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
328 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
331 if ( !is_null( $block ) && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
332 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
333 $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
334 getCanonicalName(
NS_USER ) .
':' . $block->getTarget();
345 'showIfEmpty' =>
false,
348 'sp-contributions-blocked-notice-anon' :
349 'sp-contributions-blocked-notice',
350 $userObj->getName() # Support GENDER in
'sp-contributions-blocked-notice'
352 'offset' =>
'' # don
't use WebRequest parameter offset
359 return Html::rawElement( 'div
', [ 'class' => 'mw-contributions-user-tools
' ],
360 $this->msg( 'contributions-subtitle
' )->rawParams( $user )->params( $userObj->getName() )
373 public static function getUserLinks( SpecialPage $sp, User $target ) {
374 $id = $target->getId();
375 $username = $target->getName();
376 $userpage = $target->getUserPage();
377 $talkpage = $target->getTalkPage();
378 $isIP = IP::isValid( $username );
379 $isRange = IP::isValidRange( $username );
381 $linkRenderer = $sp->getLinkRenderer();
384 # No talk pages for IP ranges.
386 $tools['user-talk
'] = $linkRenderer->makeLink(
388 $sp->msg( 'sp-contributions-talk
' )->text()
392 # Block / Change block / Unblock links
393 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
394 if ( $permissionManager->userHasRight( $sp->getUser(), 'block
' ) ) {
395 if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
396 $tools['block
'] = $linkRenderer->makeKnownLink( # Change block link
397 SpecialPage::getTitleFor( 'Block
', $username ),
398 $sp->msg( 'change-blocklink
' )->text()
400 $tools['unblock
'] = $linkRenderer->makeKnownLink( # Unblock link
401 SpecialPage::getTitleFor( 'Unblock
', $username ),
402 $sp->msg( 'unblocklink
' )->text()
404 } else { # User is not blocked
405 $tools['block
'] = $linkRenderer->makeKnownLink( # Block link
406 SpecialPage::getTitleFor( 'Block
', $username ),
407 $sp->msg( 'blocklink
' )->text()
413 $tools['log-block
'] = $linkRenderer->makeKnownLink(
414 SpecialPage::getTitleFor( 'Log
', 'block
' ),
415 $sp->msg( 'sp-contributions-blocklog
' )->text(),
417 [ 'page
' => $userpage->getPrefixedText() ]
420 # Suppression log link (T61120)
421 if ( $permissionManager->userHasRight( $sp->getUser(), 'suppressionlog
' ) ) {
422 $tools['log-suppression
'] = $linkRenderer->makeKnownLink(
423 SpecialPage::getTitleFor( 'Log
', 'suppress
' ),
424 $sp->msg( 'sp-contributions-suppresslog
', $username )->text(),
426 [ 'offender
' => $username ]
430 # Don't show some links
for IP ranges
432 # Uploads: hide if IPs cannot upload (T220674)
433 if ( !$isIP || $permissionManager->userHasRight( $target,
'upload' ) ) {
436 $sp->msg(
'sp-contributions-uploads' )->text()
444 $sp->msg(
'sp-contributions-logs' )->text()
447 # Add link to deleted user contributions for priviledged users
449 if ( $permissionManager->userHasRight( $sp->getUser(),
'deletedhistory' ) ) {
452 $sp->msg(
'sp-contributions-deleted', $username )->text()
457 # Add a link to change user rights for privileged users
459 $userrightsPage->setContext( $sp->getContext() );
460 if ( $userrightsPage->userCanChangeRights( $target ) ) {
463 $sp->msg(
'sp-contributions-userrights', $username )->text()
467 Hooks::run(
'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
478 protected function getForm( array $pagerOptions ) {
479 $this->opts[
'title'] = $this->
getPageTitle()->getPrefixedText();
482 'mediawiki.userSuggest',
483 'mediawiki.special.contributions',
485 $this->
getOutput()->addModuleStyles(
'mediawiki.widgets.DateInputWidget.styles' );
489 # Add hidden params for tracking except for parameters in $skipParameters
506 foreach ( $this->opts as $name => $value ) {
507 if ( in_array( $name, $skipParameters ) ) {
518 $target = $this->opts[
'target'] ??
null;
519 $fields[
'target'] = [
521 'cssclass' =>
'mw-autocomplete-user mw-ui-input-inline mw-input',
522 'default' => $target ?
523 str_replace(
'_',
' ', $target ) :
'' ,
524 'label' => $this->
msg(
'sp-contributions-username' )->text(),
526 'id' =>
'mw-target-user-or-ip',
528 'autofocus' => !$target,
529 'section' =>
'contribs-top',
532 $ns = $this->opts[
'namespace'] ??
null;
533 $fields[
'namespace'] = [
534 'type' =>
'namespaceselect',
535 'label' => $this->
msg(
'namespace' )->text(),
536 'name' =>
'namespace',
537 'cssclass' =>
'namespaceselector',
540 'section' =>
'contribs-top',
543 $nsFilters = $request->getArray(
'wpfilters' );
544 $fields[
'nsFilters'] = [
545 'class' =>
'HTMLMultiSelectField',
547 'name' =>
'wpfilters',
550 'cssclass' => $ns ===
'' ?
551 'contribs-ns-filters mw-input-with-label mw-input-hidden' :
552 'contribs-ns-filters mw-input-with-label',
557 $this->
msg(
'invert' )->text() =>
'nsInvert',
558 $this->
msg(
'namespace_association' )->text() =>
'associated',
560 'default' => $nsFilters,
561 'section' =>
'contribs-top',
563 $fields[
'tagfilter'] = [
564 'type' =>
'tagfilter',
565 'cssclass' =>
'mw-tagfilter-input',
567 'label-message' => [
'tag-filter',
'parse' ],
568 'name' =>
'tagfilter',
570 'section' =>
'contribs-top',
573 if ( MediaWikiServices::getInstance()
575 ->userHasRight( $this->
getUser(),
'deletedhistory' )
577 $fields[
'deletedOnly'] = [
579 'id' =>
'mw-show-deleted-only',
580 'label' => $this->
msg(
'history-show-deleted' )->text(),
581 'name' =>
'deletedOnly',
582 'section' =>
'contribs-top',
586 $fields[
'topOnly'] = [
588 'id' =>
'mw-show-top-only',
589 'label' => $this->
msg(
'sp-contributions-toponly' )->text(),
591 'section' =>
'contribs-top',
593 $fields[
'newOnly'] = [
595 'id' =>
'mw-show-new-only',
596 'label' => $this->
msg(
'sp-contributions-newonly' )->text(),
598 'section' =>
'contribs-top',
600 $fields[
'hideMinor'] = [
602 'cssclass' =>
'mw-hide-minor-edits',
603 'id' =>
'mw-show-new-only',
604 'label' => $this->
msg(
'sp-contributions-hideminor' )->text(),
605 'name' =>
'hideMinor',
606 'section' =>
'contribs-top',
612 'SpecialContributions::getForm::filters',
613 [ $this, &$rawFilters ]
615 foreach ( $rawFilters as
$filter ) {
622 'section' =>
'contribs-top',
626 ' returning string[]',
638 'id' =>
'mw-date-start',
639 'label' => $this->
msg(
'date-range-from' )->text(),
641 'section' =>
'contribs-date',
646 'id' =>
'mw-date-end',
647 'label' => $this->
msg(
'date-range-to' )->text(),
649 'section' =>
'contribs-date',
658 ->setCollapsibleOptions(
659 ( $pagerOptions[
'target'] ??
null ) ||
660 ( $pagerOptions[
'start'] ??
null ) ||
661 ( $pagerOptions[
'end'] ??
null )
664 ->setSubmitText( $this->
msg(
'sp-contributions-submit' )->text() )
665 ->setWrapperLegend( $this->
msg(
'sp-contributions-search' )->text() );
667 $explain = $this->
msg(
'sp-contributions-explain' );
668 if ( !$explain->isBlank() ) {
669 $htmlForm->addFooterText(
"<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>" );
672 $htmlForm->loadData();
674 return $htmlForm->getHTML(
false );