Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.body.php |
— | — | @@ -1,51 +1,70 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | |
4 | 4 | class AutoProxyBlock { |
5 | 5 | function isProxy( $ip ) { |
6 | | - global $wgAutoProxyBlockSources; |
| 6 | + global $wgMemc, $wgAutoProxyBlockSources; |
7 | 7 | |
8 | | - if( isset($wgAutoProxyBlockSources['api']) ) { |
9 | | - foreach($wgAutoProxyBlockSources['api'] as $url) { |
10 | | - $request_options = array( |
11 | | - 'action' => 'query', |
12 | | - 'list' => 'blocks', |
13 | | - 'bkip' => "$ip", |
14 | | - 'bklimit' => '1', |
15 | | - 'bkprop' => 'expiry|reason', |
16 | | - ); |
17 | | - |
18 | | - $ban = self::requestForeighAPI($url, $request_options); |
19 | | - if( isset($ban['query']['blocks'][0]) && preg_match($wgAutoProxyBlockSources['key'], $ban['query']['blocks'][0]['reason']) ) { |
20 | | - return true; |
| 8 | + $memcKey = wfMemcKey( 'isproxy', $ip ); |
| 9 | + $data = $wgMemc->get( $memcKey ); |
| 10 | + |
| 11 | + if( $data != '' ) { |
| 12 | + return ( $data === 'proxy' ) ? true : false; |
| 13 | + } else { |
| 14 | + if( isset($wgAutoProxyBlockSources['api']) ) { |
| 15 | + foreach($wgAutoProxyBlockSources['api'] as $url) { |
| 16 | + $request_options = array( |
| 17 | + 'action' => 'query', |
| 18 | + 'list' => 'blocks', |
| 19 | + 'bkip' => $ip, |
| 20 | + 'bklimit' => '1', |
| 21 | + 'bkprop' => 'expiry|reason', |
| 22 | + ); |
| 23 | + |
| 24 | + $ban = self::requestForeighAPI($url, $request_options); |
| 25 | + if( isset($ban['query']['blocks'][0]) && preg_match($wgAutoProxyBlockSources['key'], $ban['query']['blocks'][0]['reason']) ) { |
| 26 | + $wgMemc->set( $memcKey, 'proxy', 60 * 60 * 24 ); |
| 27 | + return true; |
| 28 | + } |
21 | 29 | } |
22 | 30 | } |
23 | | - } |
24 | | - |
25 | | - if( isset($wgAutoProxyBlockSources['raw']) ) { |
26 | | - $list = array(); |
27 | | - foreach($wgAutoProxyBlockSources['raw'] as $file) { |
28 | | - if( file_exists($file) ) { |
29 | | - $p = file($file); |
30 | | - if( $p ) { |
31 | | - array_merge($list, $p); |
| 31 | + |
| 32 | + if( isset($wgAutoProxyBlockSources['raw']) ) { |
| 33 | + $list = array(); |
| 34 | + foreach($wgAutoProxyBlockSources['raw'] as $file) { |
| 35 | + if( file_exists($file) ) { |
| 36 | + $p = file($file); |
| 37 | + if( $p ) { |
| 38 | + array_merge($list, $p); |
| 39 | + } |
32 | 40 | } |
33 | 41 | } |
| 42 | + |
| 43 | + if ( in_array( $ip, array_unique($list) ) ) { |
| 44 | + $wgMemc->set( $memcKey, 'proxy', 60 * 60 * 24 ); |
| 45 | + return true; |
| 46 | + } else { |
| 47 | + $wgMemc->set( $memcKey, 'not', 60 * 60 * 24 ); |
| 48 | + return false; |
| 49 | + } |
34 | 50 | } |
35 | | - |
36 | | - return in_array( $ip, array_unique($list) ); |
| 51 | + |
| 52 | + return false; |
37 | 53 | } |
38 | | - |
39 | | - return false; |
40 | 54 | } |
41 | 55 | |
42 | 56 | function checkProxy( $title, $user, $action, &$result ) { |
43 | 57 | global $wgProxyCanPerform, $wgAutoProxyBlockLog; |
44 | 58 | |
45 | | - if( in_array( $action, $wgProxyCanPerform ) || $user->isAllowed('proxyunbannable') ) return true; |
| 59 | + if( in_array( $action, $wgProxyCanPerform ) || $user->isAllowed('proxyunbannable') ) { |
| 60 | + return true; |
| 61 | + } |
46 | 62 | |
47 | | - $IP = wfGetIP(); |
48 | | - if( self::isProxy( $IP ) ) { |
49 | | - if($wgAutoProxyBlockLog) self::addInternalLogEntry( $IP, $title->mTextform, $user->mName, $action, $user ); |
| 63 | + $userIP = wfGetIP(); |
| 64 | + if( self::isProxy( $userIP ) ) { |
| 65 | + if( $wgAutoProxyBlockLog ) { |
| 66 | + $log = new LogPage( 'proxyblock' ); |
| 67 | + $log->addEntry( 'blocked', $title, false, array( $action, $user->mName ) ); |
| 68 | + } |
50 | 69 | $result[] = array( 'proxy-blocked', $IP ); |
51 | 70 | return false; |
52 | 71 | } |
— | — | @@ -63,11 +82,16 @@ |
64 | 83 | return true; |
65 | 84 | } |
66 | 85 | |
67 | | - function tagProxyChange( $recentChange ) { // -> add check user rights |
| 86 | + function tagProxyChange( $recentChange ) { |
68 | 87 | global $wgTagProxyActions, $wgUser; |
69 | 88 | |
70 | 89 | if ( $wgTagProxyActions && self::isProxy( wfGetIP() ) && !$wgUser->isAllowed( 'notagproxychanges' ) ) { |
71 | | - ChangeTags::addTags( 'proxy', $recentChange->mAttribs['rc_id'], $recentChange->mAttribs['rc_this_oldid'], $recentChange->mAttribs['rc_logid'] ); |
| 90 | + ChangeTags::addTags( |
| 91 | + 'proxy', |
| 92 | + $recentChange->mAttribs['rc_id'], |
| 93 | + $recentChange->mAttribs['rc_this_oldid'], |
| 94 | + $recentChange->mAttribs['rc_logid'] |
| 95 | + ); |
72 | 96 | } |
73 | 97 | return true; |
74 | 98 | } |
— | — | @@ -81,20 +105,6 @@ |
82 | 106 | return true; |
83 | 107 | } |
84 | 108 | |
85 | | - function addInternalLogEntry( $ip, $title, $user, $action, $object ) { |
86 | | - global $wgAutoProxyBlockLog; |
87 | | - |
88 | | - if( !$object->isAllowed('notagproxychanges') ) { |
89 | | - $string = $ip . ' ' . $user . ' on page ' . $title . ' perform ' . $action . "\n"; |
90 | | - |
91 | | - $file = fopen($wgAutoProxyBlockLog, 'a'); |
92 | | - fwrite($file, $string); |
93 | | - fclose($file); |
94 | | - } |
95 | | - |
96 | | - return true; |
97 | | - } |
98 | | - |
99 | 109 | function requestForeighAPI( $url, $options ) { |
100 | 110 | $url .= '?format=php'; |
101 | 111 | foreach($options as $param => $value) { |
Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.i18n.php |
— | — | @@ -1,17 +1,22 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | $messages = array(); |
4 | 4 | |
5 | 5 | $messages['en'] = array( |
6 | 6 | 'autoproxyblock-desc' => 'Allows to block open proxies from performing actions in wiki', |
7 | | - 'proxy-blocked' => '$1 is listed as proxy, performed action aborted.', |
| 7 | + 'proxy-blocked' => 'Your IP address is listed as proxy, performed action aborted.', |
8 | 8 | 'abusefilter-edit-builder-vars-is-proxy' => 'True if this action was performed through a proxy', |
9 | 9 | 'tag-proxy' => 'action through proxy', |
10 | 10 | 'right-notagproxychanges' => 'protect from tagging edits through proxies as "proxy"', |
| 11 | + 'right-autoproxyblock-log' => 'view log of automatically blocked changes through proxies', |
| 12 | + 'proxyblock-log-name' => 'Auto proxy block log', |
| 13 | + 'proxyblock-log-header' => 'List of automatically blocked changes through proxies', |
| 14 | + 'proxyblock-logentry' => '', |
| 15 | + 'proxyblock-logentry-blocked' => 'User [[User:$3|$3]]\'s action "$2" on page [[$1]] automatically blocked.', |
11 | 16 | ); |
12 | 17 | |
13 | 18 | $messages['ru'] = array( |
14 | 19 | 'autoproxyblock-desc' => 'Позволяет запрещать совершать действия в вики c открытых прокси', |
15 | | - 'proxy-blocked' => '$1 находится в списках прокси, действие отменено.', |
| 20 | + 'proxy-blocked' => 'Ваш IP-адрес находится в списках прокси, действие отменено.', |
16 | 21 | 'abusefilter-edit-builder-vars-is-proxy' => 'Истинно, если действие совершено через прокси', |
17 | 22 | 'tag-proxy' => 'совершено через прокси', |
18 | 23 | 'right-notagproxychanges' => 'правки через прокси не отмечаются меткой', |
Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.php |
— | — | @@ -1,4 +1,4 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) { |
4 | 4 | exit(1); |
5 | 5 | } |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | 'path' => __FILE__, |
10 | 10 | 'name' => 'AutoProxyBlock', |
11 | 11 | 'author' => 'Cryptocoryne', |
| 12 | + 'version' => '0.9', |
12 | 13 | 'descriptionmsg' => 'autoproxyblock-desc', |
13 | 14 | 'url' => 'http://www.mediawiki.org/wiki/Extension:AutoProxyBlock', |
14 | 15 | ); |
— | — | @@ -38,5 +39,16 @@ |
39 | 40 | $wgAutoProxyBlockSources['raw'][] = '/var/www/mediawiki/proxy.list'; |
40 | 41 | $wgAutoProxyBlockSources['key'] = '/blocked proxy/i'; |
41 | 42 | |
42 | | -// if set, log all blocked actions in file |
43 | | -$wgAutoProxyBlockLog = false; |
\ No newline at end of file |
| 43 | +// if set, log all blocked actions in log |
| 44 | +$wgAutoProxyBlockLog = false; |
| 45 | + |
| 46 | +if( $wgAutoProxyBlockLog ) { |
| 47 | + $wgAvailableRights[] = 'autoproxyblock-log'; |
| 48 | + $wgGroupPermissions['bureaucrat']['autoproxyblock-log'] = true; |
| 49 | + $wgLogTypes[] = 'proxyblock'; |
| 50 | + $wgLogNames['proxyblock'] = 'proxyblock-log-name'; |
| 51 | + $wgLogHeaders['proxyblock'] = 'proxyblock-log-header'; |
| 52 | + $wgLogActions['proxyblock/proxyblock'] = 'proxyblock-logentry'; |
| 53 | + $wgLogActions['proxyblock/blocked'] = 'proxyblock-logentry-blocked'; |
| 54 | + $wgLogRestrictions['proxyblock'] = 'autoproxyblock-log'; |
| 55 | +} |
\ No newline at end of file |