(bug 32827) "[Regression] Block log for IP ranges not shown on Special:Block"
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 14 Mar 2012 01:42:14 +0000 (01:42 +0000)
committerCatrope <roan.kattouw@gmail.com>
Wed, 21 Mar 2012 22:56:43 +0000 (15:56 -0700)
(imported from SVN)

Change-Id: I16485d84553256ff6ad4932de7d17540e90af779

includes/specials/SpecialBlock.php

index 5b5b356..a58e62e 100644 (file)
@@ -381,19 +381,19 @@ class SpecialBlock extends FormSpecialPage {
                        $this->getLanguage()->pipeList( $links )
                );
 
-               if( $this->target instanceof User ){
+               $userTitle = self::getTargetUserTitle( $this->target );
+               if( $userTitle ){
                        # Get relevant extracts from the block and suppression logs, if possible
-                       $userpage = $this->target->getUserPage();
                        $out = '';
 
                        LogEventsList::showLogExtract(
                                $out,
                                'block',
-                               $userpage,
+                               $userTitle,
                                '',
                                array(
                                        'lim' => 10,
-                                       'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
+                                       'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
                                        'showIfEmpty' => false
                                )
                        );
@@ -404,12 +404,12 @@ class SpecialBlock extends FormSpecialPage {
                                LogEventsList::showLogExtract(
                                        $out,
                                        'suppress',
-                                       $userpage,
+                                       $userTitle,
                                        '',
                                        array(
                                                'lim' => 10,
                                                'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
-                                               'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
+                                               'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
                                                'showIfEmpty' => false
                                        )
                                );
@@ -421,6 +421,21 @@ class SpecialBlock extends FormSpecialPage {
                return $text;
        }
 
+       /**
+        * Get a user page target for things like logs.
+        * This handles account and IP range targets.
+        * @param $target User|string
+        * @return Title|null
+        */
+       protected static function getTargetUserTitle( $target ) {
+               if( $target instanceof User ) {
+                       return $target->getUserPage();
+               } elseif ( IP::isIPAddress( $target ) ) {
+                       return Title::makeTitleSafe( NS_USER, $target );
+               }
+               return null;
+       }
+
        /**
         * Determine the target of the block, and the type of target
         * TODO: should be in Block.php?