Parent5446 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67627


Change subject: Add special page for listing throttle overrides
......................................................................

Add special page for listing throttle overrides

Created Special:ThrottleOverrideList to list and describe all
throttle overrides in the database.

Bug: 48954
Change-Id: I902ef4e8db765fc90720c2cc054a34f2995ab9e1
---
A SpecialThrottleOverrideList.php
M ThrottleOverride.hooks.php
M ThrottleOverride.i18n.php
M ThrottleOverride.php
A patches/expiry_index.sql
R patches/table.sql
6 files changed, 205 insertions(+), 2 deletions(-)


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

diff --git a/SpecialThrottleOverrideList.php b/SpecialThrottleOverrideList.php
new file mode 100644
index 0000000..36a99d2
--- /dev/null
+++ b/SpecialThrottleOverrideList.php
@@ -0,0 +1,170 @@
+<?php
+
+/**
+ * MediaWiki extension to temporarily lift throttles.
+ * Copyright (C) 2013 Tyler Romeo <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class SpecialThrottleOverrideList extends FormSpecialPage {
+       function __construct() {
+               parent::__construct( 'ThrottleOverrideList' );
+       }
+
+       function getMessagePrefix() {
+               return 'throttleoverride-list';
+       }
+
+       function getFormFields() {
+               global $wgRateLimits;
+
+               // Construct an array of message => type. The types are:
+               // all - Show all throttles
+               // 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)
+               foreach ( array( 'all', 'actcreate', 'edit', 'move', 
'mailpassword', 'emailuser' ) as $type ) {
+                       if ( $type == 'all' || $type == 'actcreate' || isset( 
$wgRateLimits[$type] ) ) {
+                               // For grepping. The following messages are 
used here:
+                               // throttleoverride-types-all
+                               // throttleoverride-types-actcreate, 
throttleoverride-types-edit,
+                               // throttleoverride-types-moves, 
throttleoverride-types-mailpassword,
+                               // throttleoverride-types-emailuser
+                               $throttles[$this->msg( 
"throttleoverride-types-$type" )->text()] = $type;
+                       }
+               }
+
+               return array(
+                       'ThrottleType' => array(
+                               'type' => 'select',
+                               'default' => 'all',
+                               'label-message' => 
'throttleoverride-list-throttletype',
+                               'options' => $throttles
+                       )
+               );
+       }
+
+       function alterForm( HTMLForm $form ) {
+               $form->setMethod( 'get' );
+               $form->setSubmitTextMsg( 'throttleoverride-list-search' );
+       }
+
+       function onSubmit( array $data, HTMLForm $form = null ) {
+               $pager = new ThrottleOverridePager( $this, array(
+                       'throttleType' => $data['ThrottleType'],
+               ) );
+
+               if ( !$pager->getNumRows() ) {
+                       $form->addPostText( $this->msg( 
'throttleoverride-list-noresults' )->escaped() );
+               } else {
+                       $form->addPostText(
+                               $pager->getNavigationBar() .
+                               $pager->getBody() .
+                               $pager->getNavigationBar()
+                       );
+               }
+
+               return false;
+       }
+
+       function getGroupName() {
+               return 'users';
+       }
+}
+
+class ThrottleOverridePager extends TablePager {
+       function __construct( SpecialPage $page, $conds = array() ) {
+               parent::__construct( $page->getContext() );
+               $this->throttleType = isset( $conds['throttleType'] ) ? 
$conds['throttleType'] : 'all';
+       }
+
+       function getFieldNames() {
+               return array(
+                       'thr_range_start' => $this->msg( 
'throttleoverride-list-rangestart' )->text(),
+                       'thr_range_end' => $this->msg( 
'throttleoverride-list-rangeend' )->text(),
+                       'thr_expiry' => $this->msg( 
'throttleoverride-list-expiry' )->text(),
+                       'thr_type' => $this->msg( 'throttleoverride-list-type' 
)->text(),
+                       'thr_reason' => $this->msg( 
'throttleoverride-list-reason' )->text(),
+               );
+       }
+
+       function isFieldSortable( $field ) {
+               return $field === 'thr_expiry' || $field === 'thr_range_start';
+       }
+
+       function getDefaultSort() {
+               return 'thr_expiry';
+       }
+
+       function getDefaultDirections() {
+               return true;
+       }
+
+       function getQueryInfo() {
+               $a = array(
+                       'tables' => 'throttle_override',
+                       'fields' => array(
+                               'thr_type',
+                               'thr_range_start',
+                               'thr_range_end',
+                               'thr_expiry',
+                               'thr_reason',
+                       ),
+               );
+
+               if ( $this->throttleType !== 'all' ) {
+                       $a['conds'][] = $this->mDb->addIdentifierQuotes( 
'thr_type' ) .
+                               $this->mDb->buildLike(
+                                       $this->mDb->anyString(),
+                                       $this->throttleType,
+                                       $this->mDb->anyString()
+                               );
+               }
+
+               return $a;
+       }
+
+       function formatValue( $name, $value ) {
+               switch ( $name ) {
+                       case 'thr_type':
+                               $types = array();
+                               foreach ( explode( ',', $value ) as $type ) {
+                                       // For grepping. The following messages 
are used here:
+                                       // throttleoverride-types-actcreate, 
throttleoverride-types-edit,
+                                       // throttleoverride-types-moves, 
throttleoverride-types-mailpassword,
+                                       // throttleoverride-types-emailuser
+                                       $types[] = $this->msg( 
"throttleoverride-types-$type" )->escaped();
+                               }
+                               return $this->getLanguage()->commaList( $types 
);
+
+                       case 'thr_range_start':
+                       case 'thr_range_end':
+                               return IP::prettifyIP( IP::formatHex( $value ) 
);
+
+                       case 'thr_expiry':
+                               $ts = $this->getLanguage()->userTimeAndDate( 
$value, $this->getUser() );
+                               return htmlspecialchars( $ts );
+
+                       case 'thr_reason':
+                               return Linker::formatComment( $value );
+
+                       default:
+                               throw new MWException( "Unknown field $name." );
+                               return '';
+               }
+       }
+}
\ No newline at end of file
diff --git a/ThrottleOverride.hooks.php b/ThrottleOverride.hooks.php
index cd0e49e..41d5713 100644
--- a/ThrottleOverride.hooks.php
+++ b/ThrottleOverride.hooks.php
@@ -71,8 +71,14 @@
        public static function onLoadExtensionSchemaUpdates( DatabaseUpdater 
$updater ) {
                $updater->addExtensionTable(
                        'throttle_override',
-                       __DIR__ . '/table.sql'
+                       __DIR__ . '/patches/table.sql'
                );
+               $updater->addExtensionIndex(
+                       'throttle_override',
+                       'thr_expiry',
+                       __DIR__ . '/patches/expiry_index.sql'
+               );
+
                return true;
        }
 }
diff --git a/ThrottleOverride.i18n.php b/ThrottleOverride.i18n.php
index 7e998bb..b738cd5 100644
--- a/ThrottleOverride.i18n.php
+++ b/ThrottleOverride.i18n.php
@@ -16,6 +16,7 @@
  */
 $messages['en'] = array(
        'overridethrottle' => 'Override the account creation throttle',
+       'throttleoverridelist' => 'List of throttle overrides',
        'throttleoverride-desc' => 'Allows overriding of IP address throttles',
        'throttleoverride-legend' => 'Exemption information',
        'throttleoverride-text' => 'Enter the IP address or range you want to 
exempt from certain throttles, and how long the exemption should last for.
@@ -23,11 +24,21 @@
        'throttleoverride-ipaddress' => 'IP address or range',
        'throttleoverride-success' => 'The exemption was applied.',
        'throttleoverride-types' => 'Throttle types:',
+       'throttleoverride-types-all' => 'All types',
        'throttleoverride-types-actcreate' => 'Account creation',
        'throttleoverride-types-edit' => 'Page edits',
        'throttleoverride-types-move' => 'Page moves',
        'throttleoverride-types-mailpassword' => 'Password recovery emails',
-       'throttleoverride-types-emailuser' => 'User emails'
+       'throttleoverride-types-emailuser' => 'User emails',
+       'throttleoverride-list-throttletype' => 'Throttle type:',
+       'throttleoverride-list-legend' => 'Exemption filtering',
+       'throttleoverride-list-rangestart' => 'Start of IP Range',
+       'throttleoverride-list-rangeend' => 'End of IP Range',
+       'throttleoverride-list-expiry' => 'Expiry',
+       'throttleoverride-list-type' => 'Allowed actions',
+       'throttleoverride-list-reason' => 'Reason',
+       'throttleoverride-list-search' => 'Search',
+       'throttleoverride-list-noresults' => 'The throttle override list is 
empty.',
 );
 
 /** Message documentation (Message documentation)
@@ -35,17 +46,28 @@
  */
 $messages['qqq'] = array(
        'overridethrottle' => '{{doc-special|OverrideThrottle}}',
+       'throttleoverridelist' => '{{doc-special|ThrottleOverrideList}}',
        'throttleoverride-desc' => '{{desc|name=Throttle 
Override|url=http://www.mediawiki.org/wiki/Extension:ThrottleOverride}}',
        'throttleoverride-legend' => 'Label for the legend on 
Special:OverrideThrottle',
        'throttleoverride-text' => 'Intro text on Special:OverrideThrottle',
        'throttleoverride-ipaddress' => 'Label for the IP address field on 
Special:OverrideThrottle',
        'throttleoverride-success' => 'Text displayed after a successful 
submission on Special:OverrideThrottle',
        'throttleoverride-types' => 'Label for the types of throttles that can 
be overridden',
+       'throttleoverride-types-all' => 'Label for the throttle type 
representing all types (used in Special:ThrottleOverrideList)',
        'throttleoverride-types-actcreate' => 'Label for the throttle type for 
account creations',
        'throttleoverride-types-edit' => 'Label for the throttle type for page 
edits',
        'throttleoverride-types-move' => 'Label for the throttle type for page 
moves',
        'throttleoverride-types-mailpassword' => 'Label for the throttle type 
for password recovery requests',
        'throttleoverride-types-emailuser' => 'Label for the throttle type for 
user emails',
+       'throttleoverride-list-throttletype' => 'Label for the throttle type on 
Special:ThrottleOverrideList',
+       'throttleoverride-list-legend' => 'Label for the legend on 
Special:ThrottleOverrideList',
+       'throttleoverride-list-rangestart' => 'Table header in the throttle 
override list for the starting IP address of a throttle override',
+       'throttleoverride-list-rangeend' => 'Table header in the throttle 
override list for the ending IP address of a throttle override',
+       'throttleoverride-list-expiry' => 'Table header in the throttle 
override list for the expiry date and time of a throttle override',
+       'throttleoverride-list-type' => 'Table header in the throttle override 
list for the actions allowed by a throttle override',
+       'throttleoverride-list-reason' => 'Table header in the throttle 
override list for the reason of a throttle override',
+       'throttleoverride-list-search' => 'Label for the sumbit button on 
Special:ThrottleOverrideList',
+       'throttleoverride-list-noresults' => 'Message displayed on 
Special:ThrottleOverrideList when the pager returns no results',
 );
 
 /** Breton (brezhoneg)
diff --git a/ThrottleOverride.php b/ThrottleOverride.php
index 0f75ca4..5bf25af 100644
--- a/ThrottleOverride.php
+++ b/ThrottleOverride.php
@@ -31,8 +31,11 @@
 // Hooks and classes
 $wgAutoloadClasses['ThrottleOverrideHooks'] = __DIR__ . 
'/ThrottleOverride.hooks.php';
 $wgAutoloadClasses['SpecialOverrideThrottle'] = __DIR__ . 
'/SpecialOverrideThrottle.php';
+$wgAutoloadClasses['SpecialThrottleOverrideList'] = __DIR__ . 
'/SpecialThrottleOverrideList.php';
+$wgAutoloadClasses['ThrottleOverridePager'] = __DIR__ . 
'/SpecialThrottleOverrideList.php';
 
 $wgSpecialPages['OverrideThrottle'] = 'SpecialOverrideThrottle';
+$wgSpecialPages['ThrottleOverrideList'] = 'SpecialThrottleOverrideList';
 $wgSpecialPageGroups['OverrideThrottle'] = 'users';
 
 Hooks::register( 'PingLimiter', 'ThrottleOverrideHooks::onPingLimiter' );
diff --git a/patches/expiry_index.sql b/patches/expiry_index.sql
new file mode 100644
index 0000000..0eef8f0
--- /dev/null
+++ b/patches/expiry_index.sql
@@ -0,0 +1 @@
+CREATE INDEX /*i*/thr_expiry ON /*_*/throttle_override (thr_expiry);
\ No newline at end of file
diff --git a/table.sql b/patches/table.sql
similarity index 90%
rename from table.sql
rename to patches/table.sql
index 47bddf1..64bd97a 100644
--- a/table.sql
+++ b/patches/table.sql
@@ -20,3 +20,4 @@
 ) /*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/thr_range ON /*_*/throttle_override (thr_range_start(8), 
thr_range_end(8));
+CREATE INDEX /*i*/thr_expiry ON /*_*/throttle_override (thr_expiry);
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I902ef4e8db765fc90720c2cc054a34f2995ab9e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ThrottleOverride
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to