[MediaWiki-commits] [Gerrit] mediawiki...ThrottleOverride[master]: Introduce config variable for throttle types

2017-11-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/380061 )

Change subject: Introduce config variable for throttle types
..


Introduce config variable for throttle types

There is no need and it isn't desired to give the possibility to
override all types of throttles, e.g. most wikis won't have a reason to
allow certain ips to bypass the "password recovery email" throttle.

$wgThrottleOverrideTypes gives the possibility to select fewer or more
options than are enabled by default.

Note that this patch disables "mailpassword" and "emailuser" throttles
by default although those were part of the UI before.

Also fix wrong linking in ThrottleOverridePage, the special page is name
OverrideThrottle and not ThrottleOverride.

Bug: T62419
Change-Id: Ic489d845d7167cbf522206c9cc858b9c5cee17be
---
M SpecialOverrideThrottle.php
M SpecialThrottleOverrideList.php
M ThrottleOverridePager.php
M extension.json
4 files changed, 17 insertions(+), 4 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php
index 8144e30..5e9433e 100644
--- a/SpecialOverrideThrottle.php
+++ b/SpecialOverrideThrottle.php
@@ -46,7 +46,8 @@
// move - A page is moved (ping-limiter)
// mailpassword - User requests a password recovery 
(ping-limiter)
// emailuser - User emails another user (ping-limiter)
-   $throttleTypes = [ 'actcreate', 'edit', 'move', 'mailpassword', 
'emailuser' ];
+   global $wgThrottleOverrideTypes;
+   $throttleTypes = array_keys( array_filter( 
$wgThrottleOverrideTypes ) );
 
// Construct an array of message => type.
$throttles = [];
diff --git a/SpecialThrottleOverrideList.php b/SpecialThrottleOverrideList.php
index e78c3ff..7113ce3 100644
--- a/SpecialThrottleOverrideList.php
+++ b/SpecialThrottleOverrideList.php
@@ -32,9 +32,12 @@
 
function getFormFields() {
global $wgRateLimits;
+   global $wgThrottleOverrideTypes;
+   $throttleTypes = array_keys( array_filter( 
$wgThrottleOverrideTypes ) );
+   $throttleTypes = array_merge( [ 'all' ], $throttleTypes );
 
$throttles = [];
-   foreach ( [ 'all', 'actcreate', 'edit', 'move', 'mailpassword', 
'emailuser' ] as $type ) {
+   foreach ( $throttleTypes as $type ) {
if ( $type == 'all' || $type == 'actcreate' || isset( 
$wgRateLimits[$type] ) ) {
// For grepping. The following messages are 
used here:
// throttleoverride-types-all
diff --git a/ThrottleOverridePager.php b/ThrottleOverridePager.php
index 8cd7799..6bbc62a 100644
--- a/ThrottleOverridePager.php
+++ b/ThrottleOverridePager.php
@@ -97,10 +97,10 @@
$formatted = htmlspecialchars( 
$language->formatExpiry( $value,
/* User preference timezone */true ) );
 
-   // Show link to 
Special:ThrottleOverride/$Username if we're allowed to manipulate throttles.
+   // Show link to 
Special:OverrideThrottle/$Username if we're allowed to manipulate throttles.
if ( $this->getUser()->isAllowed( 
'throttleoverride' ) ) {
$link = $linkRenderer->makeKnownLink(
-   SpecialPage::getTitleFor( 
'ThrottleOverride', IP::prettifyIP( $row->thr_target ) ),
+   SpecialPage::getTitleFor( 
'OverrideThrottle', IP::prettifyIP( $row->thr_target ) ),
$this->msg( 
'throttleoverride-list-change' )->text()
);
 
diff --git a/extension.json b/extension.json
index fa01b73..8121c13 100644
--- a/extension.json
+++ b/extension.json
@@ -44,6 +44,15 @@
"IPv4": 16,
"IPv6": 19
}
+   },
+   "ThrottleOverrideTypes": {
+   "value": {
+   "actcreate": true,
+   "edit": true,
+   "move": true,
+   "mailpassword": false,
+   "emailuser": false
+   }
}
},
"ResourceModules": {

-- 
To view, visit https://gerrit.wikimedia.org/r/380061
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic489d845d7167cbf522206c9cc858b9c5cee17be
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/ThrottleOverride
Gerrit-Branch: master

[MediaWiki-commits] [Gerrit] mediawiki...ThrottleOverride[master]: Introduce config variable for throttle types

2017-09-23 Thread EddieGP (Code Review)
EddieGP has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/380061 )

Change subject: Introduce config variable for throttle types
..

Introduce config variable for throttle types

There is no need and it isn't desired to give the possibility to
override all types of throttles, e.g. most wikis won't have a reason to
allow certain ips to bypass the "password recovery email" throttle.

$wgThrottleOverrideTypes gives the possibility to select fewer or more
options than are enabled by default.

Note that this patch disables "mailpassword" and "emailuser" throttles
by default although those were part of the UI before.

This also introduces ThrottleOverride.class.php for a helper function
that is used within multiple other classes. A ThrottleOverride object
will be needed later for caching anyways.

Also fix wrong linking in ThrottleOverridePage, the special page is name
OverrideThrottle and not ThrottleOverride.

Change-Id: Ic489d845d7167cbf522206c9cc858b9c5cee17be
---
M SpecialOverrideThrottle.php
M SpecialThrottleOverrideList.php
A ThrottleOverride.class.php
M ThrottleOverridePager.php
M extension.json
5 files changed, 68 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ThrottleOverride 
refs/changes/61/380061/1

diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php
index ee62d47..38bd6eb 100644
--- a/SpecialOverrideThrottle.php
+++ b/SpecialOverrideThrottle.php
@@ -40,14 +40,7 @@
function getFormFields() {
global $wgRateLimits;
 
-   // The types are:
-   // actcreate - An account is created (not ping-limiter)
-   // edit - A page is edited (ping-limiter)
-   // move - A page is moved (ping-limiter)
-   // mailpassword - User requests a password recovery 
(ping-limiter)
-   // emailuser - User emails another user (ping-limiter)
-   $throttleTypes = [ 'actcreate', 'edit', 'move', 'mailpassword', 
'emailuser' ];
-
+   $throttleTypes = ThrottleOverride::getThrottleTypesFlatArray();
// Construct an array of message => type.
$throttles = [];
foreach ( $throttleTypes as $type ) {
diff --git a/SpecialThrottleOverrideList.php b/SpecialThrottleOverrideList.php
index e78c3ff..e163ed8 100644
--- a/SpecialThrottleOverrideList.php
+++ b/SpecialThrottleOverrideList.php
@@ -32,9 +32,10 @@
 
function getFormFields() {
global $wgRateLimits;
+   $throttleTypes = array_merge( [ 'all' ], 
ThrottleOverride::getThrottleTypesFlatArray() );
 
$throttles = [];
-   foreach ( [ 'all', 'actcreate', 'edit', 'move', 'mailpassword', 
'emailuser' ] as $type ) {
+   foreach ( $throttleTypes as $type ) {
if ( $type == 'all' || $type == 'actcreate' || isset( 
$wgRateLimits[$type] ) ) {
// For grepping. The following messages are 
used here:
// throttleoverride-types-all
diff --git a/ThrottleOverride.class.php b/ThrottleOverride.class.php
new file mode 100644
index 000..5e08dc5
--- /dev/null
+++ b/ThrottleOverride.class.php
@@ -0,0 +1,54 @@
+http://www.gnu.org/licenses/>.
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
3.0 or later
+ */
+
+/**
+ * This class currently only holds static helper functions.
+ *
+ */
+class ThrottleOverride {
+
+   /**
+* Get the keys of $wgThrottleOverrideTypes which have true as their 
value.
+* This makes it easy to iterate over all types of throttles although
+* $wgThrottleOverrideTypes is a boolean array.
+*
+* @return array Flat array of strings (throttle types).
+*/
+   function getThrottleTypesFlatArray() {
+   // The types are:
+   // actcreate - An account is created (not ping-limiter)
+   // edit - A page is edited (ping-limiter)
+   // move - A page is moved (ping-limiter)
+   // mailpassword - User requests a password recovery 
(ping-limiter)
+   // emailuser - User emails another user (ping-limiter)
+
+   $throttleTypes = [];
+   global $wgThrottleOverrideTypes;
+
+   foreach( $wgThrottleOverrideTypes as $key => $value ) {
+   if( $value ) {
+   $throttleTypes[] = $key;
+   }
+   }
+
+   return $throttleTypes;
+   }
+}
diff --git a/ThrottleOverridePager.php b/ThrottleOverridePager.php
index 8cd7799..6bbc62a 100644
--- a/ThrottleOverridePager.php
+++ b/ThrottleOverridePager.php
@@ -97,10 +97,10 @@
$formatted = htmlspecialchars( 
$language->formatExpiry( $value,