r100972 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100971‎ | r100972 | r100973 >
Date:13:23, 27 October 2011
Author:cryptocoryne
Status:deferred (Comments)
Tags:
Comment:
Followup r100863, some improves and fixes
Modified paths:
  • /trunk/extensions/AutoProxyBlock/AutoProxyBlock.body.php (modified) (history)
  • /trunk/extensions/AutoProxyBlock/AutoProxyBlock.i18n.php (modified) (history)
  • /trunk/extensions/AutoProxyBlock/AutoProxyBlock.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.body.php
@@ -1,51 +1,70 @@
2 -<?php
 2+<?php
33
44 class AutoProxyBlock {
55 function isProxy( $ip ) {
6 - global $wgAutoProxyBlockSources;
 6+ global $wgMemc, $wgAutoProxyBlockSources;
77
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+ }
2129 }
2230 }
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+ }
3240 }
3341 }
 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+ }
3450 }
35 -
36 - return in_array( $ip, array_unique($list) );
 51+
 52+ return false;
3753 }
38 -
39 - return false;
4054 }
4155
4256 function checkProxy( $title, $user, $action, &$result ) {
4357 global $wgProxyCanPerform, $wgAutoProxyBlockLog;
4458
45 - if( in_array( $action, $wgProxyCanPerform ) || $user->isAllowed('proxyunbannable') ) return true;
 59+ if( in_array( $action, $wgProxyCanPerform ) || $user->isAllowed('proxyunbannable') ) {
 60+ return true;
 61+ }
4662
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+ }
5069 $result[] = array( 'proxy-blocked', $IP );
5170 return false;
5271 }
@@ -63,11 +82,16 @@
6483 return true;
6584 }
6685
67 - function tagProxyChange( $recentChange ) { // -> add check user rights
 86+ function tagProxyChange( $recentChange ) {
6887 global $wgTagProxyActions, $wgUser;
6988
7089 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+ );
7296 }
7397 return true;
7498 }
@@ -81,20 +105,6 @@
82106 return true;
83107 }
84108
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 -
99109 function requestForeighAPI( $url, $options ) {
100110 $url .= '?format=php';
101111 foreach($options as $param => $value) {
Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.i18n.php
@@ -1,17 +1,22 @@
2 -<?php
 2+<?php
33 $messages = array();
44
55 $messages['en'] = array(
66 '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.',
88 'abusefilter-edit-builder-vars-is-proxy' => 'True if this action was performed through a proxy',
99 'tag-proxy' => 'action through proxy',
1010 '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.',
1116 );
1217
1318 $messages['ru'] = array(
1419 'autoproxyblock-desc' => 'Позволяет запрещать совершать действия в вики c открытых прокси',
15 - 'proxy-blocked' => '$1 находится в списках прокси, действие отменено.',
 20+ 'proxy-blocked' => 'Ваш IP-адрес находится в списках прокси, действие отменено.',
1621 'abusefilter-edit-builder-vars-is-proxy' => 'Истинно, если действие совершено через прокси',
1722 'tag-proxy' => 'совершено через прокси',
1823 'right-notagproxychanges' => 'правки через прокси не отмечаются меткой',
Index: trunk/extensions/AutoProxyBlock/AutoProxyBlock.php
@@ -1,4 +1,4 @@
2 -<?php
 2+<?php
33 if ( !defined( 'MEDIAWIKI' ) ) {
44 exit(1);
55 }
@@ -8,6 +8,7 @@
99 'path' => __FILE__,
1010 'name' => 'AutoProxyBlock',
1111 'author' => 'Cryptocoryne',
 12+ 'version' => '0.9',
1213 'descriptionmsg' => 'autoproxyblock-desc',
1314 'url' => 'http://www.mediawiki.org/wiki/Extension:AutoProxyBlock',
1415 );
@@ -38,5 +39,16 @@
3940 $wgAutoProxyBlockSources['raw'][] = '/var/www/mediawiki/proxy.list';
4041 $wgAutoProxyBlockSources['key'] = '/blocked proxy/i';
4142
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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100863Adding beta-version of extension 'AutoProxyBlock' to repocryptocoryne20:07, 26 October 2011

Comments

#Comment by Siebrand (talk | contribs)   13:30, 27 October 2011

Please add message documentation for the newly added messages. Thanks.

#Comment by Nikerabbit (talk | contribs)   13:36, 27 October 2011

Good, you removed those nasty BOM characters from the files. You might want to consider using the new log message naming convention introduced in 1.19.

Status & tagging log