Commit JeLuF's register_globals fixes, first phase
[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 $wpBlockAddress = $_REQUEST["wpBlockAddress"];
27 $wpBlockReason = $_REQUEST["wpBlockReason"];
28 $ip = $_REQUEST["ip"];
29
30 $wgOut->setPagetitle( wfMsg( "blockip" ) );
31 $wgOut->addWikiText( wfMsg( "blockiptext" ) );
32
33 if ( ! $wpBlockAddress ) { $wpBlockAddress = $ip; }
34 $ipa = wfMsg( "ipaddress" );
35 $reason = wfMsg( "ipbreason" );
36 $ipbs = wfMsg( "ipbsubmit" );
37 $action = wfLocalUrlE( $wgLang->specialPage( "Blockip" ),
38 "action=submit" );
39
40 if ( "" != $err ) {
41 $wgOut->setSubtitle( wfMsg( "formerror" ) );
42 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
43 }
44 $wgOut->addHTML( "<p>
45 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
46 <table border=0><tr>
47 <td align=\"right\">{$ipa}:</td>
48 <td align=\"left\">
49 <input tabindex=1 type=text size=20 name=\"wpBlockAddress\" value=\"{$wpBlockAddress}\">
50 </td></tr><tr>
51 <td align=\"right\">{$reason}:</td>
52 <td align=\"left\">
53 <input tabindex=2 type=text size=40 name=\"wpBlockReason\" value=\"{$wpBlockReason}\">
54 </td></tr><tr>
55 <td>&nbsp;</td><td align=\"left\">
56 <input tabindex=3 type=submit name=\"wpBlock\" value=\"{$ipbs}\">
57 </td></tr></table>
58 </form>\n" );
59
60 }
61
62 function doSubmit()
63 {
64 global $wgOut, $wgUser, $wgLang;
65 global $ip, $wpBlockAddress, $wpBlockReason, $wgSysopUserBans;
66 $wpBlockAddress = $_REQUEST["wpBlockAddress"];
67 $wpBlockReason = $_REQUEST["wpBlockReason"];
68 $ip = $_REQUEST["ip"];
69
70 $userId = 0;
71 $wpBlockAddress = trim( $wpBlockAddress );
72
73 if ( ! preg_match( "/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/",
74 $wpBlockAddress ) )
75 {
76 if ( $wgSysopUserBans ) {
77 $userId = User::idFromName( $wpBlockAddress );
78 if ( $userId == 0 ) {
79 $this->showForm( wfMsg( "badipaddress" ) );
80 return;
81 }
82 } else {
83 $this->showForm( wfMsg( "badipaddress" ) );
84 return;
85 }
86 }
87 if ( "" == $wpBlockReason ) {
88 $this->showForm( wfMsg( "noblockreason" ) );
89 return;
90 }
91
92 # Create block
93 # Note: for a user block, ipb_address is only for display purposes
94 $ban = new Block( $wpBlockAddress, $userId, $wgUser->getID(),
95 wfStrencode( $wpBlockReason ), wfTimestampNow(), 0 );
96 $ban->insert();
97
98 # Make log entry
99 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
100 $action = wfMsg( "blocklogentry", $wgBlockAddress );
101 $log->addEntry( $action, $wpBlockReason );
102
103 # Report to the user
104 $success = wfLocalUrl( $wgLang->specialPage( "Blockip" ),
105 "action=success&ip={$wpBlockAddress}" );
106 $wgOut->redirect( $success );
107 }
108
109 function showSuccess()
110 {
111 global $wgOut, $wgUser;
112
113 $wgOut->setPagetitle( wfMsg( "blockip" ) );
114 $wgOut->setSubtitle( wfMsg( "blockipsuccesssub" ) );
115 $text = wfMsg( "blockipsuccesstext", $_REQUEST["ip"] );
116 $wgOut->addWikiText( $text );
117 }
118 }
119
120 ?>