[MediaWiki-commits] [Gerrit] Enabled parameter now allows enabled range - change (mediawiki...ZeroBanner)
jenkins-bot has submitted this change and it was merged. Change subject: Enabled parameter now allows enabled range .. Enabled parameter now allows enabled range Enabled can now be an array of two elements, each being either a date or an integer. If first is an integer, represents number of hours since now If second is an integer, represents the duration (in hours) Change-Id: I23839878a376e73324384b042e809d668f954308 --- M i18n/en.json M i18n/qqq.json M includes/ZeroConfig.php 3 files changed, 86 insertions(+), 4 deletions(-) Approvals: Dr0ptp4kt: Looks good to me, approved jenkins-bot: Verified diff --git a/i18n/en.json b/i18n/en.json index de212ca..b4d27b6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -43,6 +43,7 @@ zero-config-ipsets: Parameter \$1\ must be the name of an existing ip set declared in \ipsets\ field, zero-config-admins: Parameter \$1\ must be an existing user account, zero-config-proxies: Parameter \$1\ must be a list of proxies supporting zero-rating for this carrier, + zero-config-enabled: Parameter \$1\ must be either true, false, or a list with two timestamps. Timestamp could be in any time format. First array can also be a number of hours after (before) now, and second value can be the duration in hours., group-zeroadmin: Zero administrators, group-zeroadmin-member: {{GENDER:$1|Zero administrator}}, grouppage-zeroadmin: {{ns:project}}:Zero administrators, diff --git a/i18n/qqq.json b/i18n/qqq.json index f8e90d0..0d1cc03 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -59,6 +59,7 @@ zero-config-ipsets: ipsets parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, zero-config-admins: Admins parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, zero-config-proxies: Proxies parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, + zero-config-enabled: Enabled parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, group-zeroadmin: {{doc-group|zeroadmin}}, group-zeroadmin-member: {{doc-group|zeroadmin|member}}, grouppage-zeroadmin: {{doc-group|zeroadmin|page}}, diff --git a/includes/ZeroConfig.php b/includes/ZeroConfig.php index 5801e43..6837157 100644 --- a/includes/ZeroConfig.php +++ b/includes/ZeroConfig.php @@ -1,11 +1,16 @@ ?php namespace ZeroBanner; +use DateInterval; +use DateTime; +use DateTimeZone; use JsonConfig\JCObjContent; use JsonConfig\JCUtils; use JsonConfig\JCValidators; use JsonConfig\JCValue; +use MWTimestamp; use stdClass; +use TimestampException; /** * JSON Zero Config @@ -25,6 +30,7 @@ private $mode = null; private $ipset = null; private $proxy = null; + private $enabledValue = false; const ignoreNetwork = 0x1; const ignoreDisabled = 0x2; @@ -54,7 +60,7 @@ $proxy = $proxy !== false ? strtoupper( $proxy ) : 'DIRECT'; $all = $this-getDataWithDefaults(); - if ( $all-enabled || ( $mode self::ignoreDisabled ) ) { + if ( $this-enabledValue || ( $mode self::ignoreDisabled ) ) { foreach ( $all-configs as $cfg ) { if ( ( $mode self::ignoreNetwork || in_array( $ipset, $cfg-ipsets ) ) ( $mode self::ignoreDisabled || $cfg-enabled ) @@ -100,7 +106,7 @@ } public function enabled() { - return $this-config-enabled $this-getDataWithDefaults()-enabled; + return $this-enabledValue $this-getDataWithDefaults()-enabled; } public function name() { @@ -205,7 +211,7 @@ // Optional comment $this-testOptional( 'comment', '', $isString ); // Config is enabled - $this-testOptional( 'enabled', true, $isBool ); + $this-testOptional( 'enabled', true, $this-getEnabledValidator() ); // Map of localized partner names $this-test( 'name', self::getLangToStrValidator() ); // Map of localized banner texts with {{PARTNER}} placeholder @@ -322,6 +328,76 @@ $this-testOptional( 'testInfoScreen', false, $isBool ); } + private function getEnabledValidator() { + $self = $this; + return function ( JCValue $jcv, array $path ) use ( $self ) { + if ( $jcv-isMissing() ) { + $jcv-setValue( true ); + $self-setEnabled( true ); + return true; + } + $v = $jcv-getValue(); + if ( is_bool( $v ) ) { + $self-setEnabled( $v ); +
[MediaWiki-commits] [Gerrit] Enabled parameter now allows enabled range - change (mediawiki...ZeroBanner)
Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/163897 Change subject: Enabled parameter now allows enabled range .. Enabled parameter now allows enabled range Enabled can now be an array of two elements, each being either a date or an integer. If first is an integer, represents number of hours since now If second is an integer, represents the duration (in hours) Change-Id: I23839878a376e73324384b042e809d668f954308 --- M i18n/en.json M i18n/qqq.json M includes/ZeroConfig.php 3 files changed, 85 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroBanner refs/changes/97/163897/1 diff --git a/i18n/en.json b/i18n/en.json index de212ca..b4d27b6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -43,6 +43,7 @@ zero-config-ipsets: Parameter \$1\ must be the name of an existing ip set declared in \ipsets\ field, zero-config-admins: Parameter \$1\ must be an existing user account, zero-config-proxies: Parameter \$1\ must be a list of proxies supporting zero-rating for this carrier, + zero-config-enabled: Parameter \$1\ must be either true, false, or a list with two timestamps. Timestamp could be in any time format. First array can also be a number of hours after (before) now, and second value can be the duration in hours., group-zeroadmin: Zero administrators, group-zeroadmin-member: {{GENDER:$1|Zero administrator}}, grouppage-zeroadmin: {{ns:project}}:Zero administrators, diff --git a/i18n/qqq.json b/i18n/qqq.json index f8e90d0..0d1cc03 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -59,6 +59,7 @@ zero-config-ipsets: ipsets parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, zero-config-admins: Admins parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, zero-config-proxies: Proxies parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, + zero-config-enabled: Enabled parameter validation error. Parameters:\n* $1 - field name\n{{Related|Zeroconfig}}, group-zeroadmin: {{doc-group|zeroadmin}}, group-zeroadmin-member: {{doc-group|zeroadmin|member}}, grouppage-zeroadmin: {{doc-group|zeroadmin|page}}, diff --git a/includes/ZeroConfig.php b/includes/ZeroConfig.php index 5801e43..caada8c 100644 --- a/includes/ZeroConfig.php +++ b/includes/ZeroConfig.php @@ -1,11 +1,16 @@ ?php namespace ZeroBanner; +use DateInterval; +use DateTime; +use DateTimeZone; use JsonConfig\JCObjContent; use JsonConfig\JCUtils; use JsonConfig\JCValidators; use JsonConfig\JCValue; +use MWTimestamp; use stdClass; +use TimestampException; /** * JSON Zero Config @@ -25,6 +30,7 @@ private $mode = null; private $ipset = null; private $proxy = null; + private $enabledValue = false; const ignoreNetwork = 0x1; const ignoreDisabled = 0x2; @@ -100,7 +106,7 @@ } public function enabled() { - return $this-config-enabled $this-getDataWithDefaults()-enabled; + return $this-enabledValue $this-getDataWithDefaults()-enabled; } public function name() { @@ -205,7 +211,7 @@ // Optional comment $this-testOptional( 'comment', '', $isString ); // Config is enabled - $this-testOptional( 'enabled', true, $isBool ); + $this-testOptional( 'enabled', true, $this-getEnabledValidator() ); // Map of localized partner names $this-test( 'name', self::getLangToStrValidator() ); // Map of localized banner texts with {{PARTNER}} placeholder @@ -322,6 +328,76 @@ $this-testOptional( 'testInfoScreen', false, $isBool ); } + private function getEnabledValidator() { + $self = $this; + return function ( JCValue $jcv, array $path ) use ( $self ) { + if ( $jcv-isMissing() ) { + $jcv-setValue( true ); + $self-setEnabled( true ); + return true; + } + $v = $jcv-getValue(); + if ( is_bool( $v ) ) { + $self-setEnabled( $v ); + return true; + } + if ( JCUtils::isList( $v ) count( $v ) === 2 ) { + /** @var DateTime[] $range */ + $range = array(); + $now = null; + foreach ( $v as $time ) { + if ( is_int( $time ) ) { + // first digit - relative to now, second