r35852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35851‎ | r35852 | r35853 >
Date:07:42, 4 June 2008
Author:siebrand
Status:old
Tags:
Comment:
Remove trailing whitespace introduced in r35849
Modified paths:
  • /trunk/extensions/TorBlock/TorBlock.class.php (modified) (history)
  • /trunk/extensions/TorBlock/loadExitNodes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TorBlock/loadExitNodes.php
@@ -1,10 +1,10 @@
22 <?php
33 /*
4 - * Updates the tor exit node list in
 4+ * Updates the tor exit node list in
55 */
66
77 require_once ( getenv('MW_INSTALL_PATH') !== false
88 ? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc"
99 : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
1010
11 -TorBlock::loadExitNodes();
\ No newline at end of file
 11+TorBlock::loadExitNodes();
Index: trunk/extensions/TorBlock/TorBlock.class.php
@@ -4,18 +4,18 @@
55
66 class TorBlock {
77 public static $mExitNodes;
8 -
 8+
99 public static function onGetUserPermissionsErrorsExpensive( &$title, &$user, &$action, &$result ) {
1010 global $wgTorAllowedActions;
1111 if (in_array( $action, $wgTorAllowedActions)) {
1212 return true;
1313 }
14 -
 14+
1515 wfDebug( "Checking Tor status\n" );
16 -
 16+
1717 if (self::isExitNode()) {
1818 wfDebug( "-User detected as editing through tor.\n" );
19 -
 19+
2020 global $wgTorBypassPermissions;
2121 foreach( $wgTorBypassPermissions as $perm) {
2222 if ($user->isAllowed( $perm )) {
@@ -23,16 +23,16 @@
2424 return true;
2525 }
2626 }
27 -
 27+
2828 $ip = wfGetIp();
2929 wfDebug( "-User detected as editing from Tor node. Adding Tor block to permissions errors\n" );
3030 wfLoadExtensionMessages( 'TorBlock' );
31 -
 31+
3232 $result[] = array('torblock-blocked', $ip);
33 -
 33+
3434 return false;
3535 }
36 -
 36+
3737 return true;
3838 }
3939
@@ -64,15 +64,15 @@
6565 }
6666
6767 wfDebug( "Loading Tor exit node list cold.\n" );
68 -
 68+
6969 return self::loadExitNodes();
7070 }
71 -
 71+
7272 public static function loadExitNodes() {
7373 wfProfileIn( __METHOD__ );
74 -
 74+
7575 global $wgTorIPs, $wgMemc;
76 -
 76+
7777 // Set loading key, to prevent DoS of server.
7878
7979 $wgMemc->set( 'mw-tor-exit-nodes', 'loading', 300 );
@@ -81,76 +81,76 @@
8282 foreach( $wgTorIPs as $ip ) {
8383 $nodes = array_unique( array_merge( $nodes, self::loadNodesForIP( $ip ) ) );
8484 }
85 -
 85+
8686 // Save to cache.
8787 $wgMemc->set( 'mw-tor-exit-nodes', $nodes, 1800 ); // Store for half an hour.
88 -
 88+
8989 wfProfileOut( __METHOD__ );
90 -
 90+
9191 return self::$mExitNodes = $nodes;
9292 }
93 -
 93+
9494 public static function loadNodesForIP( $ip ) {
9595 $url = 'https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip='.$ip;
9696 $data = Http::get( $url );
9797 $lines = explode("\n", $data);
98 -
 98+
9999 $nodes = array();
100100 foreach( $lines as $line ) {
101101 if (strpos( $line, '#' )===false) {
102102 $nodes[] = trim($line);
103103 }
104104 }
105 -
 105+
106106 return $nodes;
107107 }
108 -
 108+
109109 public static function isExitNode($ip = null) {
110110 #return true; ## FOR DEBUGGING
111111 if ($ip == null) {
112112 $ip = wfGetIp();
113113 }
114 -
 114+
115115 $nodes = self::getExitNodes();
116 -
 116+
117117 return in_array( $ip, $nodes );
118118 }
119 -
 119+
120120 public static function onGetBlockedStatus( &$user ) {
121121 if (self::isExitNode() && $user->mBlock && !$user->mBlock->mUser) {
122122 wfDebug( "User using Tor node. Disabling IP block as it was probably targetted at the tor node." );
123123 // Node is probably blocked for being a Tor node. Remove block.
124124 $user->mBlockedBy = 0;
125125 }
126 -
 126+
127127 return true;
128128 }
129 -
 129+
130130 public static function onAbortAutoblock( $autoblockip, &$block ) {
131131 return !self::isExitNode( $autoblockip );
132132 }
133 -
 133+
134134 public static function onGetAutoPromoteGroups( $user, &$promote ) {
135135 // Check against stricter requirements for tor nodes.
136136 // Counterintuitively, we do the requirement checks first.
137137 // This is so that we don't have to hit memcached to get the
138138 // exit list, unnecessarily.
139 -
 139+
140140 if (!count($promote)) {
141141 return true; // No groups to promote to anyway
142142 }
143 -
 143+
144144 $age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
145145 global $wgTorAutoConfirmAge, $wgTorAutoConfirmCount;
146 -
 146+
147147 if ($age >= $wgTorAutoConfirmAge && $user->getEditCount() >= $wgTorAutoConfirmCount) {
148148 return true; // Does match requirements. Don't bother checking if we're an exit node.
149149 }
150 -
 150+
151151 if (self::isExitNode()) { // Tor user, doesn't match the expanded requirements.
152152 $promote = array();
153153 }
154 -
 154+
155155 return true;
156156 }
157157 }
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r35849TorBlock extension updates:...werdna06:52, 4 June 2008

Status & tagging log