5 * @subpackage SpecialPage
11 function wfSpecialIpblocklist() {
12 global $wgUser, $wgOut, $wgRequest;
14 $ip = $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) );
15 $id = $wgRequest->getVal( 'id' );
16 $reason = $wgRequest->getText( 'wpUnblockReason' );
17 $action = $wgRequest->getText( 'action' );
18 $successip = $wgRequest->getVal( 'successip' );
20 $ipu = new IPUnblockForm( $ip, $id, $reason );
22 if ( "success" == $action ) {
23 $ipu->showList( $wgOut->parse( wfMsg( 'unblocked', $successip ) ) );
24 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
25 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
26 if ( ! $wgUser->isAllowed('block') ) {
27 $wgOut->permissionRequired( 'block' );
30 # Can't unblock when the database is locked
32 $wgOut->readOnlyPage();
36 } else if ( "unblock" == $action ) {
37 # Can't unblock when the database is locked
39 $wgOut->readOnlyPage();
51 * @subpackage SpecialPage
54 var $ip, $reason, $id;
56 function IPUnblockForm( $ip, $id, $reason ) {
57 $this->ip
= strtr( $ip, '_', ' ' );
59 $this->reason
= $reason;
62 function showForm( $err ) {
63 global $wgOut, $wgUser, $wgSysopUserBans;
65 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
66 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
68 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
69 $ipr = wfMsgHtml( 'ipbreason' );
70 $ipus = wfMsgHtml( 'ipusubmit' );
71 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
72 $action = $titleObj->escapeLocalURL( "action=submit" );
75 $wgOut->setSubtitle( wfMsg( "formerror" ) );
76 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
78 $token = htmlspecialchars( $wgUser->editToken() );
82 $block = Block
::newFromID( $this->id
);
84 $encName = htmlspecialchars( $block->getRedactedName() );
85 $encId = htmlspecialchars( $this->id
);
86 $addressPart = $encName . "<input type='hidden' name=\"id\" value=\"$encId\" />";
89 if ( !$addressPart ) {
90 $addressPart = "<input tabindex='1' type='text' size='20' " .
91 "name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />";
95 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
98 <td align='right'>{$ipa}:</td>
104 <td align='right'>{$ipr}:</td>
106 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
112 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
116 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
121 function doSubmit() {
125 $block = Block
::newFromID( $this->id
);
127 $this->ip
= $block->getRedactedName();
130 $block = new Block();
131 $this->ip
= trim( $this->ip
);
132 if ( substr( $this->ip
, 0, 1 ) == "#" ) {
133 $id = substr( $this->ip
, 1 );
134 $block = Block
::newFromID( $id );
136 $block = Block
::newFromDB( $this->ip
);
145 if ( $block->delete() ) {
147 $log = new LogPage( 'block' );
148 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
155 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
156 $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip
) );
157 $wgOut->redirect( $success );
159 if ( !$this->ip
&& $this->id
) {
160 $this->ip
= '#' . $this->id
;
162 $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id
) ) );
166 function showList( $msg ) {
169 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
171 $wgOut->setSubtitle( $msg );
174 // Purge expired entries on one in every 10 queries
175 if ( !mt_rand( 0, 10 ) ) {
176 Block
::purgeExpired();
181 if ( $this->ip
== '' ) {
182 // No extra conditions
183 } elseif ( substr( $this->ip
, 0, 1 ) == '#' ) {
184 $conds['ipb_id'] = substr( $this->ip
, 1 );
185 } elseif ( IP
::toUnsigned( $this->ip
) !== false ) {
186 $conds['ipb_address'] = $this->ip
;
187 $conds['ipb_auto'] = 0;
188 } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip
, $matches ) ) {
189 $conds['ipb_address'] = Block
::normaliseRange( $this->ip
);
190 $conds['ipb_auto'] = 0;
192 $user = User
::newFromName( $this->ip
);
193 if ( $user && ( $id = $user->getID() ) != 0 ) {
194 $conds['ipb_user'] = $id;
197 $conds['ipb_address'] = $this->ip
;
198 $conds['ipb_auto'] = 0;
202 $pager = new IPBlocklistPager( $this, $conds );
203 $s = $pager->getNavigationBar() .
205 if ( $pager->getNumRows() ) {
210 $s .= '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
212 $s .= $pager->getNavigationBar();
213 $wgOut->addHTML( $s );
216 function searchForm() {
217 global $wgTitle, $wgScript, $wgRequest;
219 wfElement( 'form', array(
220 'action' => $wgScript ),
222 wfHidden( 'title', $wgTitle->getPrefixedDbKey() ) .
223 wfElement( 'input', array(
226 'value' => 'search' ) ).
227 wfElement( 'input', array(
230 'value' => $wgRequest->getText( 'limit' ) ) ) .
231 wfElement( 'input', array(
233 'value' => $this->ip
) ) .
234 wfElement( 'input', array(
236 'value' => wfMsg( 'searchbutton' ) ) ) .
241 * Callback function to output a block
243 function formatRow( $block ) {
244 global $wgUser, $wgLang;
246 wfProfileIn( __METHOD__
);
248 static $sk=null, $msg=null;
251 $sk = $wgUser->getSkin();
252 if( is_null( $msg ) ) {
254 $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink',
255 'anononlyblock', 'createaccountblock', 'noautoblockblock' );
256 foreach( $keys as $key ) {
257 $msg[$key] = wfMsgHtml( $key );
259 $msg['blocklistline'] = wfMsg( 'blocklistline' );
260 $msg['contribslink'] = wfMsg( 'contribslink' );
263 # Prepare links to the blocker's user and talk pages
264 $blocker_id = $block->getBy();
265 $blocker_name = $block->getByName();
266 $blocker = $sk->userLink( $blocker_id, $blocker_name );
267 $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
269 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
270 if( $block->mAuto
) {
271 $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
273 $target = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $block->mAddress
), $block->mAddress
);
274 $target .= ' (' . $sk->makeKnownLinkObj( SpecialPage
::getSafeTitleFor( 'Contributions', $block->mAddress
), $msg['contribslink'] ) . ')';
277 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
279 $properties = array();
280 if ( $block->mExpiry
=== "" ||
$block->mExpiry
=== Block
::infinity() ) {
281 $properties[] = $msg['infiniteblock'];
283 $properties[] = wfMsgReplaceArgs( $msg['expiringblock'],
284 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
286 if ( $block->mAnonOnly
) {
287 $properties[] = $msg['anononlyblock'];
289 if ( $block->mCreateAccount
) {
290 $properties[] = $msg['createaccountblock'];
292 if (!$block->mEnableAutoblock
&& $block->mUser
) {
293 $properties[] = $msg['noautoblockblock'];
296 $properties = implode( ', ', $properties );
298 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
302 if ( $wgUser->isAllowed('block') ) {
303 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
304 $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId
) ) . ')';
306 $s .= $sk->commentBlock( $block->mReason
);
308 wfProfileOut( __METHOD__
);
313 class IPBlocklistPager
extends ReverseChronologicalPager
{
314 public $mForm, $mConds;
316 function __construct( $form, $conds = array() ) {
317 $this->mForm
= $form;
318 $this->mConds
= $conds;
319 parent
::__construct();
322 function getStartBody() {
323 wfProfileIn( __METHOD__
);
324 # Do a link batch query
325 $this->mResult
->seek( 0 );
329 while ( $row = $this->mResult->fetchObject() ) {
330 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
331 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
332 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->ipb_address ) );
333 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ipb_address ) );
336 # Usernames and titles are in fact related by a simple substitution of space -> underscore
337 # The last few lines of Title::secureAndSplit() tell the story.
338 while ( $row = $this->mResult
->fetchObject() ) {
339 $name = str_replace( ' ', '_', $row->user_name
);
340 $lb->add( NS_USER
, $name );
341 $lb->add( NS_USER_TALK
, $name );
342 $name = str_replace( ' ', '_', $row->ipb_address
);
343 $lb->add( NS_USER
, $name );
344 $lb->add( NS_USER_TALK
, $name );
347 wfProfileOut( __METHOD__
);
351 function formatRow( $row ) {
353 $block->initFromRow( $row );
354 return $this->mForm
->formatRow( $block );
357 function getQueryInfo() {
358 $conds = $this->mConds
;
359 $conds[] = 'ipb_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
360 $conds[] = 'ipb_by=user_id';
362 'tables' => array( 'ipblocks', 'user' ),
363 'fields' => $this->mDb
->tableName( 'ipblocks' ) . '.*,user_name',
368 function getIndexField() {
369 return 'ipb_timestamp';