Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64548
Change subject: Use "sites" parameter to show banner
......................................................................
Use "sites" parameter to show banner
* Only shows Zero banner if "sites" allows it
* Changed sites to be a list of "m.wiki", "zero.wiki", … values
* For compatibility, all old string values except "redirect" (wasn't used) will
continue to be supported.
Change-Id: I853496a860742ba906b756b26f4c13b51bacb82f
---
M includes/CarrierConfig.php
M includes/PageRenderingHooks.php
M includes/ZeroConfig.i18n.php
3 files changed, 42 insertions(+), 9 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess
refs/changes/48/64548/1
diff --git a/includes/CarrierConfig.php b/includes/CarrierConfig.php
index 296e858..68e700e 100644
--- a/includes/CarrierConfig.php
+++ b/includes/CarrierConfig.php
@@ -130,15 +130,40 @@
$this->check( 'enabled', true, $validateBool );
//'sites' => 'both', // Which sites are whitelisted?
Could be zero, m, both, redirect
- $this->check( 'sites', 'both',
- function( $v ) {
- $validValues = array( 'zero', 'm', 'both',
'redirect' );
- return is_string( $v )
- && in_array( strtolower( $v ),
$validValues )
- ? null
- : array( 'zeroconfig-sites', "'" .
implode( "', '", $validValues ) . "'" );
+ $this->check2( 'sites', 'both',
+ function( $value ) {
+ $v = $value;
+ if ( is_string( $v ) ) {
+ $oldValues = array(
+ 'zero' => 'zero.wiki',
+ 'm' => 'm.wiki',
+ 'both' => array( 'm.wiki',
'zero.wiki' ) );
+ $v = strtolower( $v );
+ if ( array_key_exists( $v, $oldValues )
) {
+ $v = $oldValues[$v];
+ }
+ if ( is_string( $v ) ) {
+ $v = array( $v );
+ }
+ }
+ $validValues = array(
+ 'zero.wiki',
+ 'm.wiki',
+ );
+ if ( is_array( $v ) ) {
+ $v = array_map( 'strtolower', $v );
+ if ( count( array_intersect( $v,
$validValues ) ) !== count($v) ) {
+ $v = false;
+ } else {
+ $v = array_unique( $v );
+ }
+ }
+ return CarrierConfig::isArray( $v, false )
+ && count( $v ) > 0
+ && CarrierConfig::isArrayOfStrings( $v )
+ ? array( null, $v )
+ : array( array( 'zeroconfig-sites', "'"
. implode( "', '", $validValues ) . "'" ), $value );
} );
- $config['sites'] = strtolower( $this->config['sites'] );
//'name' => null, // Map of localized partner names
$this->check( 'name', null,
@@ -192,6 +217,7 @@
&& CarrierConfig::isArrayOfLangs(
array_keys( $v ) )
&& CarrierConfig::isArrayOfStrings( $v )
? null :
'zeroconfig-lang_name_overrides';
+ return array( null, $v );
} );
// Background banner color
diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 35b6efa..059983e 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -443,6 +443,13 @@
if ( !$config['enabled'] ) {
// If the configuration is
disabled, pretend like it doesn't exist
$config = null;
+ } else {
+ // Check if the wiki is in the
allowed list
+ // @TODO: expand to allow
non-wikipedia sites
+ $site = strtolower(
$wgRequest->getHeader( 'X-SUBDOMAIN' ) ) . '.wiki';
+ if ( !in_array( $site,
$config['sites'] ) ) {
+ $config = null;
+ }
}
}
}
diff --git a/includes/ZeroConfig.i18n.php b/includes/ZeroConfig.i18n.php
index 29df4f5..79ab1cb 100644
--- a/includes/ZeroConfig.i18n.php
+++ b/includes/ZeroConfig.i18n.php
@@ -28,7 +28,7 @@
'zeroconfig-lang_name_overrides' => 'must be a dictionary of valid
language codes to strings (optional)',
'zeroconfig-banner' => 'must be a dictionary of valid language codes to
strings (optional)',
'zeroconfig-banner_url' => 'must be a valid URL (optional)',
- 'zeroconfig-sites' => 'must be missing or one of these values: $1',
+ 'zeroconfig-sites' => 'must be missing or be a list with one or more of
these values: $1',
'zeroconfig-ips' => 'must be an array of valid non-restricted (no
private networks) CIDR IP blocks',
);
--
To view, visit https://gerrit.wikimedia.org/r/64548
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I853496a860742ba906b756b26f4c13b51bacb82f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits