New feature (special page): Ancient pages: list oldest articles first
[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 if ( ! preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/",
68 $wpUnblockAddress ) ) {
69 $this->showForm( wfMsg( "badipaddress" ) );
70 return;
71 }
72 $sql = "DELETE FROM ipblocks WHERE ipb_address='{$wpUnblockAddress}'";
73 wfQuery( $sql, $fname );
74
75 $success = wfLocalUrl( $wgLang->specialPage( "Ipblocklist" ),
76 "action=success&ip={$wpUnblockAddress}" );
77 $wgOut->redirect( $success );
78 }
79
80 function showList( $msg )
81 {
82 global $wgOut, $wgUser, $wgLang;
83 global $ip;
84
85 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
86 if ( "" != $msg ) {
87 $wgOut->setSubtitle( $msg );
88 }
89 $sql = "SELECT ipb_timestamp,ipb_address,ipb_user,ipb_by,ipb_reason " .
90 "FROM ipblocks ORDER BY ipb_timestamp";
91 $res = wfQuery( $sql, "IPUnblockForm::showList" );
92
93 $wgOut->addHTML( "<ul>" );
94 $sk = $wgUser->getSkin();
95 while ( $row = wfFetchObject( $res ) ) {
96 $addr = $row->ipb_address;
97 $name = User::whoIs( $row->ipb_by );
98 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
99 $d = $wgLang->timeanddate( $row->ipb_timestamp, true );
100
101 $line = str_replace( "$1", $d, wfMsg( "blocklistline" ) );
102 $line = str_replace( "$2", $ulink, $line );
103 $line = str_replace( "$3", $row->ipb_address, $line );
104
105 $wgOut->addHTML( "<li>{$line}" );
106 $clink = "<a href=\"" . wfLocalUrlE( $wgLang->specialPage(
107 "Contributions" ), "target={$addr}" ) . "\">" .
108 wfMsg( "contribslink" ) . "</a>";
109 $wgOut->addHTML( " ({$clink})" );
110
111 if ( $wgUser->isSysop() ) {
112 $ublink = "<a href=\"" . wfLocalUrlE( $wgLang->specialPage(
113 "Ipblocklist" ), "action=unblock&ip={$addr}" ) . "\">" .
114 wfMsg( "unblocklink" ) . "</a>";
115 $wgOut->addHTML( " ({$ublink})" );
116 }
117 if ( "" != $row->ipb_reason ) {
118 $wgOut->addHTML( " <em>(" . wfEscapeHTML( $row->ipb_reason ) .
119 ")</em>" );
120 }
121 $wgOut->addHTML( "</li>\n" );
122 }
123 wfFreeResult( $res );
124 $wgOut->addHTML( "</ul>\n" );
125 }
126 }
127
128 ?>