* Removed the need to supply a reason for a block.
[lhc/web/wiklou.git] / includes / SpecialBlockip.php
index 34fde40..d5e58c6 100644 (file)
 function wfSpecialBlockip() {
        global $wgUser, $wgOut, $wgRequest;
 
-       if ( ! $wgUser->isSysop() ) {
+       if ( ! $wgUser->isAllowed('block') ) {
                $wgOut->sysopRequired();
                return;
        }
        $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" );
 
        }
@@ -147,29 +161,32 @@ class IPBlockForm {
                                return;
                        }
                        
-                       $expiry = wfUnix2Timestamp( $expiry );
+                       $expiry = wfTimestamp( TS_MW, $expiry );
 
                }
                
-               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 );
-               $ban->insert();
-
-               # Make log entry
-               $log = new LogPage( 'block' );
-               $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $this->BlockReason );
-
-               # Report to the user
-               $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' );
-               $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip='.$this->BlockAddress ) );
+                       $this->BlockReason, wfTimestampNow(), 0, $expiry );
+               
+               if (wfRunHooks('BlockIp', array(&$ban, &$wgUser))) {
+                       
+                       $ban->insert();
+                       
+                       wfRunHooks('BlockIpComplete', array($ban, $wgUser));
+                       
+                       # Make log entry
+                       $log = new LogPage( 'block' );
+                       $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), 
+                         $this->BlockReason, $this->BlockExpiry );
+
+                       # Report to the user
+                       $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' );
+                       $wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
+                               urlencode( $this->BlockAddress ) ) );
+               }
        }
 
        function showSuccess() {