(bug 8701) Check database lock status when blocking/unblocking users
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
index 024385b..b90799f 100644 (file)
@@ -10,7 +10,7 @@
  */
 function wfSpecialIpblocklist() {
        global $wgUser, $wgOut, $wgRequest;
-
+       
        $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
        $id = $wgRequest->getVal( 'id' );
        $reason = $wgRequest->getText( 'wpUnblockReason' );
@@ -24,11 +24,21 @@ function wfSpecialIpblocklist() {
        } else if ( "submit" == $action && $wgRequest->wasPosted() &&
                $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
                if ( ! $wgUser->isAllowed('block') ) {
-                       $wgOut->sysopRequired();
+                       $wgOut->permissionRequired( 'block' );
+                       return;
+               }
+               # Can't unblock when the database is locked
+               if( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
                        return;
                }
                $ipu->doSubmit();
        } else if ( "unblock" == $action ) {
+               # Can't unblock when the database is locked
+               if( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
                $ipu->showForm( "" );
        } else {
                $ipu->showList( "" );
@@ -44,7 +54,7 @@ class IPUnblockForm {
        var $ip, $reason, $id;
 
        function IPUnblockForm( $ip, $id, $reason ) {
-               $this->ip = $ip;
+               $this->ip = strtr( $ip, '_', ' ' );
                $this->id = $id;
                $this->reason = $reason;
        }
@@ -58,7 +68,7 @@ class IPUnblockForm {
                $ipa = wfMsgHtml( $wgSysopUserBans ? 'ipadressorusername' : 'ipaddress' );
                $ipr = wfMsgHtml( 'ipbreason' );
                $ipus = wfMsgHtml( 'ipusubmit' );
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
+               $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
                $action = $titleObj->escapeLocalURL( "action=submit" );
 
                if ( "" != $err ) {
@@ -142,7 +152,7 @@ class IPUnblockForm {
 
                if ( $success ) {
                        # Report to the user
-                       $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
+                       $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
                        $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip ) );
                        $wgOut->redirect( $success );
                } else {
@@ -167,17 +177,25 @@ class IPUnblockForm {
                }
 
                $conds = array();
+               $matches = array();
                if ( $this->ip == '' ) {
                        // No extra conditions
                } elseif ( substr( $this->ip, 0, 1 ) == '#' ) {
                        $conds['ipb_id'] = substr( $this->ip, 1 );
-               } elseif ( wfIP2Unsigned( $this->ip ) !== false ) {
+               } elseif ( IP::toUnsigned( $this->ip ) !== false ) {
                        $conds['ipb_address'] = $this->ip;
                        $conds['ipb_auto'] = 0;
+               } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip, $matches ) ) {
+                       $conds['ipb_address'] = Block::normaliseRange( $this->ip );
+                       $conds['ipb_auto'] = 0;
                } else {
                        $user = User::newFromName( $this->ip );
-                       if ( ( $id = $user->getID() ) != 0 ) {
+                       if ( $user && ( $id = $user->getID() ) != 0 ) {
                                $conds['ipb_user'] = $id;
+                       } else {
+                               // Uh...?
+                               $conds['ipb_address'] = $this->ip;
+                               $conds['ipb_auto'] = 0;
                        }
                }
 
@@ -196,11 +214,12 @@ class IPUnblockForm {
        }
 
        function searchForm() {
-               global $wgTitle, $wgRequest;
+               global $wgTitle, $wgScript, $wgRequest;
                return
                        wfElement( 'form', array(
-                               'action' => $wgTitle->getLocalUrl() ),
+                               'action' => $wgScript ),
                                null ) .
+                       wfHidden( 'title', $wgTitle->getPrefixedDbKey() ) .
                        wfElement( 'input', array(
                                'type' => 'hidden',
                                'name' => 'action',
@@ -214,7 +233,7 @@ class IPUnblockForm {
                                'value' => $this->ip ) ) .
                        wfElement( 'input', array(
                                'type' => 'submit',
-                               'value' => wfMsg( 'search' ) ) ) .
+                               'value' => wfMsg( 'searchbutton' ) ) ) .
                        '</form>';
        }
 
@@ -233,7 +252,7 @@ class IPUnblockForm {
                if( is_null( $msg ) ) {
                        $msg = array();
                        $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink', 
-                               'anononlyblock', 'createaccountblock' );
+                               'anononlyblock', 'createaccountblock', 'noautoblockblock' );
                        foreach( $keys as $key ) {
                                $msg[$key] = wfMsgHtml( $key );
                        }
@@ -242,16 +261,17 @@ class IPUnblockForm {
                }
 
                # Prepare links to the blocker's user and talk pages
+               $blocker_id = $block->getBy();
                $blocker_name = $block->getByName();
-               $blocker = $sk->MakeLinkObj( Title::makeTitle( NS_USER, $blocker_name ), $blocker_name );
-               $blocker .= ' (' . $sk->makeLinkObj( Title::makeTitle( NS_USER_TALK, $blocker_name ), $wgLang->getNsText( NS_TALK ) ) . ')';
+               $blocker = $sk->userLink( $blocker_id, $blocker_name );
+               $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
 
                # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
                if( $block->mAuto ) {
                        $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
                } else {
                        $target = $sk->makeLinkObj( Title::makeTitle( NS_USER, $block->mAddress ), $block->mAddress );
-                       $target .= ' (' . $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $msg['contribslink'], 'target=' . urlencode( $block->mAddress ) ) . ')';
+                       $target .= ' (' . $sk->makeKnownLinkObj( SpecialPage::getSafeTitleFor( 'Contributions', $block->mAddress ), $msg['contribslink'] ) . ')';
                }
                
                $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
@@ -269,6 +289,10 @@ class IPUnblockForm {
                if ( $block->mCreateAccount ) {
                        $properties[] = $msg['createaccountblock'];
                }
+               if (!$block->mEnableAutoblock && $block->mUser ) {
+                       $properties[] = $msg['noautoblockblock'];
+               }
+
                $properties = implode( ', ', $properties );
 
                $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
@@ -276,7 +300,7 @@ class IPUnblockForm {
                $s = "<li>{$line}";
 
                if ( $wgUser->isAllowed('block') ) {
-                       $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
+                       $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
                        $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId ) ) . ')';
                }
                $s .= $sk->commentBlock( $block->mReason );
@@ -336,7 +360,7 @@ class IPBlocklistPager extends ReverseChronologicalPager {
                $conds[] = 'ipb_by=user_id';
                return array(
                        'tables' => array( 'ipblocks', 'user' ),
-                       'fields' => 'ipblocks.*,user_name',
+                       'fields' => $this->mDb->tableName( 'ipblocks' ) . '.*,user_name',
                        'conds' => $conds,
                );
        }