[MediaWiki-commits] [Gerrit] Rename the TorBlock class to TorBlockHooks - change (mediawiki...TorBlock)
jenkins-bot has submitted this change and it was merged. Change subject: Rename the TorBlock class to TorBlockHooks .. Rename the TorBlock class to TorBlockHooks And move into an includes dir. Change-Id: Icc5c5a6800fef1b7208cdd560c8749e9b163ef10 --- M TorBlock.php R includes/TorBlockHooks.php R includes/TorExitNodes.php 3 files changed, 19 insertions(+), 26 deletions(-) Approvals: MarkTraceur: Looks good to me, approved jenkins-bot: Verified diff --git a/TorBlock.php b/TorBlock.php index 0ed2af9..8356400 100644 --- a/TorBlock.php +++ b/TorBlock.php @@ -30,7 +30,6 @@ die(); } -$dir = __DIR__; $wgExtensionCredits['antispam'][] = array( 'path' = __FILE__, 'name' = 'TorBlock', @@ -40,21 +39,21 @@ ); $wgMessagesDirs['TorBlock'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['TorBlock'] = $dir/TorBlock.i18n.php; -$wgAutoloadClasses['TorBlock'] = $dir/TorBlock.class.php; -$wgAutoloadClasses['TorExitNodes'] = $dir/TorExitNodes.php; +$wgExtensionMessagesFiles['TorBlock'] = __DIR__ . /TorBlock.i18n.php; +$wgAutoloadClasses['TorBlockHooks'] = __DIR__ . '/includes/TorBlockHooks.php'; +$wgAutoloadClasses['TorExitNodes'] = __DIR__ . '/includes/TorExitNodes.php'; -$wgHooks['getUserPermissionsErrorsExpensive'][] = 'TorBlock::onGetUserPermissionsErrorsExpensive'; -$wgHooks['AbortAutoblock'][] = 'TorBlock::onAbortAutoblock'; -$wgHooks['GetAutoPromoteGroups'][] = 'TorBlock::onGetAutoPromoteGroups'; -$wgHooks['GetBlockedStatus'][] = 'TorBlock::onGetBlockedStatus'; -$wgHooks['AutopromoteCondition'][] = 'TorBlock::onAutopromoteCondition'; -$wgHooks['RecentChange_save'][] = 'TorBlock::onRecentChangeSave'; -$wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags'; -$wgHooks['AbuseFilter-filterAction'][] = 'TorBlock::onAbuseFilterFilterAction'; -$wgHooks['AbuseFilter-builder'][] = 'TorBlock::onAbuseFilterBuilder'; -$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlock::onEmailUserPermissionsErrors'; -$wgHooks['OtherBlockLogLink'][] = 'TorBlock::getTorBlockStatus'; +$wgHooks['getUserPermissionsErrorsExpensive'][] = 'TorBlockHooks::onGetUserPermissionsErrorsExpensive'; +$wgHooks['AbortAutoblock'][] = 'TorBlockHooks::onAbortAutoblock'; +$wgHooks['GetAutoPromoteGroups'][] = 'TorBlockHooks::onGetAutoPromoteGroups'; +$wgHooks['GetBlockedStatus'][] = 'TorBlockHooks::onGetBlockedStatus'; +$wgHooks['AutopromoteCondition'][] = 'TorBlockHooks::onAutopromoteCondition'; +$wgHooks['RecentChange_save'][] = 'TorBlockHooks::onRecentChangeSave'; +$wgHooks['ListDefinedTags'][] = 'TorBlockHooks::onListDefinedTags'; +$wgHooks['AbuseFilter-filterAction'][] = 'TorBlockHooks::onAbuseFilterFilterAction'; +$wgHooks['AbuseFilter-builder'][] = 'TorBlockHooks::onAbuseFilterBuilder'; +$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlockHooks::onEmailUserPermissionsErrors'; +$wgHooks['OtherBlockLogLink'][] = 'TorBlockHooks::onOtherBlockLogLink'; // Define new autopromote condition define( 'APCOND_TOR', 'tor' ); // Numbers won't work, we'll get collisions @@ -103,13 +102,13 @@ * Path to the CA file for the Onionoo server. * Set to false or any other invalid value to disable. */ -$wgTorOnionooCA = $dir/torproject.crt; +$wgTorOnionooCA = __DIR__ . /torproject.crt; /** * Path to the CA file for the Tor Project. * Set to false or any other invalid value to disable. */ -$wgTorProjectCA = $dir/torproject.crt; +$wgTorProjectCA = __DIR__ . /torproject.crt; /** * Disable existing blocks of Tor nodes diff --git a/TorBlock.class.php b/includes/TorBlockHooks.php similarity index 96% rename from TorBlock.class.php rename to includes/TorBlockHooks.php index e6e8881..00c7187 100644 --- a/TorBlock.class.php +++ b/includes/TorBlockHooks.php @@ -26,11 +26,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ -if ( !defined( 'MEDIAWIKI' ) ) { - die(); -} - -class TorBlock { +class TorBlockHooks { /** * Check if a user is a Tor node and not whitelisted or allowed * to bypass tor blocks. @@ -47,15 +43,13 @@ return true; } - // wfDebugLog( 'torblock', Checking Tor status\n ); - if ( TorExitNodes::isExitNode() ) { wfDebugLog( 'torblock', User detected as editing through tor. ); global $wgTorBypassPermissions; foreach ( $wgTorBypassPermissions as $perm) { if ( $user-isAllowed( $perm ) ) { - wfDebugLog( 'torblock', User has $perm permission. Exempting from Tor Blocks ); + wfDebugLog( 'torblock', User has $perm permission. Exempting from Tor Blocks. ); return true; } } @@ -274,7 +268,7 @@
[MediaWiki-commits] [Gerrit] Rename the TorBlock class to TorBlockHooks - change (mediawiki...TorBlock)
Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/181808 Change subject: Rename the TorBlock class to TorBlockHooks .. Rename the TorBlock class to TorBlockHooks And move into an includes dir. Change-Id: Icc5c5a6800fef1b7208cdd560c8749e9b163ef10 --- M TorBlock.php R includes/TorBlockHooks.php R includes/TorExitNodes.php 3 files changed, 24 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TorBlock refs/changes/08/181808/1 diff --git a/TorBlock.php b/TorBlock.php index 0ed2af9..8356400 100644 --- a/TorBlock.php +++ b/TorBlock.php @@ -30,7 +30,6 @@ die(); } -$dir = __DIR__; $wgExtensionCredits['antispam'][] = array( 'path' = __FILE__, 'name' = 'TorBlock', @@ -40,21 +39,21 @@ ); $wgMessagesDirs['TorBlock'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['TorBlock'] = $dir/TorBlock.i18n.php; -$wgAutoloadClasses['TorBlock'] = $dir/TorBlock.class.php; -$wgAutoloadClasses['TorExitNodes'] = $dir/TorExitNodes.php; +$wgExtensionMessagesFiles['TorBlock'] = __DIR__ . /TorBlock.i18n.php; +$wgAutoloadClasses['TorBlockHooks'] = __DIR__ . '/includes/TorBlockHooks.php'; +$wgAutoloadClasses['TorExitNodes'] = __DIR__ . '/includes/TorExitNodes.php'; -$wgHooks['getUserPermissionsErrorsExpensive'][] = 'TorBlock::onGetUserPermissionsErrorsExpensive'; -$wgHooks['AbortAutoblock'][] = 'TorBlock::onAbortAutoblock'; -$wgHooks['GetAutoPromoteGroups'][] = 'TorBlock::onGetAutoPromoteGroups'; -$wgHooks['GetBlockedStatus'][] = 'TorBlock::onGetBlockedStatus'; -$wgHooks['AutopromoteCondition'][] = 'TorBlock::onAutopromoteCondition'; -$wgHooks['RecentChange_save'][] = 'TorBlock::onRecentChangeSave'; -$wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags'; -$wgHooks['AbuseFilter-filterAction'][] = 'TorBlock::onAbuseFilterFilterAction'; -$wgHooks['AbuseFilter-builder'][] = 'TorBlock::onAbuseFilterBuilder'; -$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlock::onEmailUserPermissionsErrors'; -$wgHooks['OtherBlockLogLink'][] = 'TorBlock::getTorBlockStatus'; +$wgHooks['getUserPermissionsErrorsExpensive'][] = 'TorBlockHooks::onGetUserPermissionsErrorsExpensive'; +$wgHooks['AbortAutoblock'][] = 'TorBlockHooks::onAbortAutoblock'; +$wgHooks['GetAutoPromoteGroups'][] = 'TorBlockHooks::onGetAutoPromoteGroups'; +$wgHooks['GetBlockedStatus'][] = 'TorBlockHooks::onGetBlockedStatus'; +$wgHooks['AutopromoteCondition'][] = 'TorBlockHooks::onAutopromoteCondition'; +$wgHooks['RecentChange_save'][] = 'TorBlockHooks::onRecentChangeSave'; +$wgHooks['ListDefinedTags'][] = 'TorBlockHooks::onListDefinedTags'; +$wgHooks['AbuseFilter-filterAction'][] = 'TorBlockHooks::onAbuseFilterFilterAction'; +$wgHooks['AbuseFilter-builder'][] = 'TorBlockHooks::onAbuseFilterBuilder'; +$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlockHooks::onEmailUserPermissionsErrors'; +$wgHooks['OtherBlockLogLink'][] = 'TorBlockHooks::onOtherBlockLogLink'; // Define new autopromote condition define( 'APCOND_TOR', 'tor' ); // Numbers won't work, we'll get collisions @@ -103,13 +102,13 @@ * Path to the CA file for the Onionoo server. * Set to false or any other invalid value to disable. */ -$wgTorOnionooCA = $dir/torproject.crt; +$wgTorOnionooCA = __DIR__ . /torproject.crt; /** * Path to the CA file for the Tor Project. * Set to false or any other invalid value to disable. */ -$wgTorProjectCA = $dir/torproject.crt; +$wgTorProjectCA = __DIR__ . /torproject.crt; /** * Disable existing blocks of Tor nodes diff --git a/TorBlock.class.php b/includes/TorBlockHooks.php similarity index 95% rename from TorBlock.class.php rename to includes/TorBlockHooks.php index e6e8881..ec86ddc 100644 --- a/TorBlock.class.php +++ b/includes/TorBlockHooks.php @@ -26,11 +26,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ -if ( !defined( 'MEDIAWIKI' ) ) { - die(); -} - -class TorBlock { +class TorBlockHooks { /** * Check if a user is a Tor node and not whitelisted or allowed * to bypass tor blocks. @@ -47,17 +43,17 @@ return true; } - // wfDebugLog( 'torblock', Checking Tor status\n ); - if ( TorExitNodes::isExitNode() ) { wfDebugLog( 'torblock', User detected as editing through tor. ); global $wgTorBypassPermissions; - foreach ( $wgTorBypassPermissions as $perm) { - if ( $user-isAllowed( $perm ) ) { - wfDebugLog( 'torblock', User has $perm permission. Exempting from Tor Blocks ); - return true; - } + if ( $user-isAllowedAny( $wgTorBypassPermissions ) ) { +