Fix fucked up unblock links in Special:Ipblocklist
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
index 1cc467d..1b88024 100644 (file)
  */
 function wfSpecialIpblocklist() {
        global $wgUser, $wgOut, $wgRequest;
-       
+
        $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
        $reason = $wgRequest->getText( 'wpUnblockReason' );
        $action = $wgRequest->getText( 'action' );
-       
+
        $ipu = new IPUnblockForm( $ip, $reason );
 
        if ( "success" == $action ) {
@@ -41,12 +41,12 @@ function wfSpecialIpblocklist() {
  */
 class IPUnblockForm {
        var $ip, $reason;
-       
+
        function IPUnblockForm( $ip, $reason ) {
                $this->ip = $ip;
                $this->reason = $reason;
        }
-       
+
        function showForm( $err ) {
                global $wgOut, $wgUser, $wgSysopUserBans;
 
@@ -64,7 +64,7 @@ class IPUnblockForm {
                        $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
                }
                $token = htmlspecialchars( $wgUser->editToken() );
-               
+
                $wgOut->addHTML( "
 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
        <table border='0'>
@@ -91,7 +91,7 @@ class IPUnblockForm {
 </form>\n" );
 
        }
-       
+
        function doSubmit() {
                global $wgOut, $wgUser;
 
@@ -120,7 +120,7 @@ class IPUnblockForm {
 
        function showList( $msg ) {
                global $wgOut;
-               
+
                $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
                if ( "" != $msg ) {
                        $wgOut->setSubtitle( $msg );
@@ -128,15 +128,15 @@ class IPUnblockForm {
                global $wgRequest;
                list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset();
                $this->counter = 0;
-               
+
                $paging = '<p>' . wfViewPrevNext( $this->offset, $this->limit,
                        Title::makeTitle( NS_SPECIAL, 'Ipblocklist' ),
                        'ip=' . urlencode( $this->ip ) ) . "</p>\n";
                $wgOut->addHTML( $paging );
-               
+
                $search = $this->searchForm();
                $wgOut->addHTML( $search );
-
+               
                $wgOut->addHTML( "<ul>" );
                if( !Block::enumBlocks( array( &$this, "addRow" ), 0 ) ) {
                        // FIXME hack to solve #bug 1487
@@ -145,7 +145,7 @@ class IPUnblockForm {
                $wgOut->addHTML( "</ul>\n" );
                $wgOut->addHTML( $paging );
        }
-       
+
        function searchForm() {
                global $wgTitle;
                return
@@ -174,7 +174,7 @@ class IPUnblockForm {
         */
        function addRow( $block, $tag ) {
                global $wgOut, $wgUser, $wgLang;
-               
+
                if( $this->ip != '' ) {
                        if( $block->mAuto ) {
                                if( stristr( $block->mId, $this->ip ) == false ) {
@@ -186,7 +186,7 @@ class IPUnblockForm {
                                }
                        }
                }
-               
+
                // Loading blocks is fast; displaying them is slow.
                // Quick hack for paging.
                $this->counter++;
@@ -196,12 +196,12 @@ class IPUnblockForm {
                if( $this->counter - $this->offset > $this->limit ) {
                        return;
                }
-               
+
                $fname = 'IPUnblockForm-addRow';
                wfProfileIn( $fname );
-               
+
                static $sk=null, $msg=null;
-               
+
                if( is_null( $sk ) )
                        $sk = $wgUser->getSkin();
                if( is_null( $msg ) ) {
@@ -210,31 +210,39 @@ class IPUnblockForm {
                                $msg[$key] = wfMsgHtml( $key );
                        }
                        $msg['blocklistline'] = wfMsg( 'blocklistline' );
+                       $msg['contribslink'] = wfMsg( 'contribslink' );
                }
-       
-               # Hide addresses blocked by User::spreadBlocks, for privacy
-               $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
-       
-               $name = $block->getByName();
-               $ulink = $sk->makeKnownLinkObj( Title::makeTitle( NS_USER, $name ), $name );
-               $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
+
+
+               # Prepare links to the blocker's user and talk pages
+               $blocker_name = $block->getByName();
+               $blocker = $sk->MakeKnownLinkObj( Title::makeTitle( NS_USER, $blocker_name ), $blocker_name );
+               $blocker .= ' (' . $sk->makeKnownLinkObj( Title::makeTitle( NS_USER_TALK, $blocker_name ), $wgLang->getNsText( NS_TALK ) ) . ')';
+
+               # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
+               if( $block->mAuto ) {
+                       $target = '#' . $block->mID; # Hide the IP addresses of auto-blocks; privacy
+               } else {
+                       $target = $sk->makeKnownLinkObj( Title::makeTitle( NS_USER, $block->mAddress ), $block->mAddress );
+                       $target .= ' (' . $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $msg['contribslink'], 'target=' . $block->mAddress ) . ')';
+               }
+               
+               # Prep the address for the unblock link, masking autoblocks as before
+               $addr = $block->mAuto ? '#' . $block->mID : $block->mAddress;
                
+               $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
+
                if ( $block->mExpiry === "" ) {
                        $formattedExpiry = $msg['infiniteblock'];
                } else {
                        $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'],
                                array( $wgLang->timeanddate( $block->mExpiry, true ) ) );
                }
-               
-               $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $ulink, $addr, $formattedExpiry ) );
-               
+
+               $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $formattedExpiry ) );
+
                $wgOut->addHTML( "<li>{$line}" );
-       
-               if ( !$block->mAuto ) {
-                       $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" );
-                       $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['contribslink'], "target={$block->mAddress}") . ')' );
-               }
-       
+
                if ( $wgUser->isAllowed('block') ) {
                        $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
                        $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' );