Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -26,7 +26,6 @@ |
27 | 27 | public static $searchField; |
28 | 28 | public static $disableImagesURL; |
29 | 29 | public static $enableImagesURL; |
30 | | - public static $disableMobileSiteURL; |
31 | 30 | public static $viewNormalSiteURL; |
32 | 31 | public static $currentURL; |
33 | 32 | public static $displayNoticeId; |
— | — | @@ -72,7 +71,6 @@ |
73 | 72 | 'mobile-frontend-hide-button', |
74 | 73 | 'mobile-frontend-back-to-top-of-section', |
75 | 74 | 'mobile-frontend-regular-site', |
76 | | - 'mobile-frontend-perm-stop-redirect', |
77 | 75 | 'mobile-frontend-home-button', |
78 | 76 | 'mobile-frontend-random-button', |
79 | 77 | 'mobile-frontend-are-you-sure', |
— | — | @@ -231,8 +229,7 @@ |
232 | 230 | |
233 | 231 | self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' ); |
234 | 232 | 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' ); |
237 | 234 | self::$currentURL = $wgRequest->getFullRequestURL(); |
238 | 235 | self::$leaveFeedbackURL = $wgRequest->escapeAppendQuery( 'mobileaction=leave_feedback' ); |
239 | 236 | |
— | — | @@ -478,12 +475,6 @@ |
479 | 476 | exit(); |
480 | 477 | } |
481 | 478 | |
482 | | - if ( $mobileAction == 'disable_mobile_site' && $this->contentFormat == 'XHTML' ) { |
483 | | - echo $this->renderDisableMobileSiteXHTML(); |
484 | | - wfProfileOut( __METHOD__ ); |
485 | | - exit(); |
486 | | - } |
487 | | - |
488 | 479 | if ( $mobileAction == 'opt_in_mobile_site' && $this->contentFormat == 'XHTML' ) { |
489 | 480 | echo $this->renderOptInMobileSiteXHTML(); |
490 | 481 | wfProfileOut( __METHOD__ ); |
— | — | @@ -858,54 +849,6 @@ |
859 | 850 | } |
860 | 851 | |
861 | 852 | /** |
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 | | - /** |
910 | 853 | * @return DomElement |
911 | 854 | */ |
912 | 855 | public function renderLogin() { |
— | — | @@ -1166,7 +1109,6 @@ |
1167 | 1110 | $options = array( |
1168 | 1111 | 'messages' => self::$messages, |
1169 | 1112 | 'leaveFeedbackURL' => self::$leaveFeedbackURL, |
1170 | | - 'disableMobileSiteURL' => self::$disableMobileSiteURL, |
1171 | 1113 | 'viewNormalSiteURL' => self::$viewNormalSiteURL, |
1172 | 1114 | 'disableImages' => self::$disableImages, |
1173 | 1115 | 'disableImagesURL' => self::$disableImagesURL, |
— | — | @@ -1443,15 +1385,20 @@ |
1444 | 1386 | } |
1445 | 1387 | |
1446 | 1388 | 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' ) { |
1448 | 1392 | return false; |
1449 | 1393 | } |
| 1394 | + |
| 1395 | + if ( !$this->isMobileDevice() && !$this->isFauxMobileDevice() ) { |
| 1396 | + return false; |
| 1397 | + } |
1450 | 1398 | |
1451 | 1399 | $action = $this->getAction(); |
1452 | | - $mobileAction = $this->getMobileAction(); |
1453 | 1400 | |
1454 | | - if ( $action === 'edit' || $action === 'history' || |
1455 | | - $mobileAction === 'view_normal_site' ) { |
| 1401 | + |
| 1402 | + if ( $action === 'edit' || $action === 'history' ) { |
1456 | 1403 | return false; |
1457 | 1404 | } |
1458 | 1405 | |
— | — | @@ -1503,29 +1450,35 @@ |
1504 | 1451 | |
1505 | 1452 | $useFormat = $this->getUseFormat(); |
1506 | 1453 | $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' ); |
| 1454 | + |
| 1455 | + // fetch format from cookie and set it if one is not otherwise specified |
1507 | 1456 | if( !strlen( $useFormat ) && !is_null( $useFormatFromCookie ) ) { |
1508 | 1457 | $this->setUseFormat( $useFormatFromCookie ); |
1509 | 1458 | } |
1510 | 1459 | |
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 ); |
1522 | 1464 | } |
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 | | - } |
1528 | 1465 | } |
1529 | 1466 | |
| 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 | + |
1530 | 1483 | public function getVersion() { |
1531 | 1484 | return __CLASS__ . ': $Id$'; |
1532 | 1485 | } |
Index: trunk/extensions/MobileFrontend/MobileFrontend.i18n.php |
— | — | @@ -26,8 +26,7 @@ |
27 | 27 | 'mobile-frontend-hide-button' => 'Hide', |
28 | 28 | 'mobile-frontend-disable-button' => 'Disable', |
29 | 29 | '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', |
32 | 31 | 'mobile-frontend-error-page-title' => 'We have a problem!', |
33 | 32 | '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!', |
34 | 33 | 'mobile-frontend-are-you-sure' => 'Are you sure?', |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -104,6 +104,16 @@ |
105 | 105 | $wgMobileUrlTemplate = ''; |
106 | 106 | |
107 | 107 | /** |
| 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 | +/** |
108 | 118 | * URL for script used to disable mobile site |
109 | 119 | * (protocol, host, optional port; path portion) |
110 | 120 | * |