Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

SpecialBlockip.php

Go to the documentation of this file.
00001 <?php 00002 00003 function wfSpecialBlockip() 00004 { 00005 global $wgUser, $wgOut, $wgRequest; 00006 00007 if ( ! $wgUser->isSysop() ) { 00008 $wgOut->sysopRequired(); 00009 return; 00010 } 00011 $ipb = new IPBlockForm(); 00012 00013 $action = $wgRequest->getVal( 'action' ); 00014 if ( "success" == $action ) { $ipb->showSuccess(); } 00015 else if ( $wgRequest->wasPosted() && "submit" == $action ) { $ipb->doSubmit(); } 00016 else { $ipb->showForm( "" ); } 00017 } 00018 00019 class IPBlockForm { 00020 var $BlockAddress, $BlockExpiry, $BlockReason; 00021 00022 function IPBlockForm() { 00023 global $wgRequest; 00024 $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip' ) ); 00025 $this->BlockReason = $wgRequest->getText( 'wpBlockReason' ); 00026 $this->BlockExpiry = $wgRequest->getVal( 'wpBlockExpiry' ); 00027 } 00028 00029 function showForm( $err ) 00030 { 00031 global $wgOut, $wgUser, $wgLang, $wgDefaultBlockExpiry; 00032 global $wgRequest; 00033 00034 $wgOut->setPagetitle( htmlspecialchars( wfMsg( "blockip" ) ) ); 00035 $wgOut->addWikiText( htmlspecialchars( wfMsg( "blockiptext" ) ) ); 00036 00037 if ( is_null( $this->BlockExpiry ) || $this->BlockExpiry === "" ) { 00038 $this->BlockExpiry = $wgDefaultBlockExpiry; 00039 } 00040 00041 $mIpaddress = htmlspecialchars( wfMsg( "ipaddress" ) ); 00042 $mIpbexpiry = htmlspecialchars( wfMsg( "ipbexpiry" ) ); 00043 $mIpbreason = htmlspecialchars( wfMsg( "ipbreason" ) ); 00044 $mIpbsubmit = htmlspecialchars( wfMsg( "ipbsubmit" ) ); 00045 $titleObj = Title::makeTitle( NS_SPECIAL, "Blockip" ); 00046 $action = $titleObj->escapeLocalURL( "action=submit" ); 00047 00048 if ( "" != $err ) { 00049 $wgOut->setSubtitle( htmlspecialchars( wfMsg( "formerror" ) ) ); 00050 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); 00051 } 00052 00053 $scBlockAddress = htmlspecialchars( $this->BlockAddress ); 00054 $scBlockExpiry = htmlspecialchars( $this->BlockExpiry ); 00055 $scBlockReason = htmlspecialchars( $this->BlockReason ); 00056 00057 $wgOut->addHTML( " 00058 <form id=\"blockip\" method=\"post\" action=\"{$action}\"> 00059 <table border='0'> 00060 <tr> 00061 <td align=\"right\">{$mIpaddress}:</td> 00062 <td align=\"left\"> 00063 <input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" /> 00064 </td> 00065 </tr> 00066 <tr> 00067 <td align=\"right\">{$mIpbexpiry}:</td> 00068 <td align=\"left\"> 00069 <input tabindex='2' type='text' size='20' name=\"wpBlockExpiry\" value=\"{$scBlockExpiry}\" /> 00070 </td> 00071 </tr> 00072 <tr> 00073 <td align=\"right\">{$mIpbreason}:</td> 00074 <td align=\"left\"> 00075 <input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" /> 00076 </td> 00077 </tr> 00078 <tr> 00079 <td>&nbsp;</td> 00080 <td align=\"left\"> 00081 <input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" /> 00082 </td> 00083 </tr> 00084 </table> 00085 </form>\n" ); 00086 00087 } 00088 00089 function doSubmit() 00090 { 00091 global $wgOut, $wgUser, $wgLang; 00092 global $wgSysopUserBans, $wgSysopRangeBans; 00093 00094 $userId = 0; 00095 $this->BlockAddress = trim( $this->BlockAddress ); 00096 $rxIP = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; 00097 00098 # Check for invalid specifications 00099 if ( ! preg_match( "/^$rxIP$/", $this->BlockAddress ) ) { 00100 if ( preg_match( "/^($rxIP)\\/(\\d{1,2})$/", $this->BlockAddress, $matches ) ) { 00101 if ( $wgSysopRangeBans ) { 00102 if ( $matches[2] > 31 || $matches[2] < 16 ) { 00103 $this->showForm( wfMsg( "ip_range_invalid" ) ); 00104 return; 00105 } 00106 $this->BlockAddress = Block::normaliseRange( $this->BlockAddress ); 00107 } else { 00108 # Range block illegal 00109 $this->showForm( wfMsg( "range_block_disabled" ) ); 00110 return; 00111 } 00112 } else { 00113 # Username block 00114 if ( $wgSysopUserBans ) { 00115 $userId = User::idFromName( $this->BlockAddress ); 00116 if ( $userId == 0 ) { 00117 $this->showForm( wfMsg( "nosuchuser", htmlspecialchars( $this->BlockAddress ) ) ); 00118 return; 00119 } 00120 } else { 00121 $this->showForm( wfMsg( "badipaddress" ) ); 00122 return; 00123 } 00124 } 00125 } 00126 00127 if ( $this->BlockExpiry == "infinite" || $this->BlockExpiry == "indefinite" ) { 00128 $expiry = ''; 00129 } else { 00130 # Convert GNU-style date, returns -1 on error 00131 $expiry = strtotime( $this->BlockExpiry ); 00132 00133 if ( $expiry < 0 ) { 00134 $this->showForm( wfMsg( "ipb_expiry_invalid" ) ); 00135 return; 00136 } 00137 00138 $expiry = wfUnix2Timestamp( $expiry ); 00139 00140 } 00141 00142 00143 if ( "" == $this->BlockReason ) { 00144 $this->showForm( wfMsg( "noblockreason" ) ); 00145 return; 00146 } 00147 00148 # Create block 00149 # Note: for a user block, ipb_address is only for display purposes 00150 00151 $ban = new Block( $this->BlockAddress, $userId, $wgUser->getID(), 00152 wfStrencode( $this->BlockReason ), wfTimestampNow(), 0, $expiry ); 00153 $ban->insert(); 00154 00155 # Make log entry 00156 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) ); 00157 $action = wfMsg( "blocklogentry", $this->BlockAddress, $this->BlockExpiry ); 00158 $log->addEntry( $action, $this->BlockReason ); 00159 00160 # Report to the user 00161 $titleObj = Title::makeTitle( NS_SPECIAL, "Blockip" ); 00162 $wgOut->redirect( $titleObj->getFullURL( "action=success&ip={$this->BlockAddress}" ) ); 00163 } 00164 00165 function showSuccess() 00166 { 00167 global $wgOut, $wgUser; 00168 00169 $wgOut->setPagetitle( wfMsg( "blockip" ) ); 00170 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) ); 00171 $text = wfMsg( "blockipsuccesstext", $this->BlockAddress ); 00172 $wgOut->addWikiText( $text ); 00173 } 00174 } 00175 00176 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7