X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecials%2FSpecialContributions.php;h=5a5f005bafeeacd36129de2a39b22fb4d0df4f2b;hp=1b14fcbe10a9810b6da05b8488d3be845c6e4705;hb=d09554b6ef498a0182110427af6a5b0545de1293;hpb=f884d157f776afece12e0d986a8cd78574ed5335 diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 1b14fcbe10..5a5f005baf 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -103,7 +103,12 @@ class SpecialContributions extends IncludableSpecialPage { 'pagetitle', $this->msg( 'contributions-title', $target )->plain() )->inContentLanguage() ); - $this->getSkin()->setRelevantUser( $userObj ); + + # For IP ranges, we want the contributionsSub, but not the skin-dependent + # links under 'Tools', which may include irrelevant links like 'Logs'. + if ( !IP::isValidRange( $target ) ) { + $this->getSkin()->setRelevantUser( $userObj ); + } } else { $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) ); $out->setHTMLTitle( $this->msg( @@ -206,7 +211,12 @@ class SpecialContributions extends IncludableSpecialPage { 'associated' => $this->opts['associated'], ] ); - if ( !$pager->getNumRows() ) { + if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) { + // Valid range, but outside CIDR limit. + $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' ); + $limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ]; + $out->addWikiMsg( 'sp-contributions-outofrange', $limit ); + } elseif ( !$pager->getNumRows() ) { $out->addWikiMsg( 'nocontribs', $target ); } else { # Show a message about replica DB lag, if applicable @@ -223,11 +233,14 @@ class SpecialContributions extends IncludableSpecialPage { } $out->addHTML( $output ); } + $out->preventClickjacking( $pager->getPreventClickjacking() ); # Show the appropriate "footer" message - WHOIS tools, etc. if ( $this->opts['contribs'] == 'newbie' ) { $message = 'sp-contributions-footer-newbies'; + } elseif ( IP::isValidRange( $target ) ) { + $message = 'sp-contributions-footer-anon-range'; } elseif ( IP::isIPAddress( $target ) ) { $message = 'sp-contributions-footer-anon'; } elseif ( $userObj->isAnon() ) { @@ -258,8 +271,11 @@ class SpecialContributions extends IncludableSpecialPage { */ protected function contributionsSub( $userObj ) { if ( $userObj->isAnon() ) { - // Show a warning message that the user being searched for doesn't exists - if ( !User::isIP( $userObj->getName() ) ) { + // Show a warning message that the user being searched for doesn't exists. + // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx', + // but returns false for IP ranges. We don't want to suggest either of these are + // valid usernames which we would with the 'contributions-userdoesnotexist' message. + if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) { $this->getOutput()->wrapWikiMsg( "
\n\$1\n
", [ @@ -286,7 +302,13 @@ class SpecialContributions extends IncludableSpecialPage { // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs, // and also this will display a totally irrelevant log entry as a current block. if ( !$this->including() ) { - $block = Block::newFromTarget( $userObj, $userObj ); + // For IP ranges you must give Block::newFromTarget the CIDR string and not a user object. + if ( $userObj->isIPRange() ) { + $block = Block::newFromTarget( $userObj->getName(), $userObj->getName() ); + } else { + $block = Block::newFromTarget( $userObj, $userObj ); + } + if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) { if ( $block->getType() == Block::TYPE_RANGE ) { $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(); @@ -332,10 +354,14 @@ class SpecialContributions extends IncludableSpecialPage { $talkpage = $target->getTalkPage(); $linkRenderer = $sp->getLinkRenderer(); - $tools['user-talk'] = $linkRenderer->makeLink( - $talkpage, - $sp->msg( 'sp-contributions-talk' )->text() - ); + + # No talk pages for IP ranges. + if ( !IP::isValidRange( $username ) ) { + $tools['user-talk'] = $linkRenderer->makeLink( + $talkpage, + $sp->msg( 'sp-contributions-talk' )->text() + ); + } if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $username ) ) ) { if ( $sp->getUser()->isAllowed( 'block' ) ) { # Block / Change block / Unblock links @@ -374,24 +400,28 @@ class SpecialContributions extends IncludableSpecialPage { ); } } - # Uploads - $tools['uploads'] = $linkRenderer->makeKnownLink( - SpecialPage::getTitleFor( 'Listfiles', $username ), - $sp->msg( 'sp-contributions-uploads' )->text() - ); - # Other logs link - $tools['logs'] = $linkRenderer->makeKnownLink( - SpecialPage::getTitleFor( 'Log', $username ), - $sp->msg( 'sp-contributions-logs' )->text() - ); + # Don't show some links for IP ranges + if ( !IP::isValidRange( $username ) ) { + # Uploads + $tools['uploads'] = $linkRenderer->makeKnownLink( + SpecialPage::getTitleFor( 'Listfiles', $username ), + $sp->msg( 'sp-contributions-uploads' )->text() + ); - # Add link to deleted user contributions for priviledged users - if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) { - $tools['deletedcontribs'] = $linkRenderer->makeKnownLink( - SpecialPage::getTitleFor( 'DeletedContributions', $username ), - $sp->msg( 'sp-contributions-deleted', $username )->text() + # Other logs link + $tools['logs'] = $linkRenderer->makeKnownLink( + SpecialPage::getTitleFor( 'Log', $username ), + $sp->msg( 'sp-contributions-logs' )->text() ); + + # Add link to deleted user contributions for priviledged users + if ( $sp->getUser()->isAllowed( 'deletedhistory' ) ) { + $tools['deletedcontribs'] = $linkRenderer->makeKnownLink( + SpecialPage::getTitleFor( 'DeletedContributions', $username ), + $sp->msg( 'sp-contributions-deleted', $username )->text() + ); + } } # Add a link to change user rights for privileged users