
werdna at svn
May 23, 2008, 9:02 PM
Post #1 of 1
(92 views)
Permalink
|
|
SVN: [35272] trunk/extensions/GlobalBlocking
|
|
Revision: 35272 Author: werdna Date: 2008-05-24 04:02:32 +0000 (Sat, 24 May 2008) Log Message: ----------- Globalblocking updates: * Support range-blocking. * Use split-off formatExpiry and parseExpiryInput functions. * Deprecate GlobalBlocking::buildForm. * Display wiki name, not DB name if centralauth is installed. * Link to blocker's user page if centralauth is installed. * Use getText() instead of getVal() for loading parameters. * Normalise ranges for searching, unblocking etc. * Do searches as GET parameters, makes linking better. * Code quality/readability. * Standardise presentation of expiry with regular blocks. * When blocking, check for expired blocks before checking for duplicate blocks. * Make fields bigger. * Fix missing message. Modified Paths: -------------- trunk/extensions/GlobalBlocking/GlobalBlocking.i18n.php trunk/extensions/GlobalBlocking/GlobalBlocking.php trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php Modified: trunk/extensions/GlobalBlocking/GlobalBlocking.i18n.php =================================================================== --- trunk/extensions/GlobalBlocking/GlobalBlocking.i18n.php 2008-05-24 03:51:10 UTC (rev 35271) +++ trunk/extensions/GlobalBlocking/GlobalBlocking.i18n.php 2008-05-24 04:02:32 UTC (rev 35272) @@ -30,6 +30,8 @@ You may wish to consult the [[Special:Globalblocklist|list of global blocks]].', 'globalblocking-block-successsub' => 'Global block successful', 'globalblocking-block-alreadyblocked' => 'The IP address $1 is already blocked globally. You can view the existing block on the [[Special:Globalblocklist|list of global blocks]].', + 'globalblocking-block-bigrange' => 'The range you specified ($1) is too big to block. You may block, at most, 65,536 addresses (/16 ranges)', + 'globalblocking-list' => 'List of globally blocked IP addresses', 'globalblocking-search-legend' => 'Search for a global block', 'globalblocking-search-ip' => 'IP Address:', @@ -40,7 +42,7 @@ 'globalblocking-list-blockitem' => "$1: '''$2''' (''$3'') globally blocked '''[[Special:Contributions/$4|$4]]''' ''($5)''", 'globalblocking-list-expiry' => 'expiry $1', 'globalblocking-list-anononly' => 'anon-only', - 'globalblocking-list-unblock' => 'unblock', + 'globalblocking-list-unblock' => 'remove', 'globalblocking-list-whitelisted' => 'locally disabled by $1: $2', 'globalblocking-list-whitelist' => 'local status', @@ -53,6 +55,7 @@ 'globalblocking-unblock-unblocked' => "You have successfully removed the global block #$2 on the IP address '''$1'''", 'globalblocking-unblock-errors' => "You cannot remove a global block for that IP address, because:\n\$1", 'globalblocking-unblock-successsub' => 'Global block successfully removed', + 'globalblocking-unblock-subtitle' => 'Removing global block', 'globalblocking-whitelist-subtitle' => 'Editing the local status of a global block', 'globalblocking-whitelist-legend' => 'Change local status', Modified: trunk/extensions/GlobalBlocking/GlobalBlocking.php =================================================================== --- trunk/extensions/GlobalBlocking/GlobalBlocking.php 2008-05-24 03:51:10 UTC (rev 35271) +++ trunk/extensions/GlobalBlocking/GlobalBlocking.php 2008-05-24 04:02:32 UTC (rev 35272) @@ -76,8 +76,15 @@ global $wgUser; $dbr = GlobalBlocking::getGlobalBlockingSlave(); $ip = wfGetIp(); + + $hex_ip = IP::toHex( $ip ); + + $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother checking blocks out of this /16. - $conds = array( 'gb_address' => $ip, 'gb_timestamp<'.$dbr->addQuotes($dbr->timestamp(wfTimestampNow())) ); + $conds = array( 'gb_range_end>='.$dbr->addQuotes($hex_ip), // This block in the given range. + 'gb_range_start<='.$dbr->addQuotes($hex_ip), + 'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ), + 'gb_expiry>'.$dbr->addQuotes($dbr->timestamp(wfTimestampNow())) ); if (!$wgUser->isAnon()) $conds['gb_anon_only'] = 0; @@ -91,17 +98,14 @@ return true; } - $expiry = Block::decodeExpiry( $block->gb_expiry ); - if ($expiry == 'infinity') { - $expiry = wfMsg( 'infiniteblock' ); - } else { - global $wgLang; - $expiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $expiry ), true ); - } + $expiry = Block::formatExpiry( $block->gb_expiry ); wfLoadExtensionMessages( 'GlobalBlocking' ); - $result[] = array('globalblocking-blocked', $block->gb_by, $block->gb_by_wiki, $block->gb_reason, $expiry); + $display_wiki = self::getWikiName( $block->gb_by_wiki ); + $user_display = self::maybeLinkUserpage( $block->gb_by_wiki, $block->gb_by ); + + $result[] = array('globalblocking-blocked', $user_display, $display_wiki, $block->gb_reason, $expirystr); return false; } @@ -118,10 +122,6 @@ return wfGetDB( DB_SLAVE, 'globalblocking', $wgGlobalBlockingDatabase ); } - static function buildForm( $fields, $submitLabel ) { - return wfBuildForm( $fields, $submitLabel ); - } - static function getGlobalBlockId( $ip ) { $dbr = GlobalBlocking::getGlobalBlockingSlave(); @@ -176,4 +176,24 @@ return array( 'user' => $row->gbw_by, 'reason' => $row->gbw_reason ); } } + + static function getWikiName( $wiki_id ) { + if (class_exists('WikiMap')) { + // We can give more info than just the wiki id! + $wiki = WikiMap::getWiki( $wiki_id ); + + return $wiki->getDisplayName(); + } + + return $wiki_id; + } + + static function maybeLinkUserpage( $wiki_id, $user ) { + if (class_exists( 'WikiMap')) { + $wiki = WikiMap::getWiki( $wiki_id ); + + return "[".$wiki->getUrl( "User:$user" )." $user]"; + } + return $user; + } } Modified: trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php =================================================================== --- trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php 2008-05-24 03:51:10 UTC (rev 35271) +++ trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php 2008-05-24 04:02:32 UTC (rev 35272) @@ -30,11 +30,17 @@ if ($wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ))) { // They want to submit. Let's have a look. $errors = $this->trySubmit(); + return; } $errorstr = ''; + + if (is_array($errors) && count($errors)>0) + $hasErrors = true; + else + $hasErrors = false; - if (!is_array($errors) || count($errors)>0) { + if ($hasErrors) { if (is_array($errors)) { foreach ( $errors as $error ) { $errorstr .= '* ' . call_user_func_array('wfMsgHtml', $error)."\n"; @@ -42,19 +48,19 @@ $errorstr = wfMsgExt( 'globalblocking-block-errors', array( 'parse'), $errorstr ); } - - $wgOut->addHtml( $this->buildForm( $errorstr ) ); } + + $wgOut->addHtml( $this->buildForm( $errorstr ) ); } function loadParameters() { global $wgRequest; - $this->mAddress = $wgRequest->getVal( 'wpAddress' ); - $this->mReason = $wgRequest->getVal( 'wpReason' ); - $this->mExpiry = $this->mExpirySelection = $wgRequest->getVal( 'wpExpiry' ); + $this->mAddress = $wgRequest->getText( 'wpAddress' ); + $this->mReason = $wgRequest->getText( 'wpReason' ); + $this->mExpiry = $this->mExpirySelection = $wgRequest->getText( 'wpExpiry' ); if ($this->mExpiry == 'other') { - $this->mExpiry = $wgRequest->getVal( wpExpiryOther ); + $this->mExpiry = $wgRequest->getText( 'wpExpiryOther' ); } $this->mAnonOnly = $wgRequest->getCheck( 'wpAnonOnly' ); } @@ -62,37 +68,46 @@ function trySubmit() { global $wgUser,$wgDBname,$wgOut; $errors = array(); + + ## Purge expired blocks. + GlobalBlocking::purgeExpired(); ## Validate input $ip = IP::sanitizeIP( $this->mAddress ); - if (!(IP::isIPv4( $ip ) || IP::isIPv6($ip))) { + if (!IP::isIPAddress($ip)) { // Invalid IP address. $errors[] = array( 'globalblocking-block-ipinvalid', $ip ); } - $expiry = $this->mExpiry; // Already checked for 'other' expiry in loadParameters. - - if ($expiry == 'infinite' || $expiry == 'indefinite') { - $expiry = 'infinity'; - } else { - $expiry = strtotime( $expiry); - if ($expiry < 0 || $expiry === false) { - $errors[] = array( 'globalblocking-block-expiryinvalid', $this->mExpiry ); - } + $expirestr = $this->mExpiry; // Already checked for 'other' expiry in loadParameters. + + if ( false === (Block::parseExpiryInput($expirestr))) { + $errors[] = array( 'globalblocking-block-expiryinvalid', $this->mExpiry ); } if (GlobalBlocking::getGlobalBlockId($ip)) { $errors[] = array( 'globalblocking-block-alreadyblocked', $ip ); } - + + // Check for too-big ranges. + list( $range_start, $range_end ) = IP::parseRange( $ip ); + + if (substr( $range_start, 0, 4 ) != substr( $range_end, 0, 4 )) { + // Range crosses a /16 boundary. + $errors[] = array( 'globalblocking-block-bigrange', $ip ); + } + + // Normalise the range + if ($range_start != $range_end) { + $ip = Block::normaliseRange( $ip ); + } + if (count($errors)>0) return $errors; // We're a-ok. $dbw = GlobalBlocking::getGlobalBlockingMaster(); - - GlobalBlocking::purgeExpired(); $row = array(); $row['gb_address'] = $ip; @@ -102,8 +117,7 @@ $row['gb_timestamp'] = $dbw->timestamp(wfTimestampNow()); $row['gb_anon_only'] = $this->mAnonOnly; $row['gb_expiry'] = Block::encodeExpiry($expiry, $dbw); - $row['gb_range_start'] = 0; - $row['gb_range_end'] = 0; + list( $row['gb_range_start'], $row['gb_range_end'] ) = array( $range_start, $range_end ); $dbw->insert( 'globalblocks', $row, __METHOD__ ); @@ -144,25 +158,25 @@ $fields = array (); // Who to block - $fields['ipaddress'] = wfInput( 'wpAddress', false, $this->mAddress ); + $fields['ipaddress'] = wfInput( 'wpAddress', 45, $this->mAddress ); // Why to block them - $fields['globalblocking-block-reason'] = wfInput( 'wpReason', false, $this->mReason ); + $fields['globalblocking-block-reason'] = wfInput( 'wpReason', 45, $this->mReason ); // How long to block them for if ( wfMsg( 'globalblocking-expiry-options' ) != '-') { # Drop-down list $fields['globalblocking-block-expiry'] = $this->buildExpirySelector( 'wpExpiry', 'wpExpiry', $this->mExpirySelection ); - $fields['globalblocking-block-expiry-otherfield'] = wfInput( 'wpExpiryOther', false, $this->mExpiry == $this->mExpirySelection ? '' : $this->mExpiry ); + $fields['globalblocking-block-expiry-otherfield'] = wfInput( 'wpExpiryOther', 45, $this->mExpiry == $this->mExpirySelection ? '' : $this->mExpiry ); } else { - $fields['globalblocking-block-expiry'] = wfInput( 'wpExpiry', $this->mExpiry ); + $fields['globalblocking-block-expiry'] = wfInput( 'wpExpiry', 45, $this->mExpiry ); } // Block all users, or just anonymous ones $fields['globalblocking-block-options'] = wfCheckLabel( wfMsg( 'ipbanononly' ), 'wpAnonOnly', 'wpAnonOnly', $this->mAnonOnly ); // Build a form. - $form .= GlobalBlocking::buildForm( $fields, 'globalblocking-block-submit' ); + $form .= wfBuildForm( $fields, 'globalblocking-block-submit' ); $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); @@ -185,7 +199,7 @@ if ($id == null) { $id = $name; } if ($selected == null) { $selected = 'other'; } - $attribs = array( 'id' => $id, 'name' => $name, 'onchange' => 'considerChangingExpiryFocus()' ); + $attribs = array( 'id' => $id, 'name' => $name, 'onchange' => 'considerChangingExpiryFocus()', 'size' => 45 ); $selector .= Xml::openElement( 'select', $attribs ); Modified: trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php =================================================================== --- trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php 2008-05-24 03:51:10 UTC (rev 35271) +++ trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php 2008-05-24 04:02:32 UTC (rev 35272) @@ -36,7 +36,7 @@ // Validate search IP $ip = $this->mSearchIP; - if (!(IP::isIPv4($ip) || IP::isIPv6($ip)) && strlen($ip)) { + if (!IP::isIPAddress($ip) && strlen($ip)) { $errors[] = array('globalblocking-list-ipinvalid',$ip); $ip = ''; } @@ -47,13 +47,13 @@ $searchForm = ''; $searchForm .= Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'globalblocking-search-legend' ) ); - $searchForm .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'globalblocklist-search' ) ); + $searchForm .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'name' => 'globalblocklist-search' ) ); $searchForm .= Xml::hidden( 'title', SpecialPage::getTitleFor('GlobalBlockList')->getPrefixedText() ); if (count($errors)>0) { $errorstr = ''; foreach ( $errors as $error ) { - $errorstr .= '* ' . call_user_func_array('wfMsgHtml', $error)."\n"; + $errorstr .= '* ' . call_user_func_array('wfMsg', $error)."\n"; } $searchForm .= Xml::openElement( 'div', array( 'class' => 'error' ) ) . @@ -61,8 +61,8 @@ } $fields = array(); - $fields['globalblocking-search-ip'] = wfInput( 'wpSearchIP', false, $ip ); - $searchForm .= GlobalBlocking::buildForm( $fields, 'globalblocking-search-submit' ); + $fields['globalblocking-search-ip'] = wfInput( 'wpSearchIP', 45, $ip ); + $searchForm .= wfBuildForm( $fields, 'globalblocking-search-submit' ); $searchForm .= Xml::hidden( 'wpSearch', 1 ); $searchForm .= Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ); @@ -83,15 +83,24 @@ function loadParameters() { global $wgRequest,$wgUser; - $this->mSearchIP = $wgRequest->getVal( 'wpSearchIP' ); - $this->mSearch = $wgRequest->getCheck( 'wpSearch' ); - $this->mAction = $wgRequest->getVal( 'action', 'list' ); - $this->mUnblockIP = $wgRequest->getVal( 'unblockip' ); - $this->mWhitelistIP = $wgRequest->getVal( 'whitelistip' ); + #$this->mSearchIP = $wgRequest->geText( 'wpSearchIP' ); + $this->mSearch = $wgRequest->getText( 'wpSearch' ); + $this->mAction = $wgRequest->getText( 'action', 'list' ); + #$this->mUnblockIP = $wgRequest->getText( 'unblockip' ); + #$this->mWhitelistIP = $wgRequest->getVal( 'whitelistip' ); $this->mWhitelistID = $wgRequest->getVal( 'whitelistid' ); - $this->mWhitelistStatus = $wgRequest->getVal( 'wpWhitelistStatus' ); - $this->mEditToken = $wgRequest->getVal( 'wpEditToken' ); - $this->mReason = $wgRequest->getVal( 'wpReason' ); + $this->mWhitelistStatus = $wgRequest->getCheck( 'wpWhitelistStatus' ); + $this->mEditToken = $wgRequest->getText( 'wpEditToken' ); + $this->mReason = $wgRequest->getText( 'wpReason' ); + + // Normalise ranges if necessary. + $normalise_fields = array( 'mWhitelistIP' => 'whitelistip', 'mUnblockIP' => 'unblockip', 'mSearchIP' => 'wpSearchIP' ); + + foreach( $normalise_fields as $object_field => $post_field ) { + $ip = $wgRequest->getText( $post_field ); + + $this->$object_field = Block::normaliseRange( $ip ); + } } function whitelistForm() { @@ -124,11 +133,11 @@ $fields = array(); - $fields['ipaddress'] = wfInput( 'whitelistip', false, $this->mWhitelistIP, array( 'readonly' => 'readonly' ) ); - $fields['globalblocking-whitelist-reason'] = wfInput( 'wpReason', false, $this->mReason ); + $fields['ipaddress'] = wfInput( 'whitelistip', 45, $this->mWhitelistIP, array( 'readonly' => 'readonly' ) ); + $fields['globalblocking-whitelist-reason'] = wfInput( 'wpReason', 45, $this->mReason ); $fields['globalblocking-whitelist-status'] = Xml::checkLabel( wfMsgExt( 'globalblocking-whitelist-statuslabel', 'parsemag' ), 'wpWhitelistStatus', 'wpWhitelistStatus', $cur_status ); - $form .= GlobalBlocking::buildForm( $fields, 'globalblocking-whitelist-submit' ); + $form .= wfBuildForm( $fields, 'globalblocking-whitelist-submit' ); $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); @@ -197,14 +206,14 @@ return; } - $wgOut->setSubTitle( wfMsg( 'globalblocking-unblockform-subtitle' ) ); + $wgOut->setSubTitle( wfMsg( 'globalblocking-unblock-subtitle' ) ); $form = ''; if (count($errors)>0) { $errorstr = ''; foreach ( $errors as $error ) { - $errorstr .= '* ' . call_user_func_array('wfMsgHtml', $error)."\n"; + $errorstr .= '* ' . call_user_func_array('wfMsg', $error)."\n"; } $form .= Xml::openElement( 'div', array( 'class' => 'error' ) ) . @@ -219,10 +228,10 @@ $fields = array(); - $fields['ipaddress'] = wfInput( 'unblockip', false, $this->mUnblockIP ); - $fields['globalblocking-unblock-reason'] = wfInput( 'wpReason', false, $this->mReason ); + $fields['ipaddress'] = wfInput( 'unblockip', 45, $this->mUnblockIP ); + $fields['globalblocking-unblock-reason'] = wfInput( 'wpReason', 45, $this->mReason ); - $form .= GlobalBlocking::buildForm( $fields, 'globalblocking-unblock-submit' ); + $form .= wfBuildForm( $fields, 'globalblocking-unblock-submit' ); $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ); @@ -236,7 +245,7 @@ global $wgOut,$wgUser; $errors = array(); $ip = $this->mUnblockIP; - if (!(IP::isIPv4($ip) || IP::isIPv6($ip)) && strlen($ip)) { + if (!IP::isIPAddress($ip) && strlen($ip)) { $errors[] = array('globalblocking-unblock-ipinvalid',$ip); $ip = ''; } @@ -280,25 +289,23 @@ function formatRow( $row ) { global $wgLang,$wgUser; - + + ## One-time setup + static $sk=null; + + if (is_null($sk)) { + $sk = $wgUser->getSkin(); + } + + ## Setup $timestamp = $row->gb_timestamp; $expiry = $row->gb_expiry; $options = array(); - - if (strlen($row->gb_reason)) { - $options[] = $row->gb_reason; - } - - $expiry = Block::decodeExpiry( $row->gb_expiry ); - if ($expiry == 'infinity') { - $expiry = wfMsg( 'infiniteblock' ); - } else { - global $wgLang; - $expiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $expiry ), true ); - } - $options[] = wfMsg( 'globalblocking-list-expiry', $expiry); - ## Check for whitelisting. + ## Options to display + $options[] = Block::formatExpiry( $expiry ); + + # Check for whitelisting. $wlinfo = GlobalBlocking::getWhitelistInfo( $row->gb_id ); if ($wlinfo) { $options[] = wfMsg( 'globalblocking-list-whitelisted', User::whois($wlinfo['user']), $wlinfo['reason'] ); @@ -308,10 +315,11 @@ if ($row->gb_anon_only) $options[] = wfMsg('globalblocking-list-anononly'); - - $sk = $wgUser->getSkin(); $titleObj = SpecialPage::getTitleFor( "GlobalBlockList" ); + + ## Do afterthoughts (comment, links for admins) + $comment = $sk->commentBlock($row->gb_reason); $unblockLink = ''; if (count(SpecialPage::getTitleFor( 'GlobalBlockList' )->getUserPermissionsErrors( 'globalunblock', $wgUser ))<=1 ) { @@ -321,11 +329,16 @@ if (count(SpecialPage::getTitleFor( 'GlobalBlockList' )->getUserPermissionsErrors( 'globalblock-whitelist', $wgUser ))<=1) { $whitelistLink = ' (' . $sk->makeKnownLinkObj($titleObj, wfMsg( 'globalblocking-list-whitelist' ), 'action=whitelist&whitelistip=' . urlencode( $row->gb_address ) . '&whitelistid=' . urlencode($row->gb_id) ) . ')'; } - + + ## Userpage link / Info on originating wiki + $display_wiki = GlobalBlocking::getWikiName( $row->gb_by_wiki ); + $user_display = GlobalBlocking::maybeLinkUserpage( $row->gb_by_wiki, $row->gb_by ); + + ## Put it all together. return Xml::openElement( 'li' ) . wfMsgExt( 'globalblocking-list-blockitem', array( 'parseinline' ), $timestamp, - $row->gb_by, $row->gb_by_wiki, $row->gb_address, - implode( ', ', $options) ) . " $unblockLink $whitelistLink " . + $user_display, $display_wiki, $row->gb_address, + implode( ', ', $options) ) . " $comment $unblockLink $whitelistLink " . Xml::closeElement( 'li' ); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS [at] lists https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|