Index: trunk/phase3/includes/specials/SpecialEmailuser.php |
— | — | @@ -48,6 +48,12 @@ |
49 | 49 | case 'mailnologin': |
50 | 50 | $wgOut->showErrorPage( 'mailnologin', 'mailnologintext' ); |
51 | 51 | return; |
| 52 | + default: |
| 53 | + // It's a hook error |
| 54 | + list( $title, $msg, $params ) = $error; |
| 55 | + $wgOut->showErrorPage( $title, $msg, $params ); |
| 56 | + return; |
| 57 | + |
52 | 58 | } |
53 | 59 | } |
54 | 60 | |
— | — | @@ -297,12 +303,17 @@ |
298 | 304 | return 'actionthrottledtext'; |
299 | 305 | } |
300 | 306 | |
| 307 | + $hookErr = null; |
| 308 | + wfRunHooks( 'EmailUserPermissionsErrors', array( $user, $editToken, &$hookErr ) ); |
| 309 | + |
| 310 | + if ($hookErr) { |
| 311 | + return $hookErr; |
| 312 | + } |
| 313 | + |
301 | 314 | if( !$user->matchEditToken( $editToken ) ) { |
302 | 315 | wfDebug( "Matching edit token failed.\n" ); |
303 | 316 | return 'sessionfailure'; |
304 | 317 | } |
305 | | - |
306 | | - return; |
307 | 318 | } |
308 | 319 | |
309 | 320 | static function newFromURL( $target, $text, $subject, $cc_me ) |
Index: trunk/extensions/TorBlock/TorBlock.php |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | $wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags'; |
38 | 38 | $wgHooks['AbuseFilter-filterAction'][] = 'TorBlock::onAbuseFilterFilterAction'; |
39 | 39 | $wgHooks['AbuseFilter-builder'][] = 'TorBlock::onAbuseFilterBuilder'; |
| 40 | +$wgHooks['EmailUserPermissionsErrors'][] = 'TorBlock::onEmailUserPermissionsErrors'; |
40 | 41 | |
41 | 42 | // Define new autopromote condition |
42 | 43 | define('APCOND_TOR', 'tor'); // Numbers won't work, we'll get collisions |
Index: trunk/extensions/TorBlock/TorBlock.class.php |
— | — | @@ -41,6 +41,42 @@ |
42 | 42 | return true; |
43 | 43 | } |
44 | 44 | |
| 45 | + public static function onEmailUserPermissionsErrors( $user, $editToken, &$hookError ) { |
| 46 | + wfDebug( "Checking Tor status\n" ); |
| 47 | + |
| 48 | + // Just in case we're checking another user |
| 49 | + global $wgUser; |
| 50 | + if ( $user->getName() != $wgUser->getName() ) { |
| 51 | + return true; |
| 52 | + } |
| 53 | + |
| 54 | + if (self::isExitNode()) { |
| 55 | + wfDebug( "-User detected as editing through tor.\n" ); |
| 56 | + |
| 57 | + global $wgTorBypassPermissions; |
| 58 | + foreach( $wgTorBypassPermissions as $perm) { |
| 59 | + if ($user->isAllowed( $perm )) { |
| 60 | + wfDebug( "-User has $perm permission. Exempting from Tor Blocks\n" ); |
| 61 | + return true; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + if (Block::isWhitelistedFromAutoblocks( wfGetIp() )) { |
| 66 | + wfDebug( "-IP is in autoblock whitelist. Exempting from Tor blocks.\n" ); |
| 67 | + return true; |
| 68 | + } |
| 69 | + |
| 70 | + $ip = wfGetIp(); |
| 71 | + wfDebug( "-User detected as editing from Tor node. Denying email.\n" ); |
| 72 | + |
| 73 | + wfLoadExtensionMessages( 'TorBlock' ); |
| 74 | + $hookError = array( 'permissionserrors', 'torblock-blocked', array( $ip ) ); |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
45 | 81 | public static function onAbuseFilterFilterAction( &$vars, $title ) { |
46 | 82 | $vars->setVar( 'tor_exit_node', self::isExitNode() ? 1 : 0 ); |
47 | 83 | return true; |
— | — | @@ -137,6 +173,7 @@ |
138 | 174 | global $wgTorDisableAdminBlocks; |
139 | 175 | if ($wgTorDisableAdminBlocks && self::isExitNode() && $user->mBlock && !$user->mBlock->mUser) { |
140 | 176 | wfDebug( "User using Tor node. Disabling IP block as it was probably targetted at the tor node." ); |
| 177 | + |
141 | 178 | // Node is probably blocked for being a Tor node. Remove block. |
142 | 179 | $user->mBlockedby = 0; |
143 | 180 | } |