diff options
Diffstat (limited to 'includes/specials/SpecialBlockip.php')
-rw-r--r-- | includes/specials/SpecialBlockip.php | 195 |
1 files changed, 170 insertions, 25 deletions
diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index 52829d92..4d82997f 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -47,7 +47,7 @@ class IPBlockForm { # var $BlockEmail; function IPBlockForm( $par ) { - global $wgRequest, $wgUser; + global $wgRequest, $wgUser, $wgBlockAllowsUTEdit; $this->BlockAddress = $wgRequest->getVal( 'wpBlockAddress', $wgRequest->getVal( 'ip', $par ) ); $this->BlockAddress = strtr( $this->BlockAddress, '_', ' ' ); @@ -66,6 +66,8 @@ class IPBlockForm { $this->BlockWatchUser = $wgRequest->getBool( 'wpWatchUser', false ); # Re-check user's rights to hide names, very serious, defaults to 0 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0; + $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit ); + $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false ); } function showForm( $err ) { @@ -85,10 +87,26 @@ class IPBlockForm { $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' ); $titleObj = SpecialPage::getTitleFor( 'Blockip' ); - - if ( "" != $err ) { + $user = User::newFromName( $this->BlockAddress ); + + $alreadyBlocked = false; + if ( $err && $err[0] != 'ipb_already_blocked' ) { + $key = array_shift($err); + $msg = wfMsgReal($key, $err); $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); - $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) ); + $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) ); + } elseif ( $this->BlockAddress ) { + $userId = 0; + if ( is_object( $user ) ) + $userId = $user->getId(); + $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); + if ( !is_null($currentBlock) && !$currentBlock->mAuto && # The block exists and isn't an autoblock + ( $currentBlock->mRangeStart == $currentBlock->mRangeEnd || # The block isn't a rangeblock + # or if it is, the range is what we're about to block + ( $currentBlock->mAddress == $this->BlockAddress ) ) ) { + $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress ); + $alreadyBlocked = true; + } } $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' ); @@ -108,7 +126,7 @@ class IPBlockForm { $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', wfMsgForContent( 'ipbreason-dropdown' ), - wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 ); + wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 ); global $wgStylePath, $wgStyleVersion; $wgOut->addHTML( @@ -201,7 +219,7 @@ class IPBlockForm { </tr>" ); - global $wgSysopEmailBans; + global $wgSysopEmailBans, $wgBlockAllowsUTEdit; if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) { $wgOut->addHTML(" <tr id='wpEnableEmailBan'> @@ -240,25 +258,37 @@ class IPBlockForm { </td> </tr>" ); + if( $wgBlockAllowsUTEdit ){ + $wgOut->addHTML(" + <tr id='wpAllowUsertalkRow'> + <td> </td> + <td class='mw-input'>" . + Xml::checkLabel( wfMsg( 'ipballowusertalk' ), + 'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk, + array( 'tabindex' => '12' ) ) . " + </td> + </tr>" + ); + } $wgOut->addHTML(" <tr> <td style='padding-top: 1em'> </td> <td class='mw-submit' style='padding-top: 1em'>" . - Xml::submitButton( wfMsg( 'ipbsubmit' ), - array( 'name' => 'wpBlock', 'tabindex' => '12' ) ) . " + Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ), + array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . " </td> </tr>" . Xml::closeElement( 'table' ) . Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . + ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) . Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) . Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n" ); - $wgOut->addHtml( $this->getConvenienceLinks() ); + $wgOut->addHTML( $this->getConvenienceLinks() ); - $user = User::newFromName( $this->BlockAddress ); if( is_object( $user ) ) { $this->showLogFragment( $wgOut, $user->getUserPage() ); } elseif( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $this->BlockAddress ) ) { @@ -273,9 +303,8 @@ class IPBlockForm { * $userID and $expiry will be filled accordingly * @return array(message key, arguments) on failure, empty array on success */ - function doBlock(&$userId = null, &$expiry = null) - { - global $wgUser, $wgSysopUserBans, $wgSysopRangeBans; + function doBlock( &$userId = null, &$expiry = null ) { + global $wgUser, $wgSysopUserBans, $wgSysopRangeBans, $wgBlockAllowsUTEdit; $userId = 0; # Expand valid IPv6 addresses, usernames are left as is @@ -327,8 +356,12 @@ class IPBlockForm { } } + if ( $wgUser->isBlocked() && ( $wgUser->getId() !== $userId ) ) { + return array( 'cant-block-while-blocked' ); + } + $reasonstr = $this->BlockReasonList; - if ( $reasonstr != 'other' && $this->BlockReason != '') { + if ( $reasonstr != 'other' && $this->BlockReason != '' ) { // Entry from drop down menu + additional comment $reasonstr .= ': ' . $this->BlockReason; } elseif ( $reasonstr == 'other' ) { @@ -339,7 +372,7 @@ class IPBlockForm { if( $expirestr == 'other' ) $expirestr = $this->BlockOther; - if ((strlen($expirestr) == 0) || (strlen($expirestr) > 50)) { + if ( ( strlen( $expirestr ) == 0) || ( strlen( $expirestr ) > 50) ) { return array('ipb_expiry_invalid'); } @@ -358,14 +391,27 @@ class IPBlockForm { $block = new Block( $this->BlockAddress, $userId, $wgUser->getId(), $reasonstr, wfTimestampNow(), 0, $expiry, $this->BlockAnonOnly, $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, - $this->BlockEmail ); + $this->BlockEmail, isset( $this->BlockAllowUsertalk ) ? $this->BlockAllowUsertalk : $wgBlockAllowsUTEdit ); if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) { if ( !$block->insert() ) { - return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress)); + if ( !$this->BlockReblock ) { + return array( 'ipb_already_blocked' ); + } else { + # This returns direct blocks before autoblocks/rangeblocks, since we should + # be sure the user is blocked by now it should work for our purposes + $currentBlock = Block::newFromDB( $this->BlockAddress, $userId ); + if( $block->equals( $currentBlock ) ) { + return array( 'ipb_already_blocked' ); + } + $currentBlock->delete(); + $block->insert(); + $log_action = 'reblock'; + } + } else { + $log_action = 'block'; } - wfRunHooks('BlockIpComplete', array($block, $wgUser)); if ( $this->BlockWatchUser ) { @@ -380,7 +426,7 @@ class IPBlockForm { # Make log entry, if the name is hidden, put it in the oversight log $log_type = ($this->BlockHideName) ? 'suppress' : 'block'; $log = new LogPage( $log_type ); - $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), + $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ), $reasonstr, $logParams ); # Report to the user @@ -404,8 +450,7 @@ class IPBlockForm { urlencode( $this->BlockAddress ) ) ); return; } - $key = array_shift($retval); - $this->showForm(wfMsgReal($key, $retval)); + $this->showForm( $retval ); } function showSuccess() { @@ -414,12 +459,22 @@ class IPBlockForm { $wgOut->setPagetitle( wfMsg( 'blockip' ) ); $wgOut->setSubtitle( wfMsg( 'blockipsuccesssub' ) ); $text = wfMsgExt( 'blockipsuccesstext', array( 'parse' ), $this->BlockAddress ); - $wgOut->addHtml( $text ); + $wgOut->addHTML( $text ); } function showLogFragment( $out, $title ) { - $out->addHtml( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) ); - LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText() ); + global $wgUser; + $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'block' ) ) ); + $count = LogEventsList::showLogExtract( $out, 'block', $title->getPrefixedText(), '', 10 ); + if($count > 10){ + $out->addHTML( $wgUser->getSkin()->link( + SpecialPage::getTitleFor( 'Log' ), + wfMsgHtml( 'blocklog-fulllog' ), + array(), + array( + 'type' => 'block', + 'page' => $title->getPrefixedText() ) ) ); + } } /** @@ -429,6 +484,7 @@ class IPBlockForm { * @return array */ private function blockLogFlags() { + global $wgBlockAllowsUTEdit; $flags = array(); if( $this->BlockAnonOnly && IP::isIPAddress( $this->BlockAddress ) ) // when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log @@ -439,6 +495,8 @@ class IPBlockForm { $flags[] = 'noautoblock'; if ( $this->BlockEmail ) $flags[] = 'noemail'; + if ( !$this->BlockAllowUsertalk && $wgBlockAllowsUTEdit ) + $flags[] = 'nousertalk'; return implode( ',', $flags ); } @@ -450,11 +508,25 @@ class IPBlockForm { private function getConvenienceLinks() { global $wgUser; $skin = $wgUser->getSkin(); - $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) ); + if( $this->BlockAddress ) + $links[] = $this->getContribsLink( $skin ); $links[] = $this->getUnblockLink( $skin ); $links[] = $this->getBlockListLink( $skin ); + $links[] = $skin->makeLink ( 'MediaWiki:Ipbreason-dropdown', wfMsgHtml( 'ipb-edit-dropdown' ) ); return '<p class="mw-ipb-conveniencelinks">' . implode( ' | ', $links ) . '</p>'; } + + /** + * Build a convenient link to a user or IP's contribs + * form + * + * @param $skin Skin to use + * @return string + */ + private function getContribsLink( $skin ) { + $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->BlockAddress ); + return $skin->link( $contribsPage, wfMsgHtml( 'ipb-blocklist-contribs', $this->BlockAddress ) ); + } /** * Build a convenient link to unblock the given username or IP @@ -491,4 +563,77 @@ class IPBlockForm { return $skin->makeKnownLinkObj( $list, wfMsgHtml( 'ipb-blocklist' ) ); } } + + /** + * Block a list of selected users + * @param array $users + * @param string $reason + * @param string $tag replaces user pages + * @param string $talkTag replaces user talk pages + * @returns array, list of html-safe usernames + */ + public static function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) { + global $wgUser; + $counter = $blockSize = 0; + $safeUsers = array(); + $log = new LogPage( 'block' ); + foreach( $users as $name ) { + # Enforce limits + $counter++; + $blockSize++; + # Lets not go *too* fast + if( $blockSize >= 20 ) { + $blockSize = 0; + wfWaitForSlaves( 5 ); + } + $u = User::newFromName( $name, false ); + // If user doesn't exist, it ought to be an IP then + if( is_null($u) || (!$u->getId() && !IP::isIPAddress( $u->getName() )) ) { + continue; + } + $userTitle = $u->getUserPage(); + $userTalkTitle = $u->getTalkPage(); + $userpage = new Article( $userTitle ); + $usertalk = new Article( $userTalkTitle ); + $safeUsers[] = '[[' . $userTitle->getPrefixedText() . '|' . $userTitle->getText() . ']]'; + $expirestr = $u->getId() ? 'indefinite' : '1 week'; + $expiry = Block::parseExpiryInput( $expirestr ); + $anonOnly = IP::isIPAddress( $u->getName() ) ? 1 : 0; + // Create the block + $block = new Block( $u->getName(), // victim + $u->getId(), // uid + $wgUser->getId(), // blocker + $reason, // comment + wfTimestampNow(), // block time + 0, // auto ? + $expiry, // duration + $anonOnly, // anononly? + 1, // block account creation? + 1, // autoblocking? + 0, // suppress name? + 0 // block from sending email? + ); + $oldblock = Block::newFromDB( $u->getName(), $u->getId() ); + if( !$oldblock ) { + $block->insert(); + # Prepare log parameters + $logParams = array(); + $logParams[] = $expirestr; + if( $anonOnly ) { + $logParams[] = 'anononly'; + } + $logParams[] = 'nocreate'; + # Add log entry + $log->addEntry( 'block', $userTitle, $reason, $logParams ); + } + # Tag userpage! (check length to avoid mistakes) + if( strlen($tag) > 2 ) { + $userpage->doEdit( $tag, $reason, EDIT_MINOR ); + } + if( strlen($talkTag) > 2 ) { + $usertalk->doEdit( $talkTag, $reason, EDIT_MINOR ); + } + } + return $safeUsers; + } } |