*/
/**
+ * @param $ip part of title: Special:Ipblocklist/<ip>.
* @todo document
*/
-function wfSpecialIpblocklist() {
+function wfSpecialIpblocklist( $ip = '' ) {
global $wgUser, $wgOut, $wgRequest;
-
- $ip = trim( $wgRequest->getVal( 'wpUnblockAddress', $wgRequest->getVal( 'ip' ) ) );
+ $ip = $wgRequest->getVal( 'ip', $ip );
+ $ip = trim( $wgRequest->getVal( 'wpUnblockAddress', $ip ) );
$id = $wgRequest->getVal( 'id' );
$reason = $wgRequest->getText( 'wpUnblockReason' );
$action = $wgRequest->getText( 'action' );
$ipu = new IPUnblockForm( $ip, $id, $reason );
- if( $action == 'unblock' ) {
+ if( $action == 'unblock' || $action == 'submit' && $wgRequest->wasPosted() ) {
# Check permissions
if( !$wgUser->isAllowed( 'block' ) ) {
$wgOut->permissionRequired( 'block' );
$wgOut->readOnlyPage();
return;
}
- # Show unblock form
- $ipu->showForm( '' );
- } elseif( $action == 'submit' && $wgRequest->wasPosted()
- && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
- # Check permissions
- if( !$wgUser->isAllowed( 'block' ) ) {
- $wgOut->permissionRequired( 'block' );
- return;
+
+ # bug 15810: blocked admins should have limited access here
+ if ( $wgUser->isBlocked() ) {
+ if ( $id ) {
+ # This doesn't pick up on autoblocks, but admins
+ # should have the ipblock-exempt permission anyway
+ $block = Block::newFromID( $id );
+ $user = User::newFromName( $block->mAddress );
+ } else {
+ $user = User::newFromName( $ip );
+ }
+ $status = IPBlockForm::checkUnblockSelf( $user );
+ if ( $status !== true ) {
+ throw new ErrorPageError( 'badaccess', $status );
+ }
}
- # Check for database lock
- if( wfReadOnly() ) {
- $wgOut->readOnlyPage();
- return;
+
+ if( $action == 'unblock' ){
+ # Show unblock form
+ $ipu->showForm( '' );
+ } elseif( $action == 'submit'
+ && $wgRequest->wasPosted()
+ && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) )
+ {
+ # Remove blocks and redirect user to success page
+ $ipu->doSubmit();
}
- # Remove blocks and redirect user to success page
- $ipu->doSubmit();
+
} elseif( $action == 'success' ) {
# Inform the user of a successful unblock
# (No need to check permissions or locks here,
$this->hideuserblocks = $wgRequest->getBool( 'hideuserblocks' );
$this->hidetempblocks = $wgRequest->getBool( 'hidetempblocks' );
$this->hideaddressblocks = $wgRequest->getBool( 'hideaddressblocks' );
- $this->scanRange = $wgRequest->getBool( 'range' );
}
/**
$titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
$action = $titleObj->getLocalURL( "action=submit" );
- if ( "" != $err ) {
+ if ( $err != "" ) {
$wgOut->setSubtitle( wfMsg( "formerror" ) );
$wgOut->addWikiText( Xml::tags( 'span', array( 'class' => 'error' ), $err ) . "\n" );
}
* @return array array(message key, parameters) on failure, empty array on success
*/
- static function doUnblock(&$id, &$ip, &$reason, &$range = null) {
+ static function doUnblock(&$id, &$ip, &$reason, &$range = null, $blocker=null) {
if ( $id ) {
$block = Block::newFromID( $id );
if ( !$block ) {
if ( !$block ) {
return array('ipb_cant_unblock', htmlspecialchars($id));
}
- if( $block->mRangeStart != $block->mRangeEnd
- && !strstr( $ip, "/" ) ) {
+ if( $block->mRangeStart != $block->mRangeEnd && !strstr( $ip, "/" ) ) {
/* If the specified IP is a single address, and the block is
* a range block, don't unblock the range. */
$range = $block->mAddress;
}
// Yes, this is really necessary
$id = $block->mId;
+
+ # If the name was hidden and the blocking user cannot hide
+ # names, then don't allow any block removals...
+ if( $blocker && $block->mHideName && !$blocker->isAllowed('hideuser') ) {
+ return array('ipb_cant_unblock', htmlspecialchars($id));
+ }
# Delete block
if ( !$block->delete() ) {
return array('ipb_cant_unblock', htmlspecialchars($id));
}
+
+ # Unset _deleted fields as needed
+ if( $block->mHideName ) {
+ IPBlockForm::unsuppressUserName( $block->mAddress, $block->mUser );
+ }
# Make log entry
$log = new LogPage( 'block' );
}
function doSubmit() {
- global $wgOut;
- $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range);
- if(!empty($retval))
- {
+ global $wgOut, $wgUser;
+ $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range, $wgUser);
+ if( !empty($retval) ) {
$key = array_shift($retval);
$this->showForm(wfMsgReal($key, $retval));
return;
global $wgOut, $wgUser;
$wgOut->setPagetitle( wfMsg( "ipblocklist" ) );
- if ( "" != $msg ) {
+ if ( $msg != "" ) {
$wgOut->setSubtitle( $msg );
}
$conds = array();
$matches = array();
// Is user allowed to see all the blocks?
- if ( !$wgUser->isAllowed( 'suppress' ) )
+ if ( !$wgUser->isAllowed( 'hideuser' ) )
$conds['ipb_deleted'] = 0;
if ( $this->ip == '' ) {
// No extra conditions
$conds['ipb_id'] = substr( $this->ip, 1 );
// Single IPs
} elseif ( IP::isIPAddress($this->ip) && strpos($this->ip,'/') === false ) {
- if( $this->scanRange && $iaddr = IP::toHex($this->ip) ) {
+ if( $iaddr = IP::toHex($this->ip) ) {
# Only scan ranges which start in this /16, this improves search speed
# Blocks should not cross a /16 boundary.
$range = substr( $iaddr, 0, 4 );
- $conds[] = "(ipb_address = '" . IP::sanitizeIP($this->ip) . "') OR
- (ipb_range_start LIKE '$range%' AND ipb_range_start <= '$iaddr' AND ipb_range_end >= '$iaddr')";
+ // Fixme -- encapsulate this sort of query-building.
+ $dbr = wfGetDB( DB_SLAVE );
+ $encIp = $dbr->addQuotes( IP::sanitizeIP($this->ip) );
+ $encAddr = $dbr->addQuotes( $iaddr );
+ $conds[] = "(ipb_address = $encIp) OR
+ (ipb_range_start" . $dbr->buildLike( $range, $dbr->anyString() ) . " AND
+ ipb_range_start <= $encAddr
+ AND ipb_range_end >= $encAddr)";
} else {
$conds['ipb_address'] = IP::sanitizeIP($this->ip);
}
$conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start";
}
+ // Search form
+ $wgOut->addHTML( $this->searchForm() );
+
+ // Check for other blocks, i.e. global/tor blocks
+ $otherBlockLink = array();
+ wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockLink, $this->ip ) );
+
+ // Show additional header for the local block only when other blocks exists.
+ // Not necessary in a standard installation without such extensions enabled
+ if( count( $otherBlockLink ) ) {
+ $wgOut->addHTML(
+ Html::rawElement( 'h2', array(), wfMsg( 'ipblocklist-localblock' ) ) . "\n"
+ );
+ }
$pager = new IPBlocklistPager( $this, $conds );
if ( $pager->getNumRows() ) {
$wgOut->addHTML(
- $this->searchForm() .
- $this->showhideLinks() .
$pager->getNavigationBar() .
Xml::tags( 'ul', null, $pager->getBody() ) .
$pager->getNavigationBar()
);
} elseif ( $this->ip != '') {
- $wgOut->addHTML( $this->searchForm() );
$wgOut->addWikiMsg( 'ipblocklist-no-results' );
} else {
- $wgOut->addHTML( $this->searchForm() . $this->showhideLinks() );
$wgOut->addWikiMsg( 'ipblocklist-empty' );
}
- }
- function searchForm() {
- global $wgTitle, $wgScript, $wgRequest;
- return
- Xml::tags( 'form', array( 'action' => $wgScript ),
- Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() ) .
- Xml::openElement( 'fieldset' ) .
- Xml::element( 'legend', null, wfMsg( 'ipblocklist-legend' ) ) .
- Xml::inputLabel( wfMsg( 'ipblocklist-username' ), 'ip', 'ip', /* size */ false, $this->ip ) .
- '<br/>' .
- Xml::checkLabel( wfMsg('ipblocklist-scanrange'), 'range', 'range', $this->scanRange ) .
- ' ' . Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) .
- Xml::closeElement( 'fieldset' )
+ if( count( $otherBlockLink ) ) {
+ $wgOut->addHTML(
+ Html::rawElement( 'h2', array(), wfMsgExt( 'ipblocklist-otherblocks', 'parseinline', count( $otherBlockLink ) ) ) . "\n"
);
+ $list = '';
+ foreach( $otherBlockLink as $link ) {
+ $list .= Html::rawElement( 'li', array(), $link ) . "\n";
+ }
+ $wgOut->addHTML( Html::rawElement( 'ul', array( 'class' => 'mw-ipblocklist-otherblocks' ), $list ) . "\n" );
+ }
+
}
-
- function showhideLinks() {
+
+ function searchForm() {
+ global $wgScript, $wgRequest, $wgLang;
+
$showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
$nondefaults = array();
if( $this->hideuserblocks ) {
array( 'hidetempblocks' => 1-$this->hidetempblocks ), $nondefaults);
$sipbLink = $this->makeOptionsLink( $showhide[1-$this->hideaddressblocks],
array( 'hideaddressblocks' => 1-$this->hideaddressblocks ), $nondefaults);
-
+
$links = array();
$links[] = wfMsgHtml( 'ipblocklist-sh-userblocks', $ubLink );
$links[] = wfMsgHtml( 'ipblocklist-sh-tempblocks', $tbLink );
$links[] = wfMsgHtml( 'ipblocklist-sh-addressblocks', $sipbLink );
-
- $hl = '(' . implode( ' | ', $links ) . ')<hr/>';
- return $hl;
+ $hl = $wgLang->pipeList( $links );
+
+ return
+ Xml::tags( 'form', array( 'action' => $wgScript ),
+ Xml::hidden( 'title', SpecialPage::getTitleFor( 'Ipblocklist' )->getPrefixedDbKey() ) .
+ Xml::openElement( 'fieldset' ) .
+ Xml::element( 'legend', null, wfMsg( 'ipblocklist-legend' ) ) .
+ Xml::inputLabel( wfMsg( 'ipblocklist-username' ), 'ip', 'ip', /* size */ false, $this->ip ) .
+ ' ' .
+ Xml::submitButton( wfMsg( 'ipblocklist-submit' ) ) . '<br />' .
+ $hl .
+ Xml::closeElement( 'fieldset' )
+ );
}
-
+
/**
* Makes change an option link which carries all the other options
* @param $title see Title
function makeOptionsLink( $title, $override, $options, $active = false ) {
global $wgUser;
$sk = $wgUser->getSkin();
- $params = wfArrayMerge( $options, $override );
- $ipblocklist = SpecialPage::getTitleFor( 'IPBlockList' );
+ $params = $override + $options;
+ $ipblocklist = SpecialPage::getTitleFor( 'Ipblocklist' );
return $sk->link( $ipblocklist, htmlspecialchars( $title ),
( $active ? array( 'style'=>'font-weight: bold;' ) : array() ), $params, array( 'known' ) );
}
$sk = $wgUser->getSkin();
if( is_null( $msg ) ) {
$msg = array();
- $keys = array( 'infiniteblock', 'expiringblock', 'unblocklink',
- 'anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock', 'blocklist-nousertalk' );
+ $keys = array( 'infiniteblock', 'expiringblock', 'unblocklink', 'change-blocklink',
+ 'anononlyblock', 'createaccountblock', 'noautoblockblock', 'emailblock', 'blocklist-nousertalk', 'blocklistline' );
foreach( $keys as $key ) {
$msg[$key] = wfMsgHtml( $key );
}
- $msg['blocklistline'] = wfMsg( 'blocklistline' );
}
# Prepare links to the blocker's user and talk pages
. $sk->userToolLinks( $block->mUser, $block->mAddress, false, Linker::TOOL_LINKS_NOBLOCK );
}
- $formattedTime = $wgLang->timeanddate( $block->mTimestamp, true );
+ $formattedTime = htmlspecialchars( $wgLang->timeanddate( $block->mTimestamp, true ) );
$properties = array();
$properties[] = Block::formatExpiry( $block->mExpiry );
$properties[] = $msg['blocklist-nousertalk'];
}
- $properties = implode( ', ', $properties );
+ $properties = $wgLang->commaList( $properties );
$line = wfMsgReplaceArgs( $msg['blocklistline'], array( $formattedTime, $blocker, $target, $properties ) );
$unblocklink = '';
- if ( $wgUser->isAllowed('block') ) {
- $titleObj = SpecialPage::getTitleFor( "Ipblocklist" );
- $unblocklink = ' (' . $sk->makeKnownLinkObj($titleObj, $msg['unblocklink'], 'action=unblock&id=' . urlencode( $block->mId ) ) . ')';
+ $changeblocklink = '';
+ $toolLinks = '';
+ if ( $wgUser->isAllowed( 'block' ) ) {
+ $unblocklink = $sk->link( SpecialPage::getTitleFor( 'Ipblocklist' ),
+ $msg['unblocklink'],
+ array(),
+ array( 'action' => 'unblock', 'id' => $block->mId ),
+ 'known' );
+
+ # Create changeblocklink for all blocks with exception of autoblocks
+ if( !$block->mAuto ) {
+ $changeblocklink = wfMsgExt( 'pipe-separator', 'escapenoentities' ) .
+ $sk->link( SpecialPage::getTitleFor( 'Blockip', $block->mAddress ),
+ $msg['change-blocklink'],
+ array(), array(), 'known' );
+ }
+ $toolLinks = "($unblocklink$changeblocklink)";
}
- $comment = $sk->commentBlock( $block->mReason );
+ $comment = $sk->commentBlock( htmlspecialchars($block->mReason) );
$s = "{$line} $comment";
if ( $block->mHideName )
$s = '<span class="history-deleted">' . $s . '</span>';
wfProfileOut( __METHOD__ );
- return "<li>$s $unblocklink</li>\n";
+ return "<li>$s $toolLinks</li>\n";
}
}