Fix epic fail in r64860
[lhc/web/wiklou.git] / includes / specials / SpecialIpblocklist.php
index c81ae49..ccb2899 100644 (file)
@@ -5,12 +5,13 @@
  */
 
 /**
+ * @param $ip part of title: Special:Ipblocklist/<ip>.
  * @todo document
  */
-function wfSpecialIpblocklist() {
+function wfSpecialIpblocklist( $ip = '' ) {
        global $wgUser, $wgOut, $wgRequest;
-
-       $ip = trim( $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) ) );
+       $ip = $wgRequest->getVal( 'ip', $ip );
+       $ip = trim( $wgRequest->getVal( 'wpUnblockAddress', $ip ) );
        $id = $wgRequest->getVal( 'id' );
        $reason = $wgRequest->getText( 'wpUnblockReason' );
        $action = $wgRequest->getText( 'action' );
@@ -18,7 +19,7 @@ function wfSpecialIpblocklist() {
 
        $ipu = new IPUnblockForm( $ip, $id, $reason );
 
-       if( $action == 'unblock' ) {
+       if( $action == 'unblock' || $action == 'submit' && $wgRequest->wasPosted() ) {
                # Check permissions
                if( !$wgUser->isAllowed( 'block' ) ) {
                        $wgOut->permissionRequired( 'block' );
@@ -29,22 +30,34 @@ function wfSpecialIpblocklist() {
                        $wgOut->readOnlyPage();
                        return;
                }
-               # Show unblock form
-               $ipu->showForm( '' );
-       } elseif( $action == 'submit' && $wgRequest->wasPosted()
-               && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               # Check permissions
-               if( !$wgUser->isAllowed( 'block' ) ) {
-                       $wgOut->permissionRequired( 'block' );
-                       return;
+       
+               # bug 15810: blocked admins should have limited access here
+               if ( $wgUser->isBlocked() ) {
+                       if ( $id ) {
+                               # This doesn't pick up on autoblocks, but admins
+                               # should have the ipblock-exempt permission anyway
+                               $block = Block::newFromID( $id );
+                               $user = User::newFromName( $block->mAddress );
+                       } else {
+                               $user = User::newFromName( $ip );
+                       }
+                       $status = IPBlockForm::checkUnblockSelf( $user );
+                       if ( $status !== true ) {
+                               throw new ErrorPageError( 'badaccess', $status );
+                       }
                }
-               # Check for database lock
-               if( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
+               
+               if( $action == 'unblock' ){
+                       # Show unblock form
+                       $ipu->showForm( '' );
+               } elseif( $action == 'submit' 
+                       && $wgRequest->wasPosted()
+                       && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) 
+               {
+                       # Remove blocks and redirect user to success page
+                       $ipu->doSubmit();
                }
-               # Remove blocks and redirect user to success page
-               $ipu->doSubmit();
+               
        } elseif( $action == 'success' ) {
                # Inform the user of a successful unblock
                # (No need to check permissions or locks here,
@@ -94,7 +107,7 @@ class IPUnblockForm {
                $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
                $action = $titleObj->getLocalURL( "action=submit" );
 
-               if ( "" != $err ) {
+               if ( $err != "" ) {
                        $wgOut->setSubtitle( wfMsg( "formerror" ) );
                        $wgOut->addWikiText( Xml::tags( 'span', array( 'class' => 'error' ), $err ) . "\n" );
                }
@@ -235,7 +248,7 @@ class IPUnblockForm {
                global $wgOut, $wgUser;
 
                $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
-               if ( "" != $msg ) {
+               if ( $msg != "" ) {
                        $wgOut->setSubtitle( $msg );
                }
 
@@ -296,21 +309,44 @@ class IPUnblockForm {
                        $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
                }
 
+               // Search form
+               $wgOut->addHTML( $this->searchForm() );
+
+               // Check for other blocks, i.e. global/tor blocks
+               $otherBlockLink = array();
+               wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->ip ) );
+
+               // Show additional header for the local block only when other blocks exists.
+               // Not necessary in a standard installation without such extensions enabled
+               if( count( $otherBlockLink ) ) {
+                       $wgOut->addHTML(
+                               Html::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
+                       );
+               }
                $pager = new IPBlocklistPager( $this, $conds );
                if ( $pager->getNumRows() ) {
                        $wgOut->addHTML(
-                               $this->searchForm() .
                                $pager->getNavigationBar() .
                                Xml::tags( 'ul', null, $pager->getBody() ) .
                                $pager->getNavigationBar()
                        );
                } elseif ( $this->ip != '') {
-                       $wgOut->addHTML( $this->searchForm() );
                        $wgOut->addWikiMsg( 'ipblocklist-no-results' );
                } else {
-                       $wgOut->addHTML( $this->searchForm() );
                        $wgOut->addWikiMsg( 'ipblocklist-empty' );
                }
+
+               if( count( $otherBlockLink ) ) {
+                       $wgOut->addHTML(
+                               Html::rawElement( 'h2', array(), wfMsgExt( 'ipblocklist-otherblocks', 'parseinline', count( $otherBlockLink ) ) ) . "\n"
+                       );
+                       $list = '';
+                       foreach( $otherBlockLink as $link ) {
+                               $list .= Html::rawElement( 'li', array(), $link ) . "\n";
+                       }
+                       $wgOut->addHTML( Html::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
+               }
+
        }
 
        function searchForm() {