https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113865

Revision: 113865
Author:   awjrichards
Date:     2012-03-14 21:55:22 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
* Changing how 'sticky cookies' work as well as how manually switching between 
mobile/desktop views works. If on desktop view, clicking on 'Mobile view' will 
switch the user into the mobile view, and will persist until either the cookie 
expires or user manually switches back to desktop view. Same is true for 
desktop view.
* Changed corresponding language in i18n file.
* Removed 'permanantly disable mobile view' functionality and language from 
i18n file
* Added global variable to set useformat cookie expiration length. Defaults to 
$wgCookieExpirationx

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/MobileFrontend.body.php
    trunk/extensions/MobileFrontend/MobileFrontend.i18n.php
    trunk/extensions/MobileFrontend/MobileFrontend.php

Modified: trunk/extensions/MobileFrontend/MobileFrontend.body.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.body.php     2012-03-14 
21:53:30 UTC (rev 113864)
+++ trunk/extensions/MobileFrontend/MobileFrontend.body.php     2012-03-14 
21:55:22 UTC (rev 113865)
@@ -26,7 +26,6 @@
        public static $searchField;
        public static $disableImagesURL;
        public static $enableImagesURL;
-       public static $disableMobileSiteURL;
        public static $viewNormalSiteURL;
        public static $currentURL;
        public static $displayNoticeId;
@@ -72,7 +71,6 @@
                'mobile-frontend-hide-button',
                'mobile-frontend-back-to-top-of-section',
                'mobile-frontend-regular-site',
-               'mobile-frontend-perm-stop-redirect',
                'mobile-frontend-home-button',
                'mobile-frontend-random-button',
                'mobile-frontend-are-you-sure',
@@ -231,8 +229,7 @@
 
                self::$disableImagesURL = $wgRequest->escapeAppendQuery( 
'disableImages=1' );
                self::$enableImagesURL = $wgRequest->escapeAppendQuery( 
'enableImages=1' );
-               self::$disableMobileSiteURL = $wgRequest->escapeAppendQuery( 
'mobileaction=disable_mobile_site' );
-               self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery( 
'mobileaction=view_normal_site' );
+               self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery( 
'useformat=desktop' );
                self::$currentURL = $wgRequest->getFullRequestURL();
                self::$leaveFeedbackURL = $wgRequest->escapeAppendQuery( 
'mobileaction=leave_feedback' );
 
@@ -478,12 +475,6 @@
                        exit();
                }
 
-               if ( $mobileAction == 'disable_mobile_site' && 
$this->contentFormat == 'XHTML' ) {
-                       echo $this->renderDisableMobileSiteXHTML();
-                       wfProfileOut( __METHOD__ );
-                       exit();
-               }
-
                if ( $mobileAction == 'opt_in_mobile_site' && 
$this->contentFormat == 'XHTML' ) {
                        echo $this->renderOptInMobileSiteXHTML();
                        wfProfileOut( __METHOD__ );
@@ -858,54 +849,6 @@
        }
 
        /**
-        * @return string
-        */
-       private function renderDisableMobileSiteXHTML() {
-               wfProfileIn( __METHOD__ );
-               if ( $this->contentFormat == 'XHTML' ) {
-                       $this->getMsg();
-                       $areYouSure = 
self::$messages['mobile-frontend-are-you-sure'];
-                       $explainDisable = 
self::$messages['mobile-frontend-explain-disable'];
-                       $disableButton = 
self::$messages['mobile-frontend-disable-button'];
-                       $backButton = 
self::$messages['mobile-frontend-back-button'];
-                       $htmlTitle = $areYouSure;
-                       $title = $areYouSure;
-                       $searchTemplate = $this->getSearchTemplate();
-                       $searchWebkitHtml = $searchTemplate->getHTML();
-                       $footerTemplate = $this->getFooterTemplate();
-                       $footerHtml = $footerTemplate->getHTML();
-                       $disableTemplate = new DisableTemplate();
-                       $options = array(
-                                                       'currentURL' => 
self::$currentURL,
-                                                       
'mobileRedirectFormAction' => self::$mobileRedirectFormAction,
-                                                       'areYouSure' => 
$areYouSure,
-                                                       'explainDisable' => 
$explainDisable,
-                                                       'disableButton' => 
$disableButton,
-                                                       'backButton' => 
$backButton,
-                                                       'htmlTitle' => 
$htmlTitle,
-                                                       'title' => $title,
-                                                       );
-                       $disableTemplate->setByArray( $options );
-                       $disableHtml = $disableTemplate->getHTML();
-
-                       $contentHtml = $disableHtml;
-                       $applicationTemplate = $this->getApplicationTemplate();
-                       $options = array(
-                                                       'htmlTitle' => 
$htmlTitle,
-                                                       'searchWebkitHtml' => 
$searchWebkitHtml,
-                                                       'contentHtml' => 
$contentHtml,
-                                                       'footerHtml' => 
$footerHtml,
-                                                       );
-                       $applicationTemplate->setByArray( $options );
-                       $applicationHtml = $applicationTemplate->getHTML();
-                       wfProfileOut( __METHOD__ );
-                       return $applicationHtml;
-               }
-               wfProfileOut( __METHOD__ );
-               return '';
-       }
-
-       /**
         * @return DomElement
         */
        public function renderLogin() {
@@ -1166,7 +1109,6 @@
                $options = array(
                                                'messages' => self::$messages,
                                                'leaveFeedbackURL' => 
self::$leaveFeedbackURL,
-                                               'disableMobileSiteURL' => 
self::$disableMobileSiteURL,
                                                'viewNormalSiteURL' => 
self::$viewNormalSiteURL,
                                                'disableImages' => 
self::$disableImages,
                                                'disableImagesURL' => 
self::$disableImagesURL,
@@ -1443,15 +1385,20 @@
        }
        
        protected function shouldDisplayMobileView() {
-               if ( !$this->isMobileDevice() && !$this->isFauxMobileDevice() ) 
{
+               // always display desktop view if it's explicitly requested
+               $useFormat = $this->getUseFormat();
+               if ( $useFormat == 'desktop' ) {
                        return false;
                }
+
+               if ( !$this->isMobileDevice() && !$this->isFauxMobileDevice() ) 
{
+                       return false;
+               }               
                
                $action = $this->getAction();
-               $mobileAction = $this->getMobileAction();
                
-               if ( $action === 'edit' || $action === 'history' ||
-                        $mobileAction === 'view_normal_site' ) {
+               
+               if ( $action === 'edit' || $action === 'history' ) {
                        return false;
                }
                                
@@ -1503,29 +1450,35 @@
                
                $useFormat = $this->getUseFormat();
                $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' );
+               
+               // fetch format from cookie and set it if one is not otherwise 
specified
                if( !strlen( $useFormat ) && !is_null( $useFormatFromCookie ) ) 
{
                        $this->setUseFormat( $useFormatFromCookie );
                }
                
-               // if we should not be displaying the mobile view, make sure 
cookies are unset etc.
-               if ( !$this->shouldDisplayMobileView() ) {
-                       // make sure cookie is unset for appropriate mobile 
actions
-                       $mobileAction = $this->getMobileAction();
-                       if ( in_array( $mobileAction, array( 
'view_normal_site', 'disable_mobile_site' ) ) ) {
-                               $wgRequest->response()->setCookie( 
'mf_useformat', false, time() - 3600 );
-                       }
-                       
-                       // make sure useformat is unset
-                       $this->setUseFormat( '' );
-                       return;
+               // set appropriate cookie if necessary
+               if ( ( $useFormatFromCookie != 'mobile' && $useFormat == 
'mobile' ) ||
+                               ( $useFormatFromCookie != 'desktop' && 
$useFormat == 'desktop' ) ) {
+                       $this->setUseFormatCookie( $useFormat );
                }
-               
-               // if getUseFormat and no cookie set, set the cookie
-               if ( is_null( $useFormatFromCookie ) && strlen( $useFormat ) ) {
-                       $wgRequest->response()->setCookie( 'mf_useformat', 
$useFormat, 0 );
-               }
        }
        
+       /**
+        * Set the mf_useformat cookie
+        * 
+        * This cookie can determine whether or not a user should see the mobile
+        * version of pages.
+        *
+        * @param string The format to store in the cookie
+        */
+       protected function setUseFormatCookie( $useFormat ) {
+               global $wgRequest, $wgCookieExpiration, 
$wgMobileFrontendFormatCookieExpiry;
+               $cookieDuration = ( $wgMobileFrontendFormatCookieExpiry ) ? 
+                               $wgMobileFrontendFormatCookieExpiry : 
$wgCookieExpiration;
+               $expire = time() + $cookieDuration;
+               $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, 
$expire );
+       }
+       
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }

Modified: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.i18n.php     2012-03-14 
21:53:30 UTC (rev 113864)
+++ trunk/extensions/MobileFrontend/MobileFrontend.i18n.php     2012-03-14 
21:55:22 UTC (rev 113865)
@@ -26,8 +26,7 @@
        'mobile-frontend-hide-button' => 'Hide',
        'mobile-frontend-disable-button' => 'Disable',
        'mobile-frontend-back-button' => 'Back',
-       'mobile-frontend-regular-site' => 'View this page on regular 
{{SITENAME}}',
-       'mobile-frontend-perm-stop-redirect' => 'Permanently disable mobile 
site',
+       'mobile-frontend-regular-site' => 'Desktop view',
        'mobile-frontend-error-page-title' => 'We have a problem!',
        'mobile-frontend-error-page-text' => '{{SITENAME}} mobile is still 
under active development and we are working hard to fix all of our internal 
errors. We have been notified about this error and will be fixing it soon. 
Please check back!',
        'mobile-frontend-are-you-sure' => 'Are you sure?',

Modified: trunk/extensions/MobileFrontend/MobileFrontend.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.php  2012-03-14 21:53:30 UTC 
(rev 113864)
+++ trunk/extensions/MobileFrontend/MobileFrontend.php  2012-03-14 21:55:22 UTC 
(rev 113865)
@@ -104,6 +104,16 @@
 $wgMobileUrlTemplate = '';
 
 /**
+ * The number of seconds the 'useformat' cookie should be valid
+ * 
+ * The useformat cookie gets set when a user manually elects to view
+ * either the mobile or desktop view of the site.
+ *
+ * If this value is not set, it will default to $wgCookieExpiration
+ */
+$wgMobileFrontendFormatCookieExpiry;
+
+/**
  * URL for script used to disable mobile site
  * (protocol, host, optional port; path portion)
  *


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

Reply via email to