Undelete bug partially fixed; Sysop ability to block users; various code formatting...
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
1 <?
2
3 function wfSpecialIpblocklist()
4 {
5 global $wgUser, $wgOut, $action, $ip;
6
7 $fields = array( "wpUnblockAddress" );
8 wfCleanFormFields( $fields );
9 $ipu = new IPUnblockForm();
10
11 if ( "success" == $action ) {
12 $msg = str_replace( "$1", $ip, wfMsg( "ipusuccess" ) );
13 $ipu->showList( $msg );
14 } else if ( "submit" == $action ) {
15 if ( ! $wgUser->isSysop() ) {
16 $wgOut->sysopRequired();
17 return;
18 }
19 $ipu->doSubmit();
20 } else if ( "unblock" == $action ) {
21 $ipu->showForm( "" );
22 } else {
23 $ipu->showList( "" );
24 }
25 }
26
27 class IPUnblockForm {
28
29 function showForm( $err )
30 {
31 global $wgOut, $wgUser, $wgLang;
32 global $ip, $wpUnblockAddress;
33
34 $wgOut->setPagetitle( wfMsg( "unblockip" ) );
35 $wgOut->addWikiText( wfMsg( "unblockiptext" ) );
36
37 if ( ! $wpUnblockAddress ) { $wpUnblockAddress = $ip; }
38 $ipa = wfMsg( "ipaddress" );
39 $ipus = wfMsg( "ipusubmit" );
40 $action = wfLocalUrlE( $wgLang->specialPage( "Ipblocklist" ),
41 "action=submit" );
42
43 if ( "" != $err ) {
44 $wgOut->setSubtitle( wfMsg( "formerror" ) );
45 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
46 }
47 $wgOut->addHTML( "<p>
48 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
49 <table border=0><tr>
50 <td align=right>{$ipa}:</td>
51 <td align=left>
52 <input tabindex=1 type=text size=20 name=\"wpUnblockAddress\" value=\"{$wpUnblockAddress}\">
53 </td></tr><tr>
54 <td>&nbsp;</td><td align=left>
55 <input tabindex=2 type=submit name=\"wpBlock\" value=\"{$ipus}\">
56 </td></tr></table>
57 </form>\n" );
58
59 }
60
61 function doSubmit()
62 {
63 global $wgOut, $wgUser, $wgLang;
64 global $ip, $wpUnblockAddress;
65 $fname = "IPUnblockForm::doSubmit";
66
67 $sql = "DELETE FROM ipblocks WHERE ipb_address='{$wpUnblockAddress}'";
68 wfQuery( $sql, $fname );
69
70 $success = wfLocalUrl( $wgLang->specialPage( "Ipblocklist" ),
71 "action=success&ip={$wpUnblockAddress}" );
72 $wgOut->redirect( $success );
73 }
74
75 function showList( $msg )
76 {
77 global $wgOut, $wgUser, $wgLang;
78 global $ip;
79
80 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
81 if ( "" != $msg ) {
82 $wgOut->setSubtitle( $msg );
83 }
84 $sql = "SELECT ipb_timestamp,ipb_address,ipb_user,ipb_by,ipb_reason " .
85 "FROM ipblocks ORDER BY ipb_timestamp";
86 $res = wfQuery( $sql, "IPUnblockForm::showList" );
87
88 $wgOut->addHTML( "<ul>" );
89 $sk = $wgUser->getSkin();
90 while ( $row = wfFetchObject( $res ) ) {
91 $addr = $row->ipb_address;
92 $name = User::whoIs( $row->ipb_by );
93 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
94 $d = $wgLang->timeanddate( $row->ipb_timestamp, true );
95
96 $line = str_replace( "$1", $d, wfMsg( "blocklistline" ) );
97 $line = str_replace( "$2", $ulink, $line );
98 $line = str_replace( "$3", $row->ipb_address, $line );
99
100 $wgOut->addHTML( "<li>{$line}" );
101 $clink = "<a href=\"" . wfLocalUrlE( $wgLang->specialPage(
102 "Contributions" ), "target={$addr}" ) . "\">" .
103 wfMsg( "contribslink" ) . "</a>";
104 $wgOut->addHTML( " ({$clink})" );
105
106 if ( $wgUser->isSysop() ) {
107 $ublink = "<a href=\"" . wfLocalUrlE( $wgLang->specialPage(
108 "Ipblocklist" ), "action=unblock&ip={$addr}" ) . "\">" .
109 wfMsg( "unblocklink" ) . "</a>";
110 $wgOut->addHTML( " ({$ublink})" );
111 }
112 if ( "" != $row->ipb_reason ) {
113 $wgOut->addHTML( " <em>(" . wfEscapeHTML( $row->ipb_reason ) .
114 ")</em>" );
115 }
116 $wgOut->addHTML( "</li>\n" );
117 }
118 wfFreeResult( $res );
119 $wgOut->addHTML( "</ul>\n" );
120 }
121 }
122
123 ?>