Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/63003


Change subject: Bug 44133: Cleanup how we do config
......................................................................

Bug 44133: Cleanup how we do config

Document where a config variable should be added better
Carefully move around config variables. Refactor
unset_stopmobileredirect.js so it doesn't introduce another
unnecessary variable

Bug: 44133

Change-Id: I126aadd503d233247b783af7bc4fcf13070a1299
---
M includes/MobileFrontend.hooks.php
M includes/skins/SkinMinerva.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileBase.php
M javascripts/desktop/unset_stopmobileredirect.js
5 files changed, 66 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/03/63003/1

diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index a91b770..374ba05 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -58,6 +58,8 @@
 
        /**
         * MakeGlobalVariablesScript hook handler
+        * Adds global variables to Minerva skin in both desktop and mobile 
mode that
+        * vary depending on what page you are on
         * @see 
http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
         * Adds various mobile specific config variables
         *
@@ -66,47 +68,18 @@
         * @return boolean
         */
        public static function onMakeGlobalVariablesScript( &$vars, $out ) {
-               global $wgMFPhotoUploadEndpoint, $wgCookiePath,
-                       $wgMFPhotoUploadAppendToDesc, $wgMFLoginHandshakeUrl;
+               $skin = $out->getSkin()->skinname;
+               if ( $skin === 'minerva' ) {
+                       $title = $out->getTitle();
+                       $user = $out->getUser();
+                       if ( !$user->isAnon() ) {
+                               $vars[ 'wgWatchedPageCache' ] = array(
+                                       $title->getText() => $user->isWatched( 
$title ),
+                               );
+                       }
 
-               $context = MobileContext::singleton();
-               $title = $out->getTitle();
-               $user = $out->getUser();
-               if ( !$user->isAnon() ) {
-                       $vars[ 'wgWatchedPageCache' ] = array(
-                               $title->getText() => $user->isWatched( $title ),
-                       );
-               }
-               $vars[ 'wgMFPhotoUploadEndpoint' ] = $wgMFPhotoUploadEndpoint ? 
$wgMFPhotoUploadEndpoint : '';
-               // cookie specific
-               $vars[ 'wgUseFormatCookie' ] = array(
-                       'name' => $context->getUseFormatCookieName(),
-                       'duration' => -1, // in days
-                       'path' => $wgCookiePath,
-                       'domain' => $_SERVER['HTTP_HOST'],
-               );
-               $vars[ 'wgStopMobileRedirectCookie' ] = array(
-                       'name' => 'stopMobileRedirect',
-                       'duration' => $context->getUseFormatCookieDuration() / 
( 24 * 60 * 60 ), // in days
-                       'domain' => 
$context->getStopMobileRedirectCookieDomain(),
-                       'path' => $wgCookiePath,
-               );
-               $vars[ 'wgMFPhotoUploadAppendToDesc' ] = 
$wgMFPhotoUploadAppendToDesc;
-               $vars[ 'wgImagesDisabled' ] = $context->imagesDisabled();
-
-               if ( $context->isAlphaGroupMember() ) {
-                       $env = 'alpha';
-               } else if ( $context->isBetaGroupMember() ) {
-                       $env = 'beta';
-               } else {
-                       $env = 'stable';
-               }
-               $vars[ 'wgMFMode' ] = $env;
-               $vars[ 'wgIsPageEditable' ] = $user->isAllowed( 'edit' ) && 
$title->getNamespace() == NS_MAIN;
-               $vars[ 'wgPreferredVariant' ] = 
$title->getPageLanguage()->getPreferredVariant();
-
-               if ( $wgMFLoginHandshakeUrl ) {
-                       $vars[ 'wgMFLoginHandshakeUrl' ] = 
$wgMFLoginHandshakeUrl;
+                       $vars[ 'wgIsPageEditable' ] = $user->isAllowed( 'edit' 
) && $title->getNamespace() == NS_MAIN;
+                       $vars[ 'wgPreferredVariant' ] = 
$title->getPageLanguage()->getPreferredVariant();
                }
 
                return true;
@@ -320,18 +293,36 @@
 
        /**
         * ResourceLoaderGetConfigVars hook handler
+        * This should be used for variables which vary with the html
+        * and for variables this should work cross skin
         * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
         *
         * @param array $vars
         * @return boolean
         */
        public static function onResourceLoaderGetConfigVars( &$vars ) {
-               global $wgCookiePath, $wgMFEnablePhotoUploadCTA, 
$wgMFNearbyEndpoint, $wgMFAnonymousEditing;
-               $vars['wgCookiePath'] = $wgCookiePath;
-               $vars['wgMFStopRedirectCookieHost'] = 
MobileContext::singleton()->getStopMobileRedirectCookieDomain();
-               $vars['wgMFEnablePhotoUploadCTA'] = $wgMFEnablePhotoUploadCTA;
+               global $wgCookiePath, $wgMFNearbyEndpoint;
+               $ctx = MobileContext::singleton();
+               $wgStopMobileRedirectCookie = array(
+                       'name' => 'stopMobileRedirect',
+                       'duration' => $ctx->getUseFormatCookieDuration() / ( 24 
* 60 * 60 ), // in days
+                       'domain' => $ctx->getStopMobileRedirectCookieDomain(),
+                       'path' => $wgCookiePath,
+               );
+               $vars['wgStopMobileRedirectCookie'] = 
$wgStopMobileRedirectCookie;
                $vars['wgMFNearbyEndpoint'] = $wgMFNearbyEndpoint;
-               $vars['wgMFAnonymousEditing'] = $wgMFAnonymousEditing;
+               // mobile specific config variables
+               if ( $ctx->shouldDisplayMobileView() ) {
+                       $vars[ 'wgImagesDisabled' ] = $ctx->imagesDisabled();
+                       if ( $ctx->isAlphaGroupMember() ) {
+                               $env = 'alpha';
+                       } else if ( $ctx->isBetaGroupMember() ) {
+                               $env = 'beta';
+                       } else {
+                               $env = 'stable';
+                       }
+                       $vars[ 'wgMFMode' ] = $env;
+               }
                return true;
        }
 
@@ -394,7 +385,7 @@
         * @return bool
         */
        public static function onSpecialPageBeforeExecute( SpecialPage 
$special, $subpage ) {
-               global $wgMFForceSecureLogin;
+               global $wgMFForceSecureLogin, $wgMFLoginHandshakeUrl;
                $mobileContext = MobileContext::singleton();
                if ( $special->getName() != 'Userlogin' || 
!$mobileContext->shouldDisplayMobileView() ) {
                        // no further processing necessary
@@ -403,6 +394,9 @@
                        $out = $special->getContext()->getOutput();
                        $out->addModules( 'mobile.userlogin.scripts' );
                        $out->addModuleStyles( 'mobile.userlogin.styles' );
+                       if ( $wgMFLoginHandshakeUrl ) {
+                               $out->addJsConfigVars( 'wgMFLoginHandshakeUrl', 
$wgMFLoginHandshakeUrl );
+                       }
                }
 
                // make sure we're on https if we're supposed to be and 
currently aren't.
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 04bf2a9..6ff13dd 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -25,9 +25,15 @@
        }
 
        public function getConfigVariables() {
-               global $wgMFLeadPhotoUploadCssSelector;
+               global $wgMFLeadPhotoUploadCssSelector, $wgMFAnonymousEditing, 
$wgMFEnablePhotoUploadCTA,
+                       $wgMFPhotoUploadEndpoint, $wgMFPhotoUploadAppendToDesc;
+
                return array(
+                       'wgMFAnonymousEditing' => $wgMFAnonymousEditing,
+                       'wgMFEnablePhotoUploadCTA' => $wgMFEnablePhotoUploadCTA,
+                       'wgMFPhotoUploadAppendToDesc' => 
$wgMFPhotoUploadAppendToDesc,
                        'wgMFLeadPhotoUploadCssSelector' => 
$wgMFLeadPhotoUploadCssSelector,
+                       'wgMFPhotoUploadEndpoint' => $wgMFPhotoUploadEndpoint ? 
$wgMFPhotoUploadEndpoint : '',
                );
        }
 
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index ea72319..a3809cf 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -1,8 +1,6 @@
 <?php
 
 class SkinMobile extends SkinMobileBase {
-       public $skinname = 'mobile';
-       public $stylename = 'mobile';
        public $template = 'SkinMobileTemplate';
 
        protected function prepareTemplate() {
diff --git a/includes/skins/SkinMobileBase.php 
b/includes/skins/SkinMobileBase.php
index be497f8..a4b1166 100644
--- a/includes/skins/SkinMobileBase.php
+++ b/includes/skins/SkinMobileBase.php
@@ -10,6 +10,19 @@
        /** @var array of classes that should be present on the body tag */
        private $pageClassNames = array();
 
+       public function getConfigVariables() {
+               global $wgCookiePath;
+               $ctx = MobileContext::singleton();
+               $wgUseFormatCookie = array(
+                       'name' => $ctx->getUseFormatCookieName(),
+                       'duration' => -1, // in days
+                       'path' => $wgCookiePath,
+                       'domain' => $_SERVER['HTTP_HOST'],
+               );
+               $vars = parent::getConfigVariables();
+               $vars['wgUseFormatCookie'] = $wgUseFormatCookie;
+               return $vars;
+       }
        /**
         * This will be called by OutputPage::headElement when it is creating 
the
         * "<body>" tag, - adds output property bodyClassName to the existing 
classes
diff --git a/javascripts/desktop/unset_stopmobileredirect.js 
b/javascripts/desktop/unset_stopmobileredirect.js
index 5ad6f0d..70dda93 100644
--- a/javascripts/desktop/unset_stopmobileredirect.js
+++ b/javascripts/desktop/unset_stopmobileredirect.js
@@ -1,9 +1,9 @@
 // hijack the link on desktop site to mobile view and unset stopMobileRedirect 
cookie
 ( function( $ ) {
-       $( '.stopMobileRedirectToggle' ).click( function() {
-               var hostname = mw.config.get( 'wgMFStopRedirectCookieHost' ),
-                       path = mw.config.get( 'wgCookiePath' );
-
-               $.cookie( 'stopMobileRedirect', null, { path: path, domain: 
hostname } );
-       });
+       var cookie = mw.config.get( 'wgStopMobileRedirectCookie' );
+       if ( cookie ) {
+               $( '.stopMobileRedirectToggle' ).click( function() {
+                       $.cookie( cookie.name, null, { path: cookie.path, 
domain: cookie.domain } );
+               } );
+       }
 } )( jQuery );

-- 
To view, visit https://gerrit.wikimedia.org/r/63003
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I126aadd503d233247b783af7bc4fcf13070a1299
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to