jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/381446 )

Change subject: Show global block notice on Special:Contributions for IP ranges
......................................................................


Show global block notice on Special:Contributions for IP ranges

We currently show glboal blocks for a range on a specific IP address,
but not if the user is viewing the contributions for the entire range.

Bug: T176989
Change-Id: Ib558a397b574e9b9fe70c673af57c4d857ad5e19
---
M includes/GlobalBlockingHooks.php
1 file changed, 21 insertions(+), 7 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/GlobalBlockingHooks.php b/includes/GlobalBlockingHooks.php
index 2249dd5..346c7f7 100644
--- a/includes/GlobalBlockingHooks.php
+++ b/includes/GlobalBlockingHooks.php
@@ -148,22 +148,36 @@
                $userId, User $user, SpecialPage $sp
        ) {
                $name = $user->getName();
-               if ( !IP::isValid( $name ) ) {
+               if ( !IP::isIPAddress( $name ) ) {
                        return true;
                }
 
-               $rangeCondition = GlobalBlocking::getRangeCondition( $name );
-               $pager = new GlobalBlockListPager( $sp->getContext(), 
$rangeCondition );
-               $pager->setLimit( 1 ); // show at most one entry
-               $body = $pager->getBody();
+               // Obtain the first and the last IP of a range if IP is a range
+               list( $startIP, $endIP ) = IP::parseRange( $name );
+               substr( $startIP, 0, 4 );
+               substr( $endIP, 0, 4 );
+               $startname = IP::formatHex( $startIP );
+               $endname = IP::formatHex( $endIP );
 
-               if ( $body != '' ) {
+               // Get results from the first ip of a range
+               $rangeConditionstart = GlobalBlocking::getRangeCondition( 
$startname );
+               $pagerstart = new GlobalBlockListPager( $sp->getContext(), 
$rangeConditionstart );
+               $pagerstart->setLimit( 1 ); // show at most one entry
+               $bodystart = $pagerstart->getBody();
+
+               // Get results from the last ip of a range
+               $rangeConditionend = GlobalBlocking::getRangeCondition( 
$endname );
+               $pagerend = new GlobalBlockListPager( $sp->getContext(), 
$rangeConditionend );
+               $pagerend->setLimit( 1 ); // show at most one entry
+               $bodyend = $pagerend->getBody();
+
+               if ( $bodystart != '' && $bodyend != '' ) {
                        $out = $sp->getOutput();
                        $out->addHTML(
                                Html::rawElement( 'div',
                                        [ 'class' => 
'mw-warning-with-logexcerpt' ],
                                        $sp->msg( 
'globalblocking-contribs-notice', $name )->parse() .
-                                       Html::rawElement( 'ul', [], $body )
+                                       Html::rawElement( 'ul', [], $bodystart )
                                )
                        );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/381446
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib558a397b574e9b9fe70c673af57c4d857ad5e19
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/GlobalBlocking
Gerrit-Branch: master
Gerrit-Owner: Melos <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to