jenkins-bot has submitted this change and it was merged.
Change subject: Allow opt in to lazy loaded images via cookie
......................................................................
Allow opt in to lazy loaded images via cookie
When the cookie `mfLazyLoadImages` is set to 'A' enable lazy loaded
images. This will allow us to randomly allocate users to the experiment
for measurement purposes.
Changes:
* Simplifies config variable passed to client so client uses same logic
as server side
* Use onMakeGlobalVariablesScript hook to bake variable in HTML so it varies
for stable/beta users
Bug: T127883
Change-Id: Iaa5ed38c712b19e5582ed08e39e6e34a0e88ff11
---
M includes/MobileContext.php
M includes/MobileFrontend.body.php
M includes/MobileFrontend.hooks.php
M resources/mobile.startup/Skin.js
4 files changed, 34 insertions(+), 17 deletions(-)
Approvals:
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index d972cd3..9905cdd 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -9,6 +9,8 @@
class MobileContext extends ContextSource {
const USEFORMAT_COOKIE_NAME = 'mf_useformat';
const USER_MODE_PREFERENCE_NAME = 'mfMode';
+ const LAZY_LOAD_IMAGES_COOKIE_NAME = 'mfLazyLoadImages';
+ const LAZY_LOAD_IMAGES_COOKIE_VALUE = 'A';
/**
* Saves the testing mode user has opted in: 'beta' or 'stable'
@@ -20,6 +22,11 @@
* @var boolean $disableImages
*/
protected $disableImages;
+ /**
+ * Save whether images will be lazy loaded for current user
+ * @var boolean $lazyLoadImages
+ */
+ protected $lazyLoadImages;
/**
* Save explicitly requested format
* @var string $useFormat
@@ -158,6 +165,22 @@
}
/**
+ * Checks whether images should be lazy loaded for the current user
+ * @return bool
+ */
+ public function isLazyLoadImagesEnabled() {
+ if ( $this->lazyLoadImages === null ) {
+ $mfLazyLoadImages = $this->getMFConfig()->get(
'MFLazyLoadImages' );
+ $cookie = $this->getRequest()->getCookie(
self::LAZY_LOAD_IMAGES_COOKIE_NAME, '' );
+ $removeImages = $mfLazyLoadImages['base'] ||
+ ( $this->isBetaGroupMember() &&
$mfLazyLoadImages['beta'] ) ||
+ $cookie === self::LAZY_LOAD_IMAGES_COOKIE_VALUE;
+ $this->lazyLoadImages = $removeImages;
+ }
+ return $this->lazyLoadImages;
+ }
+
+ /**
* Checks whether images are disabled for the current user
* @return bool
*/
diff --git a/includes/MobileFrontend.body.php b/includes/MobileFrontend.body.php
index 928f797..5b67396 100644
--- a/includes/MobileFrontend.body.php
+++ b/includes/MobileFrontend.body.php
@@ -58,10 +58,8 @@
);
$mfLazyLoadReferences = $config->get( 'MFLazyLoadReferences' );
- $mfLazyLoadImages = $config->get( 'MFLazyLoadImages' );
- $removeImages = $mfLazyLoadImages['base'] ||
- ( $isBeta && $mfLazyLoadImages['beta'] );
+ $removeImages = $context->isLazyLoadImagesEnabled();
$removeReferences = $mfLazyLoadReferences['base'] ||
( $isBeta && $mfLazyLoadReferences['beta'] );
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index f5c1e0a..5dfb742 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -184,11 +184,8 @@
public static function onSkinAfterBottomScripts( $sk, &$html ) {
$context = MobileContext::singleton();
- $mfLazyLoadImages = $context->getMFConfig()->get(
'MFLazyLoadImages' );
- $removeImages = $mfLazyLoadImages['base'] ||
- ( $context->isBetaGroupMember() &&
$mfLazyLoadImages['beta'] );
- if ( $removeImages ) {
+ if ( $context->isLazyLoadImagesEnabled() ) {
$html .= Html::inlineScript( ResourceLoader::filter(
'minify-js',
MobileFrontendSkinHooks::gradeCImageSupport()
) );
@@ -384,6 +381,10 @@
return;
}
+ if ( $context->isLazyLoadImagesEnabled() ) {
+ $confstr .= '!lazyloadimages';
+ }
+
if ( $context->imagesDisabled() ) {
$confstr .= '!noimg';
}
@@ -468,7 +469,6 @@
'wgMFEditorOptions' => $config->get( 'MFEditorOptions'
),
'wgMFLicense' => MobileFrontendSkinHooks::getLicense(
'editor' ),
'wgMFSchemaEditSampleRate' => $config->get(
'MFSchemaEditSampleRate' ),
- 'wgMFLazyLoadImages' => $config->get(
'MFLazyLoadImages' ),
'wgMFLazyLoadReferences' => $config->get(
'MFLazyLoadReferences' ),
'wgMFSchemaMobileWebLanguageSwitcherSampleRate' =>
$config->get(
'MFSchemaMobileWebLanguageSwitcherSampleRate' ),
@@ -1323,6 +1323,7 @@
if ( $context->shouldDisplayMobileView() ){
unset( $vars['wgCategories'] );
$vars['wgMFMode'] = $context->isBetaGroupMember() ?
'beta' : 'stable';
+ $vars['wgMFLazyLoadImages'] =
$context->isLazyLoadImagesEnabled();
}
$title = $out->getTitle();
$vars['wgPreferredVariant'] =
$title->getPageLanguage()->getPreferredVariant();
diff --git a/resources/mobile.startup/Skin.js b/resources/mobile.startup/Skin.js
index 0d5442b..2f1b973 100644
--- a/resources/mobile.startup/Skin.js
+++ b/resources/mobile.startup/Skin.js
@@ -2,8 +2,7 @@
var browser = M.require( 'mobile.browser/browser' ),
View = M.require( 'mobile.view/View' ),
- Icon = M.require( 'mobile.startup/Icon' ),
- context = M.require( 'mobile.context/context' );
+ Icon = M.require( 'mobile.startup/Icon' );
/**
* Representation of the current skin being rendered.
@@ -14,9 +13,7 @@
* @uses Page
*/
function Skin( options ) {
- var self = this,
- isBeta = context.isBetaGroupMember(),
- wgMFLazyLoadImages = mw.config.get(
'wgMFLazyLoadImages' );
+ var self = this;
this.page = options.page;
this.name = options.name;
@@ -47,10 +44,8 @@
this.emit( '_resize' );
if (
- !mw.config.get( 'wgImagesDisabled' ) && (
- wgMFLazyLoadImages.base ||
- ( isBeta && wgMFLazyLoadImages.beta )
- )
+ !mw.config.get( 'wgImagesDisabled' ) &&
+ mw.config.get( 'wgMFLazyLoadImages' )
) {
$( function () {
self.loadImages();
--
To view, visit https://gerrit.wikimedia.org/r/279076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa5ed38c712b19e5582ed08e39e6e34a0e88ff11
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits