MaxSem has uploaded a new change for review.

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

Change subject: Fix fatals due to core changes
......................................................................

Fix fatals due to core changes

MF started crashing in 1.25wmf1 because SpecialPage_initList hook
started gettng called earlier, before request title is initialized.
This change postpones most of toggling until the time the title is there.

Bug: 71329
Change-Id: I01cde170a47fa9fad1753d9b5b95131c2ee952d3
---
M includes/MobileContext.php
M includes/MobileFrontend.hooks.php
M tests/phpunit/MobileContextTest.php
3 files changed, 40 insertions(+), 8 deletions(-)


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

diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index c935c03..fba5138 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -74,6 +74,10 @@
         * @var MobileContext $instance
         */
        private static $instance = null;
+       /**
+        * @var string What to switch the view to
+        */
+       private $viewChange = '';
 
        /**
         * Returns the actual MobileContext Instance or create a new if no 
exists
@@ -898,10 +902,26 @@
         * a mobile page), set the requested view for this particular request
         * and set a cookie to keep them on that view for subsequent requests.
         *
-        * @param string $view user requested particular view
+        * @param string $view User requested particular view
         */
        public function toggleView( $view ) {
                global $wgMobileUrlTemplate;
+
+               $this->viewChange = $view;
+               if ( !strlen( trim( $wgMobileUrlTemplate ) ) ) {
+                       $this->setUseFormat( $view );
+               }
+       }
+
+       /**
+        * Performs view change as requested vy toggleView()
+        */
+       public function doToggling() {
+               global $wgMobileUrlTemplate;
+
+               if ( !$this->viewChange ) {
+                       return;
+               }
 
                $url = $this->getRequest()->getFullRequestURL();
                $parsed = wfParseUrl( $url );
@@ -911,7 +931,7 @@
                unset( $query['title'] );
                $url = $this->getTitle()->getFullURL( $query, false, 
PROTO_CURRENT );
 
-               if ( $view == 'mobile' ) {
+               if ( $this->viewChange == 'mobile' ) {
                        // unset stopMobileRedirect cookie
                        // @TODO is this necessary with unsetting the cookie 
via JS?
                        $this->unsetStopMobileRedirectCookie();
@@ -919,13 +939,12 @@
                        // if no mobileurl template, set mobile cookie
                        if ( !strlen( trim( $wgMobileUrlTemplate ) ) ) {
                                $this->setUseFormatCookie();
-                               $this->setUseFormat( $view );
                        } else {
                                // else redirect to mobile domain
                                $mobileUrl = $this->getMobileUrl( $url );
                                $this->getOutput()->redirect( $mobileUrl, 301 );
                        }
-               } elseif ( $view == 'desktop' ) {
+               } elseif ( $this->viewChange == 'desktop' ) {
                        // set stopMobileRedirect cookie
                        $this->setStopMobileRedirectCookie();
                        // unset useformat cookie
@@ -933,10 +952,7 @@
                                $this->unsetUseFormatCookie();
                        }
 
-                       // if no mobileurl template, unset useformat cookie
-                       if ( !strlen( trim( $wgMobileUrlTemplate ) ) ) {
-                               $this->setUseFormat( $view );
-                       } else {
+                       if ( strlen( trim( $wgMobileUrlTemplate ) ) ) {
                                // if mobileurl template, redirect to desktop 
domain
                                $desktopUrl = $this->getDesktopUrl( $url );
                                $this->getOutput()->redirect( $desktopUrl, 301 
);
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index b570ae9..328fe57 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -51,6 +51,7 @@
 
                $mobileContext = MobileContext::singleton();
 
+               $mobileContext->doToggling();
                if ( !$mobileContext->shouldDisplayMobileView()
                        || $mobileContext->isBlacklistedPage()
                ) {
diff --git a/tests/phpunit/MobileContextTest.php 
b/tests/phpunit/MobileContextTest.php
index 9c8154a..f8a5f3d 100644
--- a/tests/phpunit/MobileContextTest.php
+++ b/tests/phpunit/MobileContextTest.php
@@ -503,6 +503,7 @@
                $context = $this->makeContext( $url );
                $context->getContext()->setTitle( Title::newFromText( $page ) );
                $context->checkToggleView();
+               $context->doToggling();
                $location = $context->getOutput()->getRedirect();
                $this->assertEquals( $expectedLocation, $location );
        }
@@ -554,6 +555,20 @@
                    */
                );
        }
+
+       public function testBug71329() {
+               SpecialPageFactory::resetList();
+               RequestContext::resetMain();
+               $req = new FauxRequest(
+                       array( 'title' => 'Special:Search', 'mobileaction' => 
'toggle_view_mobile' )
+               );
+               $req->setRequestURL( 
'/w/index.php?title=Special:Search&mobileaction=toggle_view_mobile' );
+               RequestContext::getMain()->setRequest( $req );
+               MobileContext::setInstance( null );
+               $this->setMwGlobals( 'wgTitle', null );
+               SpecialPage::getTitleFor( 'Search' );
+               $this->assertTrue( true, 'In case of failure this test just 
crashes' );
+       }
 }
 
 class MFFauxRequest extends FauxRequest {

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

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

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

Reply via email to