Bmansurov has uploaded a new change for review. https://gerrit.wikimedia.org/r/247547
Change subject: WIP: Save settings across devices ...................................................................... WIP: Save settings across devices Change-Id: Iaf5754eb803d4b46d29a6d3cc73bc51ad49626f0 --- M includes/MobileContext.php M includes/MobileFrontend.hooks.php 2 files changed, 26 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/47/247547/1 diff --git a/includes/MobileContext.php b/includes/MobileContext.php index ad60ca2..f553fa5 100644 --- a/includes/MobileContext.php +++ b/includes/MobileContext.php @@ -8,6 +8,8 @@ */ class MobileContext extends ContextSource { const USEFORMAT_COOKIE_NAME = 'mf_useformat'; + const USER_MODE_PREFERENCE_NAME = 'mfMode'; + const USER_IMAGE_PREFERENCE_NAME = 'mfDisableImages'; /** * Saves the testing mode user has opted in: 'beta' or 'stable' * @var string $mobileMode @@ -162,6 +164,7 @@ public function imagesDisabled() { if ( is_null( $this->disableImages ) ) { $this->disableImages = (bool)$this->getRequest()->getCookie( 'disableImages' ); + $this->getUser()->setOption( self::USER_IMAGE_PREFERENCE_NAME, $this->disableImages ); } return $this->disableImages; @@ -280,11 +283,16 @@ return true; } + private function loadMobileModeCookie() { + $req = $this->getRequest(); + $this->mobileMode = $req->getCookie( 'optin', '' ); + } + /** * Returns the testing mode user has opted in: 'beta' or any other value for stable * @return string */ - public function getMobileMode() { + protected function getMobileMode() { $enableBeta = $this->getMFConfig()->get( 'MFEnableBeta' ); if ( !$enableBeta ) { @@ -295,8 +303,19 @@ if ( $mobileAction === 'beta' || $mobileAction === 'stable' ) { $this->mobileMode = $mobileAction; } else { - $req = $this->getRequest(); - $this->mobileMode = $req->getCookie( 'optin', '' ); + $user = $this->getUser(); + if ( $user->isAnon() ) { + $this->loadMobileModeCookie(); + } else { + $mode = $user->getOption( self::USER_MODE_PREFERENCE_NAME ); + $this->mobileMode = $mode; + // Edge case where preferences are corrupt or the user opted + // in before change. + if ( $mode === null ) { + // Should we set the user option here? + $this->loadMobileModeCookie(); + } + } } } return $this->mobileMode; @@ -318,6 +337,9 @@ wfIncrStats( 'mobile.opt_in_cookie_unset' ); } $this->mobileMode = $mode; + $user = $this->getUser(); + $user->setOption( self::USER_MODE_PREFERENCE_NAME, $mode ); + $user->saveSettings(); $host = $this->getBaseDomain(); // Deal with people running off localhost. see http://curl.haxx.se/rfc/cookie_spec.html @@ -334,6 +356,7 @@ * @return boolean */ public function isBetaGroupMember() { +// wfVarDump($this->getUser()); return $this->getMobileMode() === 'beta'; } diff --git a/includes/MobileFrontend.hooks.php b/includes/MobileFrontend.hooks.php index 4c17e4d..3dc9884 100644 --- a/includes/MobileFrontend.hooks.php +++ b/includes/MobileFrontend.hooks.php @@ -108,11 +108,6 @@ $name = $context->getTitle()->getDBkey(); $inTestMode = $name === SpecialPage::getTitleFor( 'JavaScriptTest', 'qunit' )->getDBkey(); - // FIXME: remove the migration code below at some point. - // alpha no more, fallback to beta - if ( $mobileContext->getMobileMode() === 'alpha' ) { - $mobileContext->setMobileMode( 'beta' ); - } if ( $mobileContext->isBetaGroupMember() && class_exists( $betaSkinName ) ) { $skinName = $betaSkinName; } -- To view, visit https://gerrit.wikimedia.org/r/247547 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaf5754eb803d4b46d29a6d3cc73bc51ad49626f0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits