* Rename "ipusuccess" to "unblocked", change the format (now wiki text)
[lhc/web/wiklou.git] / includes / SpecialIpblocklist.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * @todo document
10 */
11 function wfSpecialIpblocklist() {
12 global $wgUser, $wgOut, $wgRequest;
13
14 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
15 $reason = $wgRequest->getText( 'wpUnblockReason' );
16 $action = $wgRequest->getText( 'action' );
17
18 $ipu = new IPUnblockForm( $ip, $reason );
19
20 if ( "success" == $action ) {
21 $ipu->showList( wfMsgWikiHtml( 'unblocked', $ip ) );
22 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
23 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
24 if ( ! $wgUser->isAllowed('block') ) {
25 $wgOut->sysopRequired();
26 return;
27 }
28 $ipu->doSubmit();
29 } else if ( "unblock" == $action ) {
30 $ipu->showForm( "" );
31 } else {
32 $ipu->showList( "" );
33 }
34 }
35
36 /**
37 *
38 * @package MediaWiki
39 * @subpackage SpecialPage
40 */
41 class IPUnblockForm {
42 var $ip, $reason;
43
44 function IPUnblockForm( $ip, $reason ) {
45 $this->ip = $ip;
46 $this->reason = $reason;
47 }
48
49 function showForm( $err ) {
50 global $wgOut, $wgUser, $wgSysopUserBans;
51
52 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
53 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
54
55 $ipa = wfMsgHtml( $wgSysopUserBans ? 'ipadressorusername' : 'ipaddress' );
56 $ipr = wfMsgHtml( 'ipbreason' );
57 $ipus = wfMsgHtml( 'ipusubmit' );
58 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
59 $action = $titleObj->escapeLocalURL( "action=submit" );
60
61 if ( "" != $err ) {
62 $wgOut->setSubtitle( wfMsg( "formerror" ) );
63 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
64 }
65 $token = htmlspecialchars( $wgUser->editToken() );
66
67 $wgOut->addHTML( "
68 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
69 <table border='0'>
70 <tr>
71 <td align='right'>{$ipa}:</td>
72 <td align='left'>
73 <input tabindex='1' type='text' size='20' name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip ) . "\" />
74 </td>
75 </tr>
76 <tr>
77 <td align='right'>{$ipr}:</td>
78 <td align='left'>
79 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason ) . "\" />
80 </td>
81 </tr>
82 <tr>
83 <td>&nbsp;</td>
84 <td align='left'>
85 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
86 </td>
87 </tr>
88 </table>
89 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
90 </form>\n" );
91
92 }
93
94 function doSubmit() {
95 global $wgOut;
96
97 $block = new Block();
98 $this->ip = trim( $this->ip );
99
100 if ( $this->ip{0} == "#" ) {
101 $block->mId = substr( $this->ip, 1 );
102 } else {
103 $block->mAddress = $this->ip;
104 }
105
106 # Delete block (if it exists)
107 # We should probably check for errors rather than just declaring success
108 $block->delete();
109
110 # Make log entry
111 $log = new LogPage( 'block' );
112 $log->addEntry( 'unblock', Title::makeTitle( NS_USER, $this->ip ), $this->reason );
113
114 # Report to the user
115 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
116 $success = $titleObj->getFullURL( "action=success&ip=" . urlencode( $this->ip ) );
117 $wgOut->redirect( $success );
118 }
119
120 function showList( $msg ) {
121 global $wgOut;
122
123 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
124 if ( "" != $msg ) {
125 $wgOut->setSubtitle( $msg );
126 }
127 global $wgRequest;
128 list( $this->limit, $this->offset ) = $wgRequest->getLimitOffset();
129 $this->counter = 0;
130
131 $paging = '<p>' . wfViewPrevNext( $this->offset, $this->limit,
132 Title::makeTitle( NS_SPECIAL, 'Ipblocklist' ),
133 'ip=' . urlencode( $this->ip ) ) . "</p>\n";
134 $wgOut->addHTML( $paging );
135
136 $search = $this->searchForm();
137 $wgOut->addHTML( $search );
138
139 $wgOut->addHTML( "<ul>" );
140 if( !Block::enumBlocks( array( &$this, "addRow" ), 0 ) ) {
141 // FIXME hack to solve #bug 1487
142 $wgOut->addHTML( '<li>'.wfMsgHtml( 'ipblocklistempty' ).'</li>' );
143 }
144 $wgOut->addHTML( "</ul>\n" );
145 $wgOut->addHTML( $paging );
146 }
147
148 function searchForm() {
149 global $wgTitle;
150 return
151 wfElement( 'form', array(
152 'action' => $wgTitle->getLocalUrl() ),
153 null ) .
154 wfElement( 'input', array(
155 'type' => 'hidden',
156 'name' => 'action',
157 'value' => 'search' ) ).
158 wfElement( 'input', array(
159 'type' => 'hidden',
160 'name' => 'limit',
161 'value' => $this->limit ) ).
162 wfElement( 'input', array(
163 'name' => 'ip',
164 'value' => $this->ip ) ) .
165 wfElement( 'input', array(
166 'type' => 'submit',
167 'value' => wfMsg( 'search' ) ) ) .
168 '</form>';
169 }
170
171 /**
172 * Callback function to output a block
173 */
174 function addRow( $block, $tag ) {
175 global $wgOut, $wgUser, $wgLang;
176
177 if( $this->ip != '' ) {
178 if( $block->mAuto ) {
179 if( stristr( $block->mId, $this->ip ) == false ) {
180 return;
181 }
182 } else {
183 if( stristr( $block->mAddress, $this->ip ) == false ) {
184 return;
185 }
186 }
187 }
188
189 // Loading blocks is fast; displaying them is slow.
190 // Quick hack for paging.
191 $this->counter++;
192 if( $this->counter <= $this->offset ) {
193 return;
194 }
195 if( $this->counter - $this->offset > $this->limit ) {
196 return;
197 }
198
199 $fname = 'IPUnblockForm-addRow';
200 wfProfileIn( $fname );
201
202 static $sk=null, $msg=null;
203
204 if( is_null( $sk ) )
205 $sk = $wgUser->getSkin();
206 if( is_null( $msg ) ) {
207 $msg = array();
208 foreach( array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink' ) as $key ) {
209 $msg[$key] = wfMsgHtml( $key );
210 }
211 $msg['blocklistline'] = wfMsg( 'blocklistline' );
212 $msg['contribslink'] = wfMsg( 'contribslink' );
213 }
214
215
216 # Prepare links to the blocker's user and talk pages
217 $blocker_name = $block->getByName();
218 $blocker = $sk->MakeLinkObj( Title::makeTitle( NS_USER, $blocker_name ), $blocker_name );
219 $blocker .= ' (' . $sk->makeLinkObj( Title::makeTitle( NS_USER_TALK, $blocker_name ), $wgLang->getNsText( NS_TALK ) ) . ')';
220
221 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
222 if( $block->mAuto ) {
223 $target = '#' . $block->mId; # Hide the IP addresses of auto-blocks; privacy
224 } else {
225 $target = $sk->makeLinkObj( Title::makeTitle( NS_USER, $block->mAddress ), $block->mAddress );
226 $target .= ' (' . $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $msg['contribslink'], 'target=' . urlencode( $block->mAddress ) ) . ')';
227 }
228
229 # Prep the address for the unblock link, masking autoblocks as before
230 $addr = $block->mAuto ? '#' . $block->mId : $block->mAddress;
231
232 $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
233
234 if ( $block->mExpiry === "" ) {
235 $formattedExpiry = $msg['infiniteblock'];
236 } else {
237 $formattedExpiry = wfMsgReplaceArgs( $msg['expiringblock'],
238 array( $wgLang->timeanddate( $block->mExpiry, true ) ) );
239 }
240
241 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $formattedExpiry ) );
242
243 $wgOut->addHTML( "<li>{$line}" );
244
245 if ( $wgUser->isAllowed('block') ) {
246 $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" );
247 $wgOut->addHTML( ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&ip=' . urlencode( $addr ) ) . ')' );
248 }
249 $wgOut->addHTML( $sk->commentBlock( $block->mReason ) );
250 $wgOut->addHTML( "</li>\n" );
251 wfProfileOut( $fname );
252 }
253 }
254
255 ?>