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' );
31 } else if ( "unblock" == $action ) {
41 * @subpackage SpecialPage
44 var $ip, $reason, $id;
46 function IPUnblockForm( $ip, $id, $reason ) {
49 $this->reason
= $reason;
52 function showForm( $err ) {
53 global $wgOut, $wgUser, $wgSysopUserBans;
55 $wgOut->setPagetitle( wfMsg( 'unblockip' ) );
56 $wgOut->addWikiText( wfMsg( 'unblockiptext' ) );
58 $ipa = wfMsgHtml( $wgSysopUserBans ?
'ipadressorusername' : 'ipaddress' );
59 $ipr = wfMsgHtml( 'ipbreason' );
60 $ipus = wfMsgHtml( 'ipusubmit' );
61 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
62 $action = $titleObj->escapeLocalURL( "action=submit" );
65 $wgOut->setSubtitle( wfMsg( "formerror" ) );
66 $wgOut->addWikitext( "<span class='error'>{$err}</span>\n" );
68 $token = htmlspecialchars( $wgUser->editToken() );
72 $block = Block
::newFromID( $this->id
);
74 $encName = htmlspecialchars( $block->getRedactedName() );
75 $encId = htmlspecialchars( $this->id
);
76 $addressPart = $encName . "<input type='hidden' name=\"id\" value=\"$encId\" />";
79 if ( !$addressPart ) {
80 $addressPart = "<input tabindex='1' type='text' size='20' " .
81 "name=\"wpUnblockAddress\" value=\"" . htmlspecialchars( $this->ip
) . "\" />";
85 <form id=\"unblockip\" method=\"post\" action=\"{$action}\">
88 <td align='right'>{$ipa}:</td>
94 <td align='right'>{$ipr}:</td>
96 <input tabindex='1' type='text' size='40' name=\"wpUnblockReason\" value=\"" . htmlspecialchars( $this->reason
) . "\" />
102 <input tabindex='2' type='submit' name=\"wpBlock\" value=\"{$ipus}\" />
106 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
111 function doSubmit() {
115 $block = Block
::newFromID( $this->id
);
117 $this->ip
= $block->getRedactedName();
120 $block = new Block();
121 $this->ip
= trim( $this->ip
);
122 if ( substr( $this->ip
, 0, 1 ) == "#" ) {
123 $id = substr( $this->ip
, 1 );
124 $block = Block
::newFromID( $id );
126 $block = Block
::newFromDB( $this->ip
);
135 if ( $block->delete() ) {
137 $log = new LogPage( 'block' );
138 $log->addEntry( 'unblock', Title
::makeTitle( NS_USER
, $this->ip
), $this->reason
);
145 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
146 $success = $titleObj->getFullURL( "action=success&successip=" . urlencode( $this->ip
) );
147 $wgOut->redirect( $success );
149 if ( !$this->ip
&& $this->id
) {
150 $this->ip
= '#' . $this->id
;
152 $this->showForm( wfMsg( 'ipb_cant_unblock', htmlspecialchars( $this->id
) ) );
156 function showList( $msg ) {
159 $wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
161 $wgOut->setSubtitle( $msg );
164 // Purge expired entries on one in every 10 queries
165 if ( !mt_rand( 0, 10 ) ) {
166 Block
::purgeExpired();
170 if ( $this->ip
== '' ) {
171 // No extra conditions
172 } elseif ( substr( $this->ip
, 0, 1 ) == '#' ) {
173 $conds['ipb_id'] = substr( $this->ip
, 1 );
174 } elseif ( IP
::toUnsigned( $this->ip
) !== false ) {
175 $conds['ipb_address'] = $this->ip
;
176 $conds['ipb_auto'] = 0;
177 } elseif( preg_match( "/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/", $this->ip
, $matches ) ) {
178 $conds['ipb_address'] = Block
::normaliseRange( $this->ip
);
179 $conds['ipb_auto'] = 0;
181 $user = User
::newFromName( $this->ip
);
182 if ( $user && ( $id = $user->getID() ) != 0 ) {
183 $conds['ipb_user'] = $id;
186 $conds['ipb_address'] = $this->ip
;
187 $conds['ipb_auto'] = 0;
191 $pager = new IPBlocklistPager( $this, $conds );
192 $s = $pager->getNavigationBar() .
194 if ( $pager->getNumRows() ) {
199 $s .= '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
201 $s .= $pager->getNavigationBar();
202 $wgOut->addHTML( $s );
205 function searchForm() {
206 global $wgTitle, $wgScript, $wgRequest;
208 wfElement( 'form', array(
209 'action' => $wgScript ),
211 wfHidden( 'title', $wgTitle->getPrefixedDbKey() ) .
212 wfElement( 'input', array(
215 'value' => 'search' ) ).
216 wfElement( 'input', array(
219 'value' => $wgRequest->getText( 'limit' ) ) ) .
220 wfElement( 'input', array(
222 'value' => $this->ip
) ) .
223 wfElement( 'input', array(
225 'value' => wfMsg( 'search' ) ) ) .
230 * Callback function to output a block
232 function formatRow( $block ) {
233 global $wgUser, $wgLang;
235 wfProfileIn( __METHOD__
);
237 static $sk=null, $msg=null;
240 $sk = $wgUser->getSkin();
241 if( is_null( $msg ) ) {
243 $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink',
244 'anononlyblock', 'createaccountblock' );
245 foreach( $keys as $key ) {
246 $msg[$key] = wfMsgHtml( $key );
248 $msg['blocklistline'] = wfMsg( 'blocklistline' );
249 $msg['contribslink'] = wfMsg( 'contribslink' );
252 # Prepare links to the blocker's user and talk pages
253 $blocker_name = $block->getByName();
254 $blocker = $sk->MakeLinkObj( Title
::makeTitle( NS_USER
, $blocker_name ), $blocker_name );
255 $blocker .= ' (' . $sk->makeLinkObj( Title
::makeTitle( NS_USER_TALK
, $blocker_name ), $wgLang->getNsText( NS_TALK
) ) . ')';
257 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
258 if( $block->mAuto
) {
259 $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
261 $target = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $block->mAddress
), $block->mAddress
);
262 $target .= ' (' . $sk->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ), $msg['contribslink'], 'target=' . urlencode( $block->mAddress
) ) . ')';
265 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
267 $properties = array();
268 if ( $block->mExpiry
=== "" ||
$block->mExpiry
=== Block
::infinity() ) {
269 $properties[] = $msg['infiniteblock'];
271 $properties[] = wfMsgReplaceArgs( $msg['expiringblock'],
272 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
274 if ( $block->mAnonOnly
) {
275 $properties[] = $msg['anononlyblock'];
277 if ( $block->mCreateAccount
) {
278 $properties[] = $msg['createaccountblock'];
280 $properties = implode( ', ', $properties );
282 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
286 if ( $wgUser->isAllowed('block') ) {
287 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Ipblocklist" );
288 $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId
) ) . ')';
290 $s .= $sk->commentBlock( $block->mReason
);
292 wfProfileOut( __METHOD__
);
297 class IPBlocklistPager
extends ReverseChronologicalPager
{
298 public $mForm, $mConds;
300 function __construct( $form, $conds = array() ) {
301 $this->mForm
= $form;
302 $this->mConds
= $conds;
303 parent
::__construct();
306 function getStartBody() {
307 wfProfileIn( __METHOD__
);
308 # Do a link batch query
309 $this->mResult
->seek( 0 );
313 while ( $row = $this->mResult->fetchObject() ) {
314 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
315 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
316 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->ipb_address ) );
317 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ipb_address ) );
320 # Usernames and titles are in fact related by a simple substitution of space -> underscore
321 # The last few lines of Title::secureAndSplit() tell the story.
322 while ( $row = $this->mResult
->fetchObject() ) {
323 $name = str_replace( ' ', '_', $row->user_name
);
324 $lb->add( NS_USER
, $name );
325 $lb->add( NS_USER_TALK
, $name );
326 $name = str_replace( ' ', '_', $row->ipb_address
);
327 $lb->add( NS_USER
, $name );
328 $lb->add( NS_USER_TALK
, $name );
331 wfProfileOut( __METHOD__
);
335 function formatRow( $row ) {
337 $block->initFromRow( $row );
338 return $this->mForm
->formatRow( $block );
341 function getQueryInfo() {
342 $conds = $this->mConds
;
343 $conds[] = 'ipb_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
344 $conds[] = 'ipb_by=user_id';
346 'tables' => array( 'ipblocks', 'user' ),
347 'fields' => $this->mDb
->tableName( 'ipblocks' ) . '.*,user_name',
352 function getIndexField() {
353 return 'ipb_timestamp';