EddieGP has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393439 )
Change subject: Add feature to remove exemptions ...................................................................... Add feature to remove exemptions This adds a new special page, Special:DeleteThrottleOverride, which takes a ip range and reason and will remove all exemptions from that range (if any) and create a log entry with the given reason. The range parameter is prefilled and a log excerpt for that range is shown if this parameter is given as the subpage name (e.g. Special:DeleteThrottleOverride/127.0.0.0/8). On Special:ThrottleOverrideList a link is added to remove that throttle (in the same place where the "change throttle" link already is). Re-uses CSS from Special:OverrideThrottle, the css file and module names have been altered to reflect that. Change-Id: Ie7283b7f0498d28c9f03a7d884c0af2f30aa23a6 --- A SpecialDeleteThrottleOverride.php M SpecialOverrideThrottle.php M ThrottleOverride.i18n.alias.php M ThrottleOverrideLogFormatter.php M ThrottleOverridePager.php M extension.json M i18n/en.json M i18n/qqq.json R resources/ext.throttleoverride.specials.css 9 files changed, 177 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ThrottleOverride refs/changes/39/393439/1 diff --git a/SpecialDeleteThrottleOverride.php b/SpecialDeleteThrottleOverride.php new file mode 100644 index 0000000..4aba8a2 --- /dev/null +++ b/SpecialDeleteThrottleOverride.php @@ -0,0 +1,134 @@ +<?php + +/** + * MediaWiki extension to temporarily lift throttles. + * + * 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/>. + * + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later + */ + +use MediaWiki\MediaWikiServices; + +/** + * Deletes a throttle override for a given IP. + */ +class SpecialDeleteThrottleOverride extends FormSpecialPage { + + private $ip; + + public function __construct() { + parent::__construct( 'DeleteThrottleOverride', 'throttleoverride' ); + + $out = $this->getOutput(); + $out->addModules( 'ext.throttleoverride.specials' ); + } + + function getFormFields() { + $data = [ + 'Target' => [ + 'type' => 'text', + 'label-message' => 'throttleoverride-ipaddress', + 'required' => true, + 'autofocus' => true + ], + 'Reason' => [ + 'type' => 'text', + 'label-message' => 'ipbreason', + ], + ]; + + // If this site was called as Special:DeleteThrottleOverride/$this->par, set the target + if ( $this->par ) { + $data['Target']['default'] = $this->par; + } + + return $data; + } + + function onSubmit( array $data ) { + $reason = trim( $data['Reason'] ); + + $ip = IP::sanitizeIP( $data[ 'Target' ] ); + if ( !IP::isIPAddress( $ip ) ) { + // Invalid IP address. + return [ 'throttleoverride-validation-ipinvalid' ]; + } + $this->ip = IP::sanitizeRange( $ip ); + + // Create a log entry + $logEntry = new ManualLogEntry( 'throttleoverride', 'deleted' ); + $logEntry->setPerformer( $this->getUser() ); + $logEntry->setTarget( Title::makeTitle( NS_USER, $this->ip ) ); + $logEntry->setComment( $reason ); + $logId = $logEntry->insert(); + $logEntry->publish( $logId ); + + // Delete the exemption + $dbw = wfGetDB( DB_MASTER ); + $dbw->delete( 'throttle_override', [ 'thr_target' => $this->ip ], __METHOD__ ); + + // Purge the cache + $parsedRange = IP::parseRange( $data['Target'] ); + list( $rangeStart, $rangeEnd ) = $parsedRange; + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $cache->touchCheckKey( ThrottleOverrideHooks::getBucketKey( $cache, $rangeStart ) ); + + return true; + } + + protected function postText() { + $out = ''; + if ( $this->par ) { + # Get the relevant extract from the log. + $ipTitle = Title::makeTitleSafe( NS_USER, $this->par ); + + LogEventsList::showLogExtract( + $out, + 'throttleoverride', + $ipTitle, + '', + [ + 'lim' => 10, + 'msgKey' => [ 'throttleoverride-showlog' ], + 'showIfEmpty' => false + ] + ); + } + + return $out; + } + + function onSuccess() { + $out = $this->getOutput(); + $out->setPageTitle( $this->msg( 'deletethrottleoverride-success-sub' ) ); + $out->addWikiMsg( 'deletethrottleoverride-success', wfEscapeWikiText( $this->ip ) ); + } + + function getMessagePrefix() { + return 'throttleoverride'; + } + + function requiresWrite() { + return true; + } + + protected function getGroupName() { + return 'users'; + } + + protected function getDisplayFormat() { + return 'ooui'; + } +} diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php index a9e1f7b..ae6477b 100644 --- a/SpecialOverrideThrottle.php +++ b/SpecialOverrideThrottle.php @@ -30,7 +30,7 @@ parent::__construct( 'OverrideThrottle', 'throttleoverride' ); $out = $this->getOutput(); - $out->addModules( 'ext.throttleoverride.specialOverrideThrottle' ); + $out->addModules( 'ext.throttleoverride.specials' ); } function getMessagePrefix() { @@ -246,7 +246,7 @@ $ip = IP::sanitizeIP( $target ); if ( !IP::isIPAddress( $ip ) ) { // Invalid IP address. - $errors[] = [ 'throttleoverride-validation-ipinvalid', $ip ]; + $errors[] = [ 'throttleoverride-validation-ipinvalid' ]; } if ( $expiry === false ) { diff --git a/ThrottleOverride.i18n.alias.php b/ThrottleOverride.i18n.alias.php index 6da3b24..bfdc752 100644 --- a/ThrottleOverride.i18n.alias.php +++ b/ThrottleOverride.i18n.alias.php @@ -11,6 +11,7 @@ /** English (English) */ $specialPageAliases['en'] = array( + 'DeleteThrottleOverride' => array( 'DeleteThrottleOverride' ), 'OverrideThrottle' => array( 'OverrideThrottle', 'ThrottleOverride' ), 'ThrottleOverrideList' => array( 'ThrottleOverrideList' ), ); @@ -58,4 +59,4 @@ /** Simplified Chinese (中文(简体)) */ $specialPageAliases['zh-hans'] = array( 'OverrideThrottle' => array( '节流阀覆盖' ), -); \ No newline at end of file +); diff --git a/ThrottleOverrideLogFormatter.php b/ThrottleOverrideLogFormatter.php index 2a99cb3..98c256a 100644 --- a/ThrottleOverrideLogFormatter.php +++ b/ThrottleOverrideLogFormatter.php @@ -34,18 +34,22 @@ $targetUser = User::newFromName( $this->entry->getTarget()->getText(), false ); $params[2] = Message::rawParam( $this->makeUserLink( $targetUser ) ); - // Build a (human-readable) list of throttle types - $types = []; - foreach ( explode( ',', $params[3] ) as $type ) { - $types[] = wfMessage( "throttleoverride-log-type-{$type}" )->text(); + $subtype = $this->entry->getSubtype(); + if ( $subtype == "created" ) { + // Build a (human-readable) list of throttle types + $types = []; + foreach ( explode( ',', $params[3] ) as $type ) { + $types[] = wfMessage( "throttleoverride-log-type-{$type}" )->text(); + } + $params[3] = $language->listToText( $types ); + + // Make the timestamp human-readable. + $params[4] = $language->formatExpiry( $params[4] ); + + // The additional parameter $6 counts the number of throttle types for {{PLURAL:$6|...}} use. + $params[5] = count( $types ); } - $params[3] = $language->listToText( $types ); - // Make the timestamp human-readable. - $params[4] = $language->formatExpiry( $params[4] ); - - // The additional parameter $6 counts the number of throttle types for {{PLURAL:$6|...}} use. - $params[5] = count( $types ); return $params; } } diff --git a/ThrottleOverridePager.php b/ThrottleOverridePager.php index 6bbc62a..47f72ba 100644 --- a/ThrottleOverridePager.php +++ b/ThrottleOverridePager.php @@ -97,17 +97,25 @@ $formatted = htmlspecialchars( $language->formatExpiry( $value, /* User preference timezone */true ) ); - // Show link to Special:OverrideThrottle/$Username if we're allowed to manipulate throttles. + // If we're allowed to manipulate throttles, ... if ( $this->getUser()->isAllowed( 'throttleoverride' ) ) { - $link = $linkRenderer->makeKnownLink( + + // ... show link to Special:OverrideThrottle/$Username (change throttle) + $links[] = $linkRenderer->makeKnownLink( SpecialPage::getTitleFor( 'OverrideThrottle', IP::prettifyIP( $row->thr_target ) ), $this->msg( 'throttleoverride-list-change' )->text() + ); + + // ... show link to Special:DeleteThrottleOverride/$Username (delete throttle) + $links[] = $linkRenderer->makeKnownLink( + SpecialPage::getTitleFor( 'DeleteThrottleOverride', IP::prettifyIP( $row->thr_target ) ), + $this->msg( 'throttleoverride-list-delete' )->text() ); $formatted .= ' ' . Html::rawElement( 'span', [ 'class' => 'mw-throttleoverridelist-actions' ], - $this->msg( 'parentheses' )->rawParams( $link )->escaped() + $this->msg( 'parentheses' )->rawParams( $language->pipeList( $links ) )->escaped() ); } diff --git a/extension.json b/extension.json index 877be67..1229d19 100644 --- a/extension.json +++ b/extension.json @@ -10,6 +10,7 @@ "throttleoverride" ], "SpecialPages": { + "DeleteThrottleOverride": "SpecialDeleteThrottleOverride", "OverrideThrottle": "SpecialOverrideThrottle", "ThrottleOverrideList": "SpecialThrottleOverrideList" }, @@ -40,6 +41,7 @@ }, "AutoloadClasses": { "ThrottleOverrideHooks": "ThrottleOverride.hooks.php", + "SpecialDeleteThrottleOverride": "SpecialDeleteThrottleOverride.php", "SpecialOverrideThrottle": "SpecialOverrideThrottle.php", "SpecialThrottleOverrideList": "SpecialThrottleOverrideList.php", "ThrottleOverridePager": "ThrottleOverridePager.php", @@ -67,9 +69,9 @@ "position": "top", "styles": "ext.throttleoverride.list.css" }, - "ext.throttleoverride.specialOverrideThrottle": { + "ext.throttleoverride.specials": { "position": "top", - "styles": "ext.throttleoverride.specialOverrideThrottle.css" + "styles": "ext.throttleoverride.specials.css" } }, "ResourceFileModulePaths": { diff --git a/i18n/en.json b/i18n/en.json index e087d98..6580b3f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6,9 +6,13 @@ "EddieGP" ] }, + "deletethrottleoverride": "Delete a throttle override", + "deletethrottleoverride-success": "The exemption for $1 was removed.<br />\nSee the [[Special:ThrottleOverrideList|list of throttle overrides]] to review exemptions.", + "deletethrottleoverride-success-sub": "Exemption successfully deleted", "overridethrottle": "Override throttles", "action-throttleoverride": "add exemptions to rate limits", "logentry-throttleoverride-created": "$1 exempted $3 from $4 {{PLURAL:$6|throttle|throttles}} until $5.", + "logentry-throttleoverride-deleted": "$1 deleted the throttle exemption from $3.", "log-name-throttleoverride": "Throttle exemptions", "log-description-throttleoverride": "This is a log of exemptions that will allow users to bypass rate limits. Rate limits are designed to prevent spam by limiting certain actions (e.g. the number of account creations or the usage of Special:Emailuser).", "right-throttleoverride": "Exempt certain IP addresses or ranges from rate limits", @@ -28,6 +32,7 @@ "throttleoverride-types-mailpassword": "Password recovery emails", "throttleoverride-types-emailuser": "User emails", "throttleoverride-list-change": "change throttle", + "throttleoverride-list-delete": "delete throttle", "throttleoverride-list-throttletype": "Throttle type:", "throttleoverride-list-legend": "Exemption filtering", "throttleoverride-list-rangestart": "Start of IP address range", diff --git a/i18n/qqq.json b/i18n/qqq.json index 06ae851..1a05213 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -9,9 +9,13 @@ "EddieGP" ] }, + "deletethrottleoverride": "{{doc-special|DeleteThrottleOverride}}", + "deletethrottleoverride-success": "Text displayed after a successful submission on [[Special:DeleteThrottleOverride]].\n\nParameters:\n* $1 - the IP address or range that was modified.", + "deletethrottleoverride-success-sub": "Used as page title in [[Special:DeleteThrottleOverride]].\n\nThis message is the subject for the following message:\n* {{msg-mw|throttleoverride-success}}", "overridethrottle": "{{doc-special|OverrideThrottle}}", "action-throttleoverride": "{{doc-action|throttleoverride}}", "logentry-throttleoverride-created": "The log message shown on Special:Log. $1 is the performing user, $2 can be used for GENDER, $3 is the target user/IP, $4 is a comma-separated list specifying which rate limits get overwritten, $5 is the time the exemption ends and $6 is the number of items in the list ($4) for use with PLURAL. The items of the list $4 are one or more of {{msg-mw|throttleoverride-log-type-actcreate}}, {{msg-mw|throttleoverride-log-type-edit}}, {{msg-mw|throttleoverride-log-type-move}}, {{msg-mw|throttleoverride-log-type-mailpassword}}, {{msg-mw|throttleoverride-log-type-emailuser}}.", + "logentry-throttleoerride-deleted": "The log message shown on Special:Log when an exemption is removed. $1 is the performing user, $2 can be used for GENDER, $3 is the target user/IP.", "log-name-throttleoverride": "The log name that appears in the drop-down on the Special:Log page.", "log-description-throttleoverride": "The description that appears on the Special:Log page when you filter logs on this specific log name.", "right-throttleoverride": "{{doc-right|throttleoverride}}", @@ -31,6 +35,7 @@ "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-change": "Shown on the page with all existing throttles, linking to the page where a throttle can be altered.", + "throttleoverride-list-delete": "Shown on the page with all existing throttles, linking to the page where a throttle can be deleted.", "throttleoverride-list-throttletype": "Label for the throttle type on [[Special:ThrottleOverrideList]].\n{{Identical|Throttle type}}", "throttleoverride-list-legend": "Fieldset legend on [[Special:ThrottleOverrideList]]", "throttleoverride-list-rangestart": "Table header in the throttle override list for the starting IP address of a throttle override", diff --git a/resources/ext.throttleoverride.specialOverrideThrottle.css b/resources/ext.throttleoverride.specials.css similarity index 100% rename from resources/ext.throttleoverride.specialOverrideThrottle.css rename to resources/ext.throttleoverride.specials.css -- To view, visit https://gerrit.wikimedia.org/r/393439 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie7283b7f0498d28c9f03a7d884c0af2f30aa23a6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ThrottleOverride Gerrit-Branch: master Gerrit-Owner: EddieGP <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
