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