isSysop() ) { $wgOut->sysopRequired(); return; } $fields = array( "wpBlockAddress", "wpBlockReason" ); wfCleanFormFields( $fields ); $ipb = new IPBlockForm(); if ( "success" == $action ) { $ipb->showSuccess(); } else if ( "submit" == $action ) { $ipb->doSubmit(); } else { $ipb->showForm( "" ); } } class IPBlockForm { function showForm( $err ) { global $wgOut, $wgUser, $wgLang; global $ip, $wpBlockAddress, $wpBlockReason; $wgOut->setPagetitle( wfMsg( "blockip" ) ); $wgOut->addWikiText( wfMsg( "blockiptext" ) ); if ( ! $wpBlockAddress ) { $wpBlockAddress = $ip; } $ipa = wfMsg( "ipaddress" ); $reason = wfMsg( "ipbreason" ); $ipbs = wfMsg( "ipbsubmit" ); $action = wfLocalUrlE( $wgLang->specialPage( "Blockip" ), "action=submit" ); if ( "" != $err ) { $wgOut->setSubtitle( wfMsg( "formerror" ) ); $wgOut->addHTML( "

{$err}\n" ); } $wgOut->addHTML( "

{$ipa}:
{$reason}:
 
\n" ); } function doSubmit() { global $wgOut, $wgUser, $wgLang; global $ip, $wpBlockAddress, $wpBlockReason; $fname = "IPBlockForm::doSubmit"; $userId = 0; if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpBlockAddress ) ) { $userId = User::idFromName( $wpBlockAddress ); if ( $userId == 0 ) { $this->showForm( wfMsg( "badipaddress" ) ); return; } } if ( "" == $wpBlockReason ) { $this->showForm( wfMsg( "noblockreason" ) ); return; } # Note: for a user block, ipb_address is only for display purposes $sql = "INSERT INTO ipblocks (ipb_address, ipb_user, ipb_by, " . "ipb_reason, ipb_timestamp ) VALUES ('{$wpBlockAddress}', {$userId}, " . $wgUser->getID() . ", '" . wfStrencode( $wpBlockReason ) . "','" . wfTimestampNow() . "')"; wfQuery( $sql, $fname ); $success = wfLocalUrl( $wgLang->specialPage( "Blockip" ), "action=success&ip={$wpBlockAddress}" ); $wgOut->redirect( $success ); } function showSuccess() { global $wgOut, $wgUser; global $ip; $wgOut->setPagetitle( wfMsg( "blockip" ) ); $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) ); $text = str_replace( "$1", $ip, wfMsg( "blockipsuccesstext" ) ); $wgOut->addWikiText( $text ); } } ?>