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