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 = SpecialPage
::getTitleFor( "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 = SpecialPage
::getTitleFor( "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();
171 if ( $this->ip
== '' ) {
172 // No extra conditions
173 } elseif ( substr( $this->ip
, 0, 1 ) == '#' ) {
174 $conds['ipb_id'] = substr( $this->ip
, 1 );
175 } elseif ( IP
::toUnsigned( $this->ip
) !== false ) {
176 $conds['ipb_address'] = $this->ip
;
177 $conds['ipb_auto'] = 0;
178 } elseif( preg_match( '/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\\/(\\d{1,2})$/', $this->ip
, $matches ) ) {
179 $conds['ipb_address'] = Block
::normaliseRange( $this->ip
);
180 $conds['ipb_auto'] = 0;
182 $user = User
::newFromName( $this->ip
);
183 if ( $user && ( $id = $user->getID() ) != 0 ) {
184 $conds['ipb_user'] = $id;
187 $conds['ipb_address'] = $this->ip
;
188 $conds['ipb_auto'] = 0;
192 $pager = new IPBlocklistPager( $this, $conds );
193 $s = $pager->getNavigationBar() .
195 if ( $pager->getNumRows() ) {
200 $s .= '<p>' . wfMsgHTML( 'ipblocklistempty' ) . '</p>';
202 $s .= $pager->getNavigationBar();
203 $wgOut->addHTML( $s );
206 function searchForm() {
207 global $wgTitle, $wgScript, $wgRequest;
209 wfElement( 'form', array(
210 'action' => $wgScript ),
212 wfHidden( 'title', $wgTitle->getPrefixedDbKey() ) .
213 wfElement( 'input', array(
216 'value' => 'search' ) ).
217 wfElement( 'input', array(
220 'value' => $wgRequest->getText( 'limit' ) ) ) .
221 wfElement( 'input', array(
223 'value' => $this->ip
) ) .
224 wfElement( 'input', array(
226 'value' => wfMsg( 'searchbutton' ) ) ) .
231 * Callback function to output a block
233 function formatRow( $block ) {
234 global $wgUser, $wgLang;
236 wfProfileIn( __METHOD__
);
238 static $sk=null, $msg=null;
241 $sk = $wgUser->getSkin();
242 if( is_null( $msg ) ) {
244 $keys = array( 'infiniteblock', 'expiringblock', 'contribslink', 'unblocklink',
245 'anononlyblock', 'createaccountblock', 'noautoblockblock' );
246 foreach( $keys as $key ) {
247 $msg[$key] = wfMsgHtml( $key );
249 $msg['blocklistline'] = wfMsg( 'blocklistline' );
250 $msg['contribslink'] = wfMsg( 'contribslink' );
253 # Prepare links to the blocker's user and talk pages
254 $blocker_id = $block->getBy();
255 $blocker_name = $block->getByName();
256 $blocker = $sk->userLink( $blocker_id, $blocker_name );
257 $blocker .= $sk->userToolLinks( $blocker_id, $blocker_name );
259 # Prepare links to the block target's user and contribs. pages (as applicable, don't do it for autoblocks)
260 if( $block->mAuto
) {
261 $target = $block->getRedactedName(); # Hide the IP addresses of auto-blocks; privacy
263 $target = $sk->makeLinkObj( Title
::makeTitle( NS_USER
, $block->mAddress
), $block->mAddress
);
264 $target .= ' (' . $sk->makeKnownLinkObj( SpecialPage
::getSafeTitleFor( 'Contributions', $block->mAddress
), $msg['contribslink'] ) . ')';
267 $formattedTime = $wgLang->timeanddate( $block->mTimestamp
, true );
269 $properties = array();
270 if ( $block->mExpiry
=== "" ||
$block->mExpiry
=== Block
::infinity() ) {
271 $properties[] = $msg['infiniteblock'];
273 $properties[] = wfMsgReplaceArgs( $msg['expiringblock'],
274 array( $wgLang->timeanddate( $block->mExpiry
, true ) ) );
276 if ( $block->mAnonOnly
) {
277 $properties[] = $msg['anononlyblock'];
279 if ( $block->mCreateAccount
) {
280 $properties[] = $msg['createaccountblock'];
282 if (!$block->mEnableAutoblock
&& $block->mUser
) {
283 $properties[] = $msg['noautoblockblock'];
286 $properties = implode( ', ', $properties );
288 $line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
292 if ( $wgUser->isAllowed('block') ) {
293 $titleObj = SpecialPage
::getTitleFor( "Ipblocklist" );
294 $s .= ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId
) ) . ')';
296 $s .= $sk->commentBlock( $block->mReason
);
298 wfProfileOut( __METHOD__
);
303 class IPBlocklistPager
extends ReverseChronologicalPager
{
304 public $mForm, $mConds;
306 function __construct( $form, $conds = array() ) {
307 $this->mForm
= $form;
308 $this->mConds
= $conds;
309 parent
::__construct();
312 function getStartBody() {
313 wfProfileIn( __METHOD__
);
314 # Do a link batch query
315 $this->mResult
->seek( 0 );
319 while ( $row = $this->mResult->fetchObject() ) {
320 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
321 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
322 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->ipb_address ) );
323 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->ipb_address ) );
326 # Usernames and titles are in fact related by a simple substitution of space -> underscore
327 # The last few lines of Title::secureAndSplit() tell the story.
328 while ( $row = $this->mResult
->fetchObject() ) {
329 $name = str_replace( ' ', '_', $row->user_name
);
330 $lb->add( NS_USER
, $name );
331 $lb->add( NS_USER_TALK
, $name );
332 $name = str_replace( ' ', '_', $row->ipb_address
);
333 $lb->add( NS_USER
, $name );
334 $lb->add( NS_USER_TALK
, $name );
337 wfProfileOut( __METHOD__
);
341 function formatRow( $row ) {
343 $block->initFromRow( $row );
344 return $this->mForm
->formatRow( $block );
347 function getQueryInfo() {
348 $conds = $this->mConds
;
349 $conds[] = 'ipb_expiry>' . $this->mDb
->addQuotes( $this->mDb
->timestamp() );
350 $conds[] = 'ipb_by=user_id';
352 'tables' => array( 'ipblocks', 'user' ),
353 'fields' => $this->mDb
->tableName( 'ipblocks' ) . '.*,user_name',
358 function getIndexField() {
359 return 'ipb_timestamp';