use Database::timestamp() for cutoff
[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 class='error'>{$err}</p>\n" );
53 }
54
55 $wgOut->addHTML( "
56 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
57 <table border='0'>
58 <tr>
59 <td align='right'>{$ipa}:</td>
60 <td align='left'>
61 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\" />
62 </td>
63 </tr>
64 <tr>
65 <td align='right'>{$ipr}:</td>
66 <td align='left'>
67 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\" />
68 </td>
69 </tr>
70 <tr>
71 <td>&nbsp;</td>
72 <td align='left'>
73 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
74 </td>
75 </tr>
76 </table>
77 </form>\n" );
78
79 }
80
81 function doSubmit()
82 {
83 global $wgOut, $wgUser, $wgLang;
84
85 $block = new Block();
86 $this->ip = trim( $this->ip );
87
88 if ( $this->ip{0} == "#" ) {
89 $block->mId = substr( $this->ip, 1 );
90 } else {
91 $block->mAddress = $this->ip;
92 }
93
94 # Delete block (if it exists)
95 # We should probably check for errors rather than just declaring success
96 $block->delete();
97
98 # Make log entry
99 $log = new LogPage( wfMsg( "blocklogpage" ), wfMsg( "blocklogtext" ) );
100 $action = wfMsg( "unblocklogentry", $this->ip );
101 $log->addEntry( $action, $this->reason );
102
103 # Report to the user
104 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
105 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip ) );
106 $wgOut->redirect( $success );
107 }
108
109 function showList( $msg )
110 {
111 global $wgOut;
112
113 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
114 if ( "" != $msg ) {
115 $wgOut->setSubtitle( $msg );
116 }
117 $wgOut->addHTML( "<ul>" );
118 Block::enumBlocks( "wfAddRow", 0 );
119 $wgOut->addHTML( "</ul>\n" );
120 }
121 }
122
123 # Callback function to output a block
124 function wfAddRow( $block, $tag ) {
125 global $wgOut, $wgUser, $wgLang;
126
127 $sk = $wgUser->getSkin();
128
129 # Hide addresses blocked by User::spreadBlocks, for privacy
130 $addr = $block->mAuto ? "#{$block->mId}" : $block->mAddress;
131
132 $name = User::whoIs( $block->mBy );
133 $ulink = $sk->makeKnownLink( $wgLang->getNsText( Namespace::getUser() ). ":{$name}", $name );
134 $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
135
136 if ( $block->mExpiry === "" ) {
137 $formattedExpiry = "indefinite";
138 } else {
139 $formattedExpiry = $wgLang->timeanddate( $block->mExpiry, true );
140 }
141
142 $line = wfMsg( "blocklistline", $formattedTime, $ulink, $addr, $formattedExpiry );
143
144 $wgOut->addHTML( "<li>{$line}" );
145
146 if ( !$block->mAuto ) {
147 $titleObj = Title::makeTitle( NS_SPECIAL, "Contributions" );
148 $clink = "<a href=\"" . $titleObj->escapeLocalURL( "target={$block->mAddress}" ) . "\">" .
149 wfMsg( "contribslink" ) . "</a>";
150 $wgOut->addHTML( " ({$clink})" );
151 }
152
153 if ( $wgUser->isSysop() ) {
154 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
155 $ublink = "<a href=\"" .
156 $titleObj->escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" .
157 wfMsg( "unblocklink" ) . "</a>";
158 $wgOut->addHTML( " ({$ublink})" );
159 }
160 if ( "" != $block->mReason ) {
161 $wgOut->addHTML( " <em>(" . wfEscapeHTML( $block->mReason ) .
162 ")</em>" );
163 }
164 $wgOut->addHTML( "</li>\n" );
165 }
166
167
168 ?>