744ceee13c05eac863673c66279a06392a743924
[lhc/web/wiklou.git] / includes / SpecialBlockip.php
1 <?
2
3 function wfSpecialBlockip()
4 {
5 global $wgUser, $wgOut, $action;
6
7 if ( ! $wgUser->isSysop() ) {
8 $wgOut->sysopRequired();
9 return;
10 }
11 $fields = array( "wpBlockAddress", "wpBlockReason" );
12 wfCleanFormFields( $fields );
13 $ipb = new IPBlockForm();
14
15 if ( "success" == $action ) { $ipb->showSuccess(); }
16 else if ( "submit" == $action ) { $ipb->doSubmit(); }
17 else { $ipb->showForm( "" ); }
18 }
19
20 class IPBlockForm {
21
22 function showForm( $err )
23 {
24 global $wgOut, $wgUser, $wgLang;
25 global $ip, $wpBlockAddress, $wpBlockReason;
26
27 $wgOut->setPagetitle( wfMsg( "blockip" ) );
28 $wgOut->addWikiText( wfMsg( "blockiptext" ) );
29
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" );
36
37 if ( "" != $err ) {
38 $wgOut->setSubtitle( wfMsg( "formerror" ) );
39 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
40 }
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" );
56
57 }
58
59 function doSubmit()
60 {
61 global $wgOut, $wgUser, $wgLang;
62 global $ip, $wpBlockAddress, $wpBlockReason, $wgSysopUserBlocks;
63 $fname = "IPBlockForm::doSubmit";
64
65 $userId = 0;
66 if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/",
67 $wpBlockAddress ) )
68 {
69 if ( $wgSysopUserBlocks ) {
70 $userId = User::idFromName( $wpBlockAddress );
71 if ( $userId == 0 ) {
72 $this->showForm( wfMsg( "badipaddress" ) );
73 return;
74 }
75 } else {
76 $this->showForm( wfMsg( "badipaddress" ) );
77 return;
78 }
79 }
80 if ( "" == $wpBlockReason ) {
81 $this->showForm( wfMsg( "noblockreason" ) );
82 return;
83 }
84
85 # Note: for a user block, ipb_address is only for display purposes
86
87 $sql = "INSERT INTO ipblocks (ipb_address, ipb_user, ipb_by, " .
88 "ipb_reason, ipb_timestamp ) VALUES ('{$wpBlockAddress}', {$userId}, " .
89 $wgUser->getID() . ", '" . wfStrencode( $wpBlockReason ) . "','" .
90 wfTimestampNow() . "')";
91 wfQuery( $sql, $fname );
92
93 $success = wfLocalUrl( $wgLang->specialPage( "Blockip" ),
94 "action=success&ip={$wpBlockAddress}" );
95 $wgOut->redirect( $success );
96 }
97
98 function showSuccess()
99 {
100 global $wgOut, $wgUser;
101 global $ip;
102
103 $wgOut->setPagetitle( wfMsg( "blockip" ) );
104 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
105 $text = str_replace( "$1", $ip, wfMsg( "blockipsuccesstext" ) );
106 $wgOut->addWikiText( $text );
107 }
108 }
109
110 ?>