Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/69280
Change subject: Allow debug params X-CS and X-SUBDOMAIN in URL ...................................................................... Allow debug params X-CS and X-SUBDOMAIN in URL * Having X-CS in URL overrides the X-CS header and ignores the 'enabled' parameter of the zero configuration * Having X-SUBDOMAIN in URL overrides header with the same name Change-Id: Ifc869adea24f3b9d27918557ac7fa954e406c7d0 --- M includes/PageRenderingHooks.php 1 file changed, 13 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess refs/changes/80/69280/1 diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php index d7e5346..1017af7 100644 --- a/includes/PageRenderingHooks.php +++ b/includes/PageRenderingHooks.php @@ -498,7 +498,8 @@ $config = null; // Allow URL override of the X-CS parameter for testing purposes $id = $wgRequest->getVal( 'X-CS' ); - if ( $id === null ) { + $isDebug = $id !== null; + if ( !$isDebug ) { $id = $wgRequest->getHeader( 'X-CS' ); } if ( $id === '(null)' || !$id ) { @@ -511,7 +512,7 @@ $conf = new CarrierConfig( $text ); if ( !$conf->isError() ) { $config = $conf->getData(); - if ( !self::isZeroEnabled( $config ) ) { + if ( !self::isZeroEnabled( $config, $isDebug ) ) { $config = null; } } @@ -525,18 +526,17 @@ * As part of self::getConfig(), determine if zero should be enabled * for this site based on configuration * @param array $config + * @param bool $isDebug If true, overrides 'enabled' config value * @return bool */ - private static function isZeroEnabled( $config ) { - if ( !$config['enabled'] ) { + private static function isZeroEnabled( $config, $isDebug ) { + if ( !$isDebug && !$config['enabled'] ) { // If the configuration is disabled, pretend like it doesn't exist return false; } // Check if the wiki is in the allowed list // @FIXME: expand to allow non-wikipedia sites - global $wgRequest; - $subdomain = $wgRequest->getHeader( 'X-SUBDOMAIN' ); - $site = strtolower( $subdomain ) . '.wikipedia'; + $site = self::isZeroSubdomain() ? 'zero.wikipedia' : 'm.wikipedia'; if ( !in_array( $site, $config['sites'] ) ) { return false; } @@ -563,7 +563,12 @@ static $isZero = null; if ( $isZero === null ) { global $wgRequest; - $isZero = $wgRequest->getHeader( 'X-SUBDOMAIN' ) === 'ZERO'; + // Allow URL override for testing purposes + $subdomain = $wgRequest->getVal( 'X-SUBDOMAIN' ); + if ( $subdomain === null ) { + $subdomain = $wgRequest->getHeader( 'X-SUBDOMAIN' ); + } + $isZero = strcasecmp( $subdomain, 'ZERO' ) === 0; } return $isZero; } -- To view, visit https://gerrit.wikimedia.org/r/69280 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifc869adea24f3b9d27918557ac7fa954e406c7d0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess Gerrit-Branch: master Gerrit-Owner: Yurik <yu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits