Major changes to user groups:
[lhc/web/wiklou.git] / includes / SpecialBlockip.php
index e95f8aa..d5e58c6 100644 (file)
@@ -19,9 +19,14 @@ function wfSpecialBlockip() {
        $ipb = new IPBlockForm();
 
        $action = $wgRequest->getVal( 'action' );
-       if ( 'success' == $action ) { $ipb->showSuccess(); }
-       else if ( $wgRequest->wasPosted() && 'submit' == $action ) { $ipb->doSubmit(); }
-       else { $ipb->showForm( '' ); }
+       if ( 'success' == $action ) {
+               $ipb->showSuccess();
+       } else if ( $wgRequest->wasPosted() && 'submit' == $action &&
+               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+               $ipb->doSubmit();
+       } else {
+               $ipb->showForm( '' );
+       }
 }
 
 /**
@@ -41,17 +46,17 @@ class IPBlockForm {
        }
        
        function showForm( $err ) {
-               global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry;
-               global $wgRequest;
+               global $wgOut, $wgUser, $wgLang, $wgBlockExpiryOptions;
+               global $wgRequest, $wgSysopUserBans;
 
                $wgOut->setPagetitle( htmlspecialchars( wfMsg( 'blockip' ) ) );
-               $wgOut->addWikiText( htmlspecialchars( wfMsg( 'blockiptext' ) ) );
+               $wgOut->addWikiText( wfMsg( 'blockiptext' ) );
 
-               if ( is_null( $this->BlockExpiry ) || $this->BlockExpiry === '' ) {
-                       $this->BlockExpiry = $wgDefaultBlockExpiry;
+               if($wgSysopUserBans) {
+                       $mIpaddress = htmlspecialchars( wfMsg( 'ipadressorusername' ) );
+               } else {
+                       $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
                }
-
-               $mIpaddress = htmlspecialchars( wfMsg( 'ipaddress' ) );
                $mIpbexpiry = htmlspecialchars( wfMsg( 'ipbexpiry' ) );
                $mIpbreason = htmlspecialchars( wfMsg( 'ipbreason' ) );
                $mIpbsubmit = htmlspecialchars( wfMsg( 'ipbsubmit' ) );
@@ -66,6 +71,12 @@ class IPBlockForm {
                $scBlockAddress = htmlspecialchars( $this->BlockAddress );
                $scBlockExpiry = htmlspecialchars( $this->BlockExpiry );
                $scBlockReason = htmlspecialchars( $this->BlockReason );
+
+               $blockExpiryFormOptions = '<option>' .
+                       implode("</option>\n\t\t\t\t\t<option>", explode(',', $wgBlockExpiryOptions)) .
+                       '</option>';
+
+               $token = htmlspecialchars( $wgUser->editToken() );
                
                $wgOut->addHTML( "
 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
@@ -79,7 +90,9 @@ class IPBlockForm {
                <tr>
                        <td align=\"right\">{$mIpbexpiry}:</td>
                        <td align=\"left\">
-                               <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" />
+                               <select tabindex='2' name=\"wpBlockExpiry\">
+                                       $blockExpiryFormOptions
+                               </select>
                        </td>
                </tr>
                <tr>
@@ -95,6 +108,7 @@ class IPBlockForm {
                        </td>
                </tr>
        </table>
+       <input type='hidden' name='wpEditToken' value=\"{$token}\" />
 </form>\n" );
 
        }
@@ -151,22 +165,17 @@ class IPBlockForm {
 
                }
                
-               if ( $this->BlockReason == '') {
-                       $this->showForm( wfMsg( 'noblockreason' ) );
-                       return;
-               }
-               
                # Create block
                # Note: for a user block, ipb_address is only for display purposes
 
                $ban = new Block( $this->BlockAddress, $userId, $wgUser->getID(), 
-                       wfStrencode( $this->BlockReason ), wfTimestampNow(), 0, $expiry );
+                       $this->BlockReason, wfTimestampNow(), 0, $expiry );
                
-               if (wfRunHooks('BlockIp', $ban, $wgUser)) {
+               if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
                        
                        $ban->insert();
                        
-                       wfRunHooks('BlockIpComplete', $ban, $wgUser);
+                       wfRunHooks('BlockIpComplete', array($ban, $wgUser));
                        
                        # Make log entry
                        $log = new LogPage( 'block' );
@@ -175,7 +184,8 @@ class IPBlockForm {
 
                        # Report to the user
                        $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' );
-                       $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress ) );
+                       $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
+                               urlencode( $this->BlockAddress ) ) );
                }
        }