Addel label tag for wcUploadAffirm label
[mediawiki.git] / includes / SpecialBlockip.php
blob6d1cb59da1d4f98539f5753129e27209ff364f4e
1 <?
3 function wfSpecialBlockip()
5 global $wgUser, $wgOut, $action;
7 if ( ! $wgUser->isSysop() ) {
8 $wgOut->sysopRequired();
9 return;
11 $fields = array( "wpBlockAddress", "wpBlockReason" );
12 wfCleanFormFields( $fields );
13 $ipb = new IPBlockForm();
15 if ( "success" == $action ) { $ipb->showSuccess(); }
16 else if ( "submit" == $action ) { $ipb->doSubmit(); }
17 else { $ipb->showForm( "" ); }
20 class IPBlockForm {
22 function showForm( $err )
24 global $wgOut, $wgUser, $wgLang;
25 global $ip, $wpBlockAddress, $wpBlockReason;
27 $wgOut->setPagetitle( wfMsg( "blockip" ) );
28 $wgOut->addWikiText( wfMsg( "blockiptext" ) );
30 if ( ! $wpBlockAddress ) { $wpBlockAddress = $ip; }
31 $ipa = wfMsg( "ipaddress" );
32 $reason = wfMsg( "ipbreason" );
33 $ipbs = wfMsg( "ipbsubmit" );
34 $action = wfLocalUrlE( $wgLang->specialPage( "Blockip" ),
35 "action=submit" );
37 if ( "" != $err ) {
38 $wgOut->setSubtitle( wfMsg( "formerror" ) );
39 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
41 $wgOut->addHTML( "<p>
42 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
43 <table border=0><tr>
44 <td align=\"right\">{$ipa}:</td>
45 <td align=\"left\">
46 <input tabindex=1 type=text size=20 name=\"wpBlockAddress\" value=\"{$wpBlockAddress}\">
47 </td></tr><tr>
48 <td align=\"right\">{$reason}:</td>
49 <td align=\"left\">
50 <input tabindex=2 type=text size=40 name=\"wpBlockReason\" value=\"{$wpBlockReason}\">
51 </td></tr><tr>
52 <td>&nbsp;</td><td align=\"left\">
53 <input tabindex=3 type=submit name=\"wpBlock\" value=\"{$ipbs}\">
54 </td></tr></table>
55 </form>\n" );
59 function doSubmit()
61 global $wgOut, $wgUser, $wgLang;
62 global $ip, $wpBlockAddress, $wpBlockReason;
63 $fname = "IPBlockForm::doSubmit";
65 if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/",
66 $wpBlockAddress ) ) {
67 $this->showForm( wfMsg( "badipaddress" ) );
68 return;
70 if ( "" == $wpBlockReason ) {
71 $this->showForm( wfMsg( "noblockreason" ) );
72 return;
74 $sql = "INSERT INTO ipblocks (ipb_address, ipb_user, ipb_by, " .
75 "ipb_reason, ipb_timestamp ) VALUES ('{$wpBlockAddress}', 0, " .
76 $wgUser->getID() . ", '" . wfStrencode( $wpBlockReason ) . "','" .
77 wfTimestampNow() . "')";
78 wfQuery( $sql, $fname );
80 $success = wfLocalUrl( $wgLang->specialPage( "Blockip" ),
81 "action=success&ip={$wpBlockAddress}" );
82 $wgOut->redirect( $success );
85 function showSuccess()
87 global $wgOut, $wgUser;
88 global $ip;
90 $wgOut->setPagetitle( wfMsg( "blockip" ) );
91 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
92 $text = str_replace( "$1", $ip, wfMsg( "blockipsuccesstext" ) );
93 $wgOut->addWikiText( $text );