r113865 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113864‎ | r113865 | r113866 >
Date:21:55, 14 March 2012
Author:awjrichards
Status:resolved (Comments)
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.i18n.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php
@@ -26,7 +26,6 @@
2727 public static $searchField;
2828 public static $disableImagesURL;
2929 public static $enableImagesURL;
30 - public static $disableMobileSiteURL;
3130 public static $viewNormalSiteURL;
3231 public static $currentURL;
3332 public static $displayNoticeId;
@@ -72,7 +71,6 @@
7372 'mobile-frontend-hide-button',
7473 'mobile-frontend-back-to-top-of-section',
7574 'mobile-frontend-regular-site',
76 - 'mobile-frontend-perm-stop-redirect',
7775 'mobile-frontend-home-button',
7876 'mobile-frontend-random-button',
7977 'mobile-frontend-are-you-sure',
@@ -231,8 +229,7 @@
232230
233231 self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' );
234232 self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' );
235 - self::$disableMobileSiteURL = $wgRequest->escapeAppendQuery( 'mobileaction=disable_mobile_site' );
236 - self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery( 'mobileaction=view_normal_site' );
 233+ self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery( 'useformat=desktop' );
237234 self::$currentURL = $wgRequest->getFullRequestURL();
238235 self::$leaveFeedbackURL = $wgRequest->escapeAppendQuery( 'mobileaction=leave_feedback' );
239236
@@ -478,12 +475,6 @@
479476 exit();
480477 }
481478
482 - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) {
483 - echo $this->renderDisableMobileSiteXHTML();
484 - wfProfileOut( __METHOD__ );
485 - exit();
486 - }
487 -
488479 if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) {
489480 echo $this->renderOptInMobileSiteXHTML();
490481 wfProfileOut( __METHOD__ );
@@ -858,54 +849,6 @@
859850 }
860851
861852 /**
862 - * @return string
863 - */
864 - private function renderDisableMobileSiteXHTML() {
865 - wfProfileIn( __METHOD__ );
866 - if ( $this->contentFormat == 'XHTML' ) {
867 - $this->getMsg();
868 - $areYouSure = self::$messages['mobile-frontend-are-you-sure'];
869 - $explainDisable = self::$messages['mobile-frontend-explain-disable'];
870 - $disableButton = self::$messages['mobile-frontend-disable-button'];
871 - $backButton = self::$messages['mobile-frontend-back-button'];
872 - $htmlTitle = $areYouSure;
873 - $title = $areYouSure;
874 - $searchTemplate = $this->getSearchTemplate();
875 - $searchWebkitHtml = $searchTemplate->getHTML();
876 - $footerTemplate = $this->getFooterTemplate();
877 - $footerHtml = $footerTemplate->getHTML();
878 - $disableTemplate = new DisableTemplate();
879 - $options = array(
880 - 'currentURL' => self::$currentURL,
881 - 'mobileRedirectFormAction' => self::$mobileRedirectFormAction,
882 - 'areYouSure' => $areYouSure,
883 - 'explainDisable' => $explainDisable,
884 - 'disableButton' => $disableButton,
885 - 'backButton' => $backButton,
886 - 'htmlTitle' => $htmlTitle,
887 - 'title' => $title,
888 - );
889 - $disableTemplate->setByArray( $options );
890 - $disableHtml = $disableTemplate->getHTML();
891 -
892 - $contentHtml = $disableHtml;
893 - $applicationTemplate = $this->getApplicationTemplate();
894 - $options = array(
895 - 'htmlTitle' => $htmlTitle,
896 - 'searchWebkitHtml' => $searchWebkitHtml,
897 - 'contentHtml' => $contentHtml,
898 - 'footerHtml' => $footerHtml,
899 - );
900 - $applicationTemplate->setByArray( $options );
901 - $applicationHtml = $applicationTemplate->getHTML();
902 - wfProfileOut( __METHOD__ );
903 - return $applicationHtml;
904 - }
905 - wfProfileOut( __METHOD__ );
906 - return '';
907 - }
908 -
909 - /**
910853 * @return DomElement
911854 */
912855 public function renderLogin() {
@@ -1166,7 +1109,6 @@
11671110 $options = array(
11681111 'messages' => self::$messages,
11691112 'leaveFeedbackURL' => self::$leaveFeedbackURL,
1170 - 'disableMobileSiteURL' => self::$disableMobileSiteURL,
11711113 'viewNormalSiteURL' => self::$viewNormalSiteURL,
11721114 'disableImages' => self::$disableImages,
11731115 'disableImagesURL' => self::$disableImagesURL,
@@ -1443,15 +1385,20 @@
14441386 }
14451387
14461388 protected function shouldDisplayMobileView() {
1447 - if ( !$this->isMobileDevice() && !$this->isFauxMobileDevice() ) {
 1389+ // always display desktop view if it's explicitly requested
 1390+ $useFormat = $this->getUseFormat();
 1391+ if ( $useFormat == 'desktop' ) {
14481392 return false;
14491393 }
 1394+
 1395+ if ( !$this->isMobileDevice() && !$this->isFauxMobileDevice() ) {
 1396+ return false;
 1397+ }
14501398
14511399 $action = $this->getAction();
1452 - $mobileAction = $this->getMobileAction();
14531400
1454 - if ( $action === 'edit' || $action === 'history' ||
1455 - $mobileAction === 'view_normal_site' ) {
 1401+
 1402+ if ( $action === 'edit' || $action === 'history' ) {
14561403 return false;
14571404 }
14581405
@@ -1503,29 +1450,35 @@
15041451
15051452 $useFormat = $this->getUseFormat();
15061453 $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' );
 1454+
 1455+ // fetch format from cookie and set it if one is not otherwise specified
15071456 if( !strlen( $useFormat ) && !is_null( $useFormatFromCookie ) ) {
15081457 $this->setUseFormat( $useFormatFromCookie );
15091458 }
15101459
1511 - // if we should not be displaying the mobile view, make sure cookies are unset etc.
1512 - if ( !$this->shouldDisplayMobileView() ) {
1513 - // make sure cookie is unset for appropriate mobile actions
1514 - $mobileAction = $this->getMobileAction();
1515 - if ( in_array( $mobileAction, array( 'view_normal_site', 'disable_mobile_site' ) ) ) {
1516 - $wgRequest->response()->setCookie( 'mf_useformat', false, time() - 3600 );
1517 - }
1518 -
1519 - // make sure useformat is unset
1520 - $this->setUseFormat( '' );
1521 - return;
 1460+ // set appropriate cookie if necessary
 1461+ if ( ( $useFormatFromCookie != 'mobile' && $useFormat == 'mobile' ) ||
 1462+ ( $useFormatFromCookie != 'desktop' && $useFormat == 'desktop' ) ) {
 1463+ $this->setUseFormatCookie( $useFormat );
15221464 }
1523 -
1524 - // if getUseFormat and no cookie set, set the cookie
1525 - if ( is_null( $useFormatFromCookie ) && strlen( $useFormat ) ) {
1526 - $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, 0 );
1527 - }
15281465 }
15291466
 1467+ /**
 1468+ * Set the mf_useformat cookie
 1469+ *
 1470+ * This cookie can determine whether or not a user should see the mobile
 1471+ * version of pages.
 1472+ *
 1473+ * @param string The format to store in the cookie
 1474+ */
 1475+ protected function setUseFormatCookie( $useFormat ) {
 1476+ global $wgRequest, $wgCookieExpiration, $wgMobileFrontendFormatCookieExpiry;
 1477+ $cookieDuration = ( $wgMobileFrontendFormatCookieExpiry ) ?
 1478+ $wgMobileFrontendFormatCookieExpiry : $wgCookieExpiration;
 1479+ $expire = time() + $cookieDuration;
 1480+ $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, $expire );
 1481+ }
 1482+
15301483 public function getVersion() {
15311484 return __CLASS__ . ': $Id$';
15321485 }
Index: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php
@@ -26,8 +26,7 @@
2727 'mobile-frontend-hide-button' => 'Hide',
2828 'mobile-frontend-disable-button' => 'Disable',
2929 'mobile-frontend-back-button' => 'Back',
30 - 'mobile-frontend-regular-site' => 'View this page on regular {{SITENAME}}',
31 - 'mobile-frontend-perm-stop-redirect' => 'Permanently disable mobile site',
 30+ 'mobile-frontend-regular-site' => 'Desktop view',
3231 'mobile-frontend-error-page-title' => 'We have a problem!',
3332 '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!',
3433 'mobile-frontend-are-you-sure' => 'Are you sure?',
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -104,6 +104,16 @@
105105 $wgMobileUrlTemplate = '';
106106
107107 /**
 108+ * The number of seconds the 'useformat' cookie should be valid
 109+ *
 110+ * The useformat cookie gets set when a user manually elects to view
 111+ * either the mobile or desktop view of the site.
 112+ *
 113+ * If this value is not set, it will default to $wgCookieExpiration
 114+ */
 115+$wgMobileFrontendFormatCookieExpiry;
 116+
 117+/**
108118 * URL for script used to disable mobile site
109119 * (protocol, host, optional port; path portion)
110120 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r113866Followup r113865, fixing unit tests I brokeawjrichards22:14, 14 March 2012
r113870Followup r113865, removing 'disable mobile site permanantly' elements from fo...awjrichards22:50, 14 March 2012
r113872Follow up r113870, r113865, checking in only what I meant to the first time! ...awjrichards22:56, 14 March 2012
r114202MFT r113807, r113831, r113832, r113865, r113866, r113870, r113871, r113872, r...awjrichards22:23, 19 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r113439Makes useformat=mobile sticky with a cookie. Changese ExtMobileFrontend::useF...awjrichards00:40, 9 March 2012

Comments

#Comment by MaxSem (talk | contribs)   22:45, 14 March 2012
  • PHP Notice: Undefined index: mobile-frontend-perm-stop-redirect in D:\Projects\MediaWiki\extensions\MobileFrontend\templates\FooterTemplate.php on line 12
  • PHP Notice: Undefined index: disableMobileSiteURL in D:\Projects\MediaWiki\extensions\MobileFrontend\templates\FooterTemplate.php on line 19
#Comment by Awjrichards (talk | contribs)   22:50, 14 March 2012

Fixed in r113870

Status & tagging log