4 * @addtogroup SpecialPage
10 function wfSpecialIpblocklist() {
11 global $wgUser, $wgOut, $wgRequest;
13 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
14 $id = $wgRequest->getVal( 'id' );
15 $reason = $wgRequest->getText( 'wpUnblockReason' );
16 $action = $wgRequest->getText( 'action' );
17 $successip = $wgRequest->getVal( 'successip' );
19 $ipu = new IPUnblockForm( $ip, $id, $reason );
21 if ( "success" == $action ) {
22 $ipu->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) );
23 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
24 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
25 if ( ! $wgUser->isAllowed('block') ) {
26 $wgOut->permissionRequired( 'block' );
29 # Can't unblock when the database is locked
31 $wgOut->readOnlyPage();
35 } else if ( "unblock" == $action ) {
36 # Can't unblock when the database is locked
38 $wgOut->readOnlyPage();
49 * @addtogroup SpecialPage
52 var $ip, $reason, $id;
54 function IPUnblockForm( $ip, $id, $reason ) {
55 $this->ip
= strtr( $ip, '_', ' ' );
57 $this->reason
= $reason;
60 function showForm( $err ) {
61 global $wgOut, $wgUser, $wgSysopUserBans;
63 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
64 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
66 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
67 $ipr = wfMsgHtml( 'ipbreason' );
68 $ipus = wfMsgHtml( 'ipusubmit' );
69 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
70 $action = $titleObj->escapeLocalURL( "action=submit" );
73 $wgOut->setSubtitle( wfMsg( "formerror" ) );
74 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
76 $token = htmlspecialchars( $wgUser->editToken() );
80 $block = Block
::newFromID( $this->id
);
82 $encName = htmlspecialchars( $block->getRedactedName() );
83 $encId = htmlspecialchars( $this->id
);
84 $addressPart = $encName . "<input type='hidden' name=\"id\" value=\"$encId\" />";
87 if ( !$addressPart ) {
88 $addressPart = "<input tabindex='1' type='text' size='20' " .
89 "name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />";
93 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
96 <td align='right'>{$ipa}:</td>
102 <td align='right'>{$ipr}:</td>
104 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
110 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
114 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
119 function doSubmit() {
123 $block = Block
::newFromID( $this->id
);
125 $this->ip
= $block->getRedactedName();
128 $block = new Block();
129 $this->ip
= trim( $this->ip
);
130 if ( substr( $this->ip
, 0, 1 ) == "#" ) {
131 $id = substr( $this->ip
, 1 );
132 $block = Block
::newFromID( $id );
134 $block = Block
::newFromDB( $this->ip
);
143 if ( $block->delete() ) {
145 $log = new LogPage( 'block' );
146 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
153 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
154 $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip
) );
155 $wgOut->redirect( $success );
157 if ( !$this->ip
&& $this->id
) {
158 $this->ip
= '#' . $this->id
;
160 $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id
) ) );
164 function showList( $msg ) {
165 global $wgOut, $wgUser;
167 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
169 $wgOut->setSubtitle( $msg );
172 // Purge expired entries on one in every 10 queries
173 if ( !mt_rand( 0, 10 ) ) {
174 Block
::purgeExpired();
179 // Is user allowed to see all the blocks?
180 if ( !$wgUser->isAllowed( 'oversight' ) )
181 $conds['ipb_deleted'] = 0;
182 if ( $this->ip
== '' ) {
183 // No extra conditions
184 } elseif ( substr( $this->ip
, 0, 1 ) == '#' ) {
185 $conds['ipb_id'] = substr( $this->ip
, 1 );
186 } elseif ( IP
::toUnsigned( $this->ip
) !== false ) {
187 $conds['ipb_address'] = $this->ip
;
188 $conds['ipb_auto'] = 0;
189 } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip
, $matches ) ) {
190 $conds['ipb_address'] = Block
::normaliseRange( $this->ip
);
191 $conds['ipb_auto'] = 0;
193 $user = User
::newFromName( $this->ip
);
194 if ( $user && ( $id = $user->getID() ) != 0 ) {
195 $conds['ipb_user'] = $id;
198 $conds['ipb_address'] = $this->ip
;
199 $conds['ipb_auto'] = 0;
203 # TODO: difference message between
204 # a) an real empty list and
205 # b) requested ip/username not on list
206 $pager = new IPBlocklistPager( $this, $conds );
207 if ( $pager->getNumRows() ) {
208 $s = $this->searchForm() .
209 $pager->getNavigationBar();
213 $s .= $pager->getNavigationBar();
215 $s = $this->searchForm() .
216 '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
218 $wgOut->addHTML( $s );
221 function searchForm() {
222 global $wgTitle, $wgScript, $wgRequest;
224 wfElement( 'form', array(
225 'action' => $wgScript ),
227 wfHidden( 'title', $wgTitle->getPrefixedDbKey() ) .
228 wfElement( 'input', array(
231 'value' => 'search' ) ).
232 wfElement( 'input', array(
235 'value' => $wgRequest->getText( 'limit' ) ) ) .
236 wfElement( 'input', array(
238 'value' => $this->ip
) ) .
239 wfElement( 'input', array(
241 'value' => wfMsg( 'ipblocklist-submit' ) ) ) .
246 * Callback function to output a block
248 function formatRow( $block ) {
249 global $wgUser, $wgLang;
251 wfProfileIn( __METHOD__
);
253 static $sk=null, $msg=null;
256 $sk = $wgUser->getSkin();
257 if( is_null( $msg ) ) {
259 $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink',
260 'anononlyblock', 'createaccountblock', 'noautoblockblock' );
261 foreach( $keys as $key ) {
262 $msg[$key] = wfMsgHtml( $key );
264 $msg['blocklistline'] = wfMsg( 'blocklistline' );
265 $msg['contribslink'] = wfMsg( 'contribslink' );
268 # Prepare links to the blocker's user and talk pages
269 $blocker_id = $block->getBy();
270 $blocker_name = $block->getByName();
271 $blocker = $sk->userLink( $blocker_id, $blocker_name );
272 $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
274 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
275 if( $block->mAuto
) {
276 $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
278 $target = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $block->mAddress
), $block->mAddress
);
279 $target .= ' (' . $sk->makeKnownLinkObj( SpecialPage
::getSafeTitleFor( 'Contributions', $block->mAddress
), $msg['contribslink'] ) . ')';
282 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
284 $properties = array();
285 if ( $block->mExpiry
=== "" ||
$block->mExpiry
=== Block
::infinity() ) {
286 $properties[] = $msg['infiniteblock'];
288 $properties[] = wfMsgReplaceArgs( $msg['expiringblock'],
289 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
291 if ( $block->mAnonOnly
) {
292 $properties[] = $msg['anononlyblock'];
294 if ( $block->mCreateAccount
) {
295 $properties[] = $msg['createaccountblock'];
297 if (!$block->mEnableAutoblock
&& $block->mUser
) {
298 $properties[] = $msg['noautoblockblock'];
301 $properties = implode( ', ', $properties );
303 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
306 if ( $wgUser->isAllowed('block') ) {
307 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
308 $unblocklink = ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId
) ) . ')';
311 $comment = $sk->commentBlock( $block->mReason
);
313 $s = "{$line} $comment";
314 if ( $block->mHideName
)
315 $s = '<span class="history-deleted">' . $s . '</span>';
317 wfProfileOut( __METHOD__
);
318 return "<li>$s $unblocklink</li>\n";
325 class IPBlocklistPager
extends ReverseChronologicalPager
{
326 public $mForm, $mConds;
328 function __construct( $form, $conds = array() ) {
329 $this->mForm
= $form;
330 $this->mConds
= $conds;
331 parent
::__construct();
334 function getStartBody() {
335 wfProfileIn( __METHOD__
);
336 # Do a link batch query
337 $this->mResult
->seek( 0 );
341 while ( $row = $this->mResult->fetchObject() ) {
342 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
343 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
344 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->ipb_address ) );
345 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ipb_address ) );
348 # Usernames and titles are in fact related by a simple substitution of space -> underscore
349 # The last few lines of Title::secureAndSplit() tell the story.
350 while ( $row = $this->mResult
->fetchObject() ) {
351 $name = str_replace( ' ', '_', $row->user_name
);
352 $lb->add( NS_USER
, $name );
353 $lb->add( NS_USER_TALK
, $name );
354 $name = str_replace( ' ', '_', $row->ipb_address
);
355 $lb->add( NS_USER
, $name );
356 $lb->add( NS_USER_TALK
, $name );
359 wfProfileOut( __METHOD__
);
363 function formatRow( $row ) {
365 $block->initFromRow( $row );
366 return $this->mForm
->formatRow( $block );
369 function getQueryInfo() {
370 $conds = $this->mConds
;
371 $conds[] = 'ipb_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
372 $conds[] = 'ipb_by=user_id';
374 'tables' => array( 'ipblocks', 'user' ),
375 'fields' => $this->mDb
->tableName( 'ipblocks' ) . '.*,user_name',
380 function getIndexField() {
381 return 'ipb_timestamp';