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( $action == 'unblock' ) {
23 if( !$wgUser->isAllowed( 'block' ) ) {
24 $wgOut->permissionRequired( 'block' );
27 # Check for database lock
29 $wgOut->readOnlyPage();
34 } elseif( $action == 'submit' && $wgRequest->wasPosted()
35 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
37 if( !$wgUser->isAllowed( 'block' ) ) {
38 $wgOut->permissionRequired( 'block' );
41 # Check for database lock
43 $wgOut->readOnlyPage();
46 # Remove blocks and redirect user to success page
48 } elseif( $action == 'success' ) {
49 # Inform the user of a successful unblock
50 # (No need to check permissions or locks here,
51 # if something was done, then it's too late!)
52 if ( substr( $successip, 0, 1) == '#' ) {
53 // A block ID was unblocked
54 $ipu->showList( $wgOut->parse( wfMsg( 'unblocked-id', $successip ) ) );
56 // A username/IP was unblocked
57 $ipu->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) );
60 # Just show the block list
67 * implements Special:ipblocklist GUI
68 * @addtogroup SpecialPage
71 var $ip, $reason, $id;
73 function IPUnblockForm( $ip, $id, $reason ) {
74 $this->ip
= strtr( $ip, '_', ' ' );
76 $this->reason
= $reason;
79 function showForm( $err ) {
80 global $wgOut, $wgUser, $wgSysopUserBans, $wgContLang;
82 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
83 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
85 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
86 $ipr = wfMsgHtml( 'ipbreason' );
87 $ipus = wfMsgHtml( 'ipusubmit' );
88 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
89 $action = $titleObj->getLocalURL( "action=submit" );
90 $alignRight = $wgContLang->isRtl() ?
'left' : 'right';
93 $wgOut->setSubtitle( wfMsg( "formerror" ) );
94 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
96 $token = htmlspecialchars( $wgUser->editToken() );
100 $block = Block
::newFromID( $this->id
);
102 $encName = htmlspecialchars( $block->getRedactedName() );
104 $addressPart = $encName . Xml
::hidden( 'id', $encId );
107 if ( !$addressPart ) {
108 $addressPart = Xml
::input( 'wpUnblockAddress', 20, $this->ip
, array( 'type' => 'text', 'tabindex' => '1' ) );
112 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'unblockip' ) ) .
113 Xml
::openElement( 'table', array( 'border' => '0' ) ).
115 <td align='$alignRight'>
123 <td align='$alignRight'>
127 Xml
::input( 'wpUnblockReason', 40, $this->reason
, array( 'type' => 'text', 'tabindex' => '2' ) ) .
133 Xml
::submitButton( $ipus, array( 'name' => 'wpBlock', 'tabindex' => '3' ) ) .
136 Xml
::closeElement( 'table' ) .
137 Xml
::hidden( 'wpEditToken', $token ) .
138 Xml
::closeElement( 'form' ) . "\n"
143 function doSubmit() {
147 $block = Block
::newFromID( $this->id
);
149 $this->ip
= $block->getRedactedName();
152 $block = new Block();
153 $this->ip
= trim( $this->ip
);
154 if ( substr( $this->ip
, 0, 1 ) == "#" ) {
155 $id = substr( $this->ip
, 1 );
156 $block = Block
::newFromID( $id );
158 $block = Block
::newFromDB( $this->ip
);
167 if ( $block->delete() ) {
169 $log = new LogPage( 'block' );
170 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
177 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
178 $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip
) );
179 $wgOut->redirect( $success );
181 if ( !$this->ip
&& $this->id
) {
182 $this->ip
= '#' . $this->id
;
184 $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id
) ) );
188 function showList( $msg ) {
189 global $wgOut, $wgUser;
191 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
193 $wgOut->setSubtitle( $msg );
196 // Purge expired entries on one in every 10 queries
197 if ( !mt_rand( 0, 10 ) ) {
198 Block
::purgeExpired();
203 // Is user allowed to see all the blocks?
204 if ( !$wgUser->isAllowed( 'oversight' ) )
205 $conds['ipb_deleted'] = 0;
206 if ( $this->ip
== '' ) {
207 // No extra conditions
208 } elseif ( substr( $this->ip
, 0, 1 ) == '#' ) {
209 $conds['ipb_id'] = substr( $this->ip
, 1 );
210 } elseif ( IP
::toUnsigned( $this->ip
) !== false ) {
211 $conds['ipb_address'] = $this->ip
;
212 $conds['ipb_auto'] = 0;
213 } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip
, $matches ) ) {
214 $conds['ipb_address'] = Block
::normaliseRange( $this->ip
);
215 $conds['ipb_auto'] = 0;
217 $user = User
::newFromName( $this->ip
);
218 if ( $user && ( $id = $user->getID() ) != 0 ) {
219 $conds['ipb_user'] = $id;
222 $conds['ipb_address'] = $this->ip
;
223 $conds['ipb_auto'] = 0;
227 $pager = new IPBlocklistPager( $this, $conds );
228 if ( $pager->getNumRows() ) {
230 $this->searchForm() .
231 $pager->getNavigationBar() .
232 Xml
::tags( 'ul', null, $pager->getBody() ) .
233 $pager->getNavigationBar()
235 } elseif ( $this->ip
!= '') {
236 $wgOut->addHTML( $this->searchForm() );
237 $wgOut->addWikiText( wfMsg( 'ipblocklist-no-results' ) );
239 $wgOut->addWikiText( wfMsg( 'ipblocklist-empty' ) );
243 function searchForm() {
244 global $wgTitle, $wgScript, $wgRequest;
246 Xml
::tags( 'form', array( 'action' => $wgScript ),
247 Xml
::hidden( 'title', $wgTitle->getPrefixedDbKey() ) .
248 Xml
::openElement( 'fieldset' ) .
249 Xml
::element( 'legend', null, wfMsg( 'ipblocklist-legend' ) ) .
250 Xml
::inputLabel( wfMsg( 'ipblocklist-username' ), 'ip', 'ip', /* size */ false, $this->ip
) .
252 Xml
::submitButton( wfMsg( 'ipblocklist-submit' ) ) .
253 Xml
::closeElement( 'fieldset' )
258 * Callback function to output a block
260 function formatRow( $block ) {
261 global $wgUser, $wgLang;
263 wfProfileIn( __METHOD__
);
265 static $sk=null, $msg=null;
268 $sk = $wgUser->getSkin();
269 if( is_null( $msg ) ) {
271 $keys = array( 'infiniteblock', 'expiringblock', 'unblocklink',
272 'anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock' );
273 foreach( $keys as $key ) {
274 $msg[$key] = wfMsgHtml( $key );
276 $msg['blocklistline'] = wfMsg( 'blocklistline' );
279 # Prepare links to the blocker's user and talk pages
280 $blocker_id = $block->getBy();
281 $blocker_name = $block->getByName();
282 $blocker = $sk->userLink( $blocker_id, $blocker_name );
283 $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
285 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
286 if( $block->mAuto
) {
287 $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
289 $target = $sk->userLink( $block->mUser
, $block->mAddress
)
290 . $sk->userToolLinks( $block->mUser
, $block->mAddress
, false, Linker
::TOOL_LINKS_NOBLOCK
);
293 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
295 $properties = array();
296 if ( $block->mExpiry
=== "" ||
$block->mExpiry
=== Block
::infinity() ) {
297 $properties[] = $msg['infiniteblock'];
299 $properties[] = wfMsgReplaceArgs( $msg['expiringblock'],
300 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
302 if ( $block->mAnonOnly
) {
303 $properties[] = $msg['anononlyblock'];
305 if ( $block->mCreateAccount
) {
306 $properties[] = $msg['createaccountblock'];
308 if (!$block->mEnableAutoblock
&& $block->mUser
) {
309 $properties[] = $msg['noautoblockblock'];
312 if ( $block->mBlockEmail
&& $block->mUser
) {
313 $properties[] = $msg['emailblock'];
316 $properties = implode( ', ', $properties );
318 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
321 if ( $wgUser->isAllowed('block') ) {
322 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
323 $unblocklink = ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId
) ) . ')';
326 $comment = $sk->commentBlock( $block->mReason
);
328 $s = "{$line} $comment";
329 if ( $block->mHideName
)
330 $s = '<span class="history-deleted">' . $s . '</span>';
332 wfProfileOut( __METHOD__
);
333 return "<li>$s $unblocklink</li>\n";
341 class IPBlocklistPager
extends ReverseChronologicalPager
{
342 public $mForm, $mConds;
344 function __construct( $form, $conds = array() ) {
345 $this->mForm
= $form;
346 $this->mConds
= $conds;
347 parent
::__construct();
350 function getStartBody() {
351 wfProfileIn( __METHOD__
);
352 # Do a link batch query
353 $this->mResult
->seek( 0 );
357 while ( $row = $this->mResult->fetchObject() ) {
358 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
359 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
360 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->ipb_address ) );
361 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ipb_address ) );
364 # Usernames and titles are in fact related by a simple substitution of space -> underscore
365 # The last few lines of Title::secureAndSplit() tell the story.
366 while ( $row = $this->mResult
->fetchObject() ) {
367 $name = str_replace( ' ', '_', $row->user_name
);
368 $lb->add( NS_USER
, $name );
369 $lb->add( NS_USER_TALK
, $name );
370 $name = str_replace( ' ', '_', $row->ipb_address
);
371 $lb->add( NS_USER
, $name );
372 $lb->add( NS_USER_TALK
, $name );
375 wfProfileOut( __METHOD__
);
379 function formatRow( $row ) {
381 $block->initFromRow( $row );
382 return $this->mForm
->formatRow( $block );
385 function getQueryInfo() {
386 $conds = $this->mConds
;
387 $conds[] = 'ipb_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
388 $conds[] = 'ipb_by=user_id';
390 'tables' => array( 'ipblocks', 'user' ),
391 'fields' => $this->mDb
->tableName( 'ipblocks' ) . '.*,user_name',
396 function getIndexField() {
397 return 'ipb_timestamp';