More globals and uninitialized variables fixes. Added WebRequest ($wgRequest)
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
1 <?php
2
3 function wfSpecialIpblocklist()
4 {
5 global $wgUser, $wgOut, $wgRequest, $action;
6
7 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
8 $reason = $wgRequest->getText( 'wpUnblockReason' );
9
10 $ipu = new IPUnblockForm( $ip, $reason );
11
12 if ( "success" == $action ) {
13 $msg = wfMsg( "ipusuccess", $ip );
14 $ipu->showList( $msg );
15 } else if ( "submit" == $action && $wgRequest->wasPosted() ) {
16 if ( ! $wgUser->isSysop() ) {
17 $wgOut->sysopRequired();
18 return;
19 }
20 $ipu->doSubmit();
21 } else if ( "unblock" == $action ) {
22 $ipu->showForm( "" );
23 } else {
24 $ipu->showList( "" );
25 }
26 }
27
28 class IPUnblockForm {
29 var $ip, $reason;
30
31 function IPUnblockForm( $ip, $reason ) {
32 $this->ip = $ip;
33 $this->reason = $reason;
34 }
35
36 function showForm( $err )
37 {
38 global $wgOut, $wgUser, $wgLang;
39
40 $wgOut->setPagetitle( wfMsg( "unblockip" ) );
41 $wgOut->addWikiText( wfMsg( "unblockiptext" ) );
42
43 $ipa = wfMsg( "ipaddress" );
44 $ipr = wfMsg( "ipbreason" );
45 $ipus = htmlspecialchars( wfMsg( "ipusubmit" ) );
46 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
47 $action = $titleObj->escapeLocalURL( "action=submit" );
48
49 if ( "" != $err ) {
50 $wgOut->setSubtitle( wfMsg( "formerror" ) );
51 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
52 }
53
54 $wgOut->addHTML( "<p>
55 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
56 <table border=0><tr>
57 <td align=right>{$ipa}:</td>
58 <td align=left>
59 <input tabindex=1 type=text size=20 name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\">
60 </td></tr><tr>
61 <td align=right>{$ipr}:</td>
62 <td align=left>
63 <input tabindex=1 type=text size=40 name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\">
64 </td></tr><tr>
65 <td>&nbsp;</td><td align=left>
66 <input tabindex=2 type=submit name=\"wpBlock\" value=\"{$ipus}\">
67 </td></tr></table>
68 </form>\n" );
69
70 }
71
72 function doSubmit()
73 {
74 global $wgOut, $wgUser, $wgLang;
75
76 $block = new Block();
77 $this->ip = trim( $this->ip );
78
79 if ( $this->ip{0} == "#" ) {
80 $block->mId = substr( $this->ip, 1 );
81 } else {
82 $block->mAddress = $this->ip;
83 }
84
85 # Delete block (if it exists)
86 # We should probably check for errors rather than just declaring success
87 $block->delete();
88
89 # Make log entry
90 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
91 $action = wfMsg( "unblocklogentry", $this->ip );
92 $log->addEntry( $action, $this->reason );
93
94 # Report to the user
95 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
96 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip ) );
97 $wgOut->redirect( $success );
98 }
99
100 function showList( $msg )
101 {
102 global $wgOut;
103
104 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
105 if ( "" != $msg ) {
106 $wgOut->setSubtitle( $msg );
107 }
108 $wgOut->addHTML( "<ul>" );
109 Block::enumBlocks( "wfAddRow", 0 );
110 $wgOut->addHTML( "</ul>\n" );
111 }
112 }
113
114 # Callback function to output a block
115 function wfAddRow( $block, $tag ) {
116 global $wgOut, $wgUser, $wgLang;
117
118 $sk = $wgUser->getSkin();
119
120 # Hide addresses blocked by User::spreadBlocks, for privacy
121 $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
122
123 $name = User::whoIs( $block->mBy );
124 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
125 $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
126
127 if ( $block->mExpiry === "" ) {
128 $formattedExpiry = "indefinite";
129 } else {
130 $formattedExpiry = $wgLang->timeanddate( $block->mExpiry, true );
131 }
132
133 $line = wfMsg( "blocklistline", $formattedTime, $ulink, $addr, $formattedExpiry );
134
135 $wgOut->addHTML( "<li>{$line}" );
136
137 if ( !$block->mAuto ) {
138 $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" );
139 $clink = "<a href=\"" . $titleObj->escapeLocalURL( "target={$block->mAddress}" ) . "\">" .
140 wfMsg( "contribslink" ) . "</a>";
141 $wgOut->addHTML( " ({$clink})" );
142 }
143
144 if ( $wgUser->isSysop() ) {
145 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
146 $ublink = "<a href=\"" .
147 $titleObj->escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" .
148 wfMsg( "unblocklink" ) . "</a>";
149 $wgOut->addHTML( " ({$ublink})" );
150 }
151 if ( "" != $block->mReason ) {
152 $wgOut->addHTML( " <em>(" . wfEscapeHTML( $block->mReason ) .
153 ")</em>" );
154 }
155 $wgOut->addHTML( "</li>\n" );
156 }
157
158
159 ?>