Last modified: 2014-02-12 23:54:17 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T40009, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38009 - enable mobile redirect broken (Certain iOS users getting served desktop site - reports of mobile view not sticking)
enable mobile redirect broken (Certain iOS users getting served desktop site ...
Status: RESOLVED FIXED
Product: MobileFrontend
Classification: Unclassified
stable (Other open bugs)
unspecified
All All
: Highest major
: ---
Assigned To: Nobody - You can work on this!
http://en.wikipedia.org/wiki/Wikipedi...
: patch, patch-need-review
: 36734 37308 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-27 21:57 UTC by Dave Yorke
Modified: 2014-02-12 23:54 UTC (History)
14 users (show)

See Also:
Web browser: Apple Safari
Mobile Platform: iOS
Assignee Huggle Beta Tester: ---


Attachments
MediaWiki:Common.js with code to unset stopMobileRedirect cookie in iOS (18.28 KB, application/x-javascript)
2012-08-16 19:49 UTC, Mark W.
Details
2nd version of iOS stopMobileRedirect cookie fix - follow Quirksmode advice... (18.28 KB, application/x-javascript)
2012-08-16 20:01 UTC, Mark W.
Details
Change stopMobileRedirect cookie using $.cookie() function. (18.28 KB, application/x-javascript)
2012-08-16 21:57 UTC, Mark W.
Details
Suggested patch to MobileContext.php (891 bytes, patch)
2012-08-16 23:04 UTC, Mark W.
Details

Description Dave Yorke 2012-06-27 21:57:13 UTC
iPhone 4, iOS 5.0.1
After switching to desktop view on a Wikipedia mobile page I am no longer redirected to the mobile Wikipedia from other sites (e.g.: google search results). (Side note: is this desirable behavior?)

Clicking on the "Mobile Version" link at the bottom of an article doesn't permanently re-enable the mobile redirect. neither does clicking the link on the  "Enable Mobile version" page. http://en.wikipedia.org/wiki/Wikipedia:Enable_mobile_version

There is a overly complacated fix on the Enable Mobile Version talk page which points to a recent regression in Mediawiki. http://en.wikipedia.org/wiki/Wikipedia_talk:Enable_mobile_version
Comment 1 Dave Yorke 2012-06-29 17:55:56 UTC
I hope my changes are helpful. please let me know. Thanks.
Comment 2 Jon 2012-07-04 16:38:26 UTC
Thanks Dave. We are looking into this.

There have also been lots of reports on Twitter and I can replicate the problem and noise in the feedback forms. Maybe Arthur Richards can take a look at this when he returns Friday.
Comment 3 Derk-Jan Hartman 2012-08-15 10:21:46 UTC
4th of july....

I added a script to take care of this highly annoying problem, since it's been a production problem for 2,5 months now.

https://en.wikipedia.org/w/index.php?title=MediaWiki%3ACommon.js&diff=507511838&oldid=499562302
Comment 4 Mark W. 2012-08-16 03:33:41 UTC
I'm still seeing the problem in Mobile Safari (iPhone 4S running iOS 5.1.1).

Prepare to reproduce this problem:
1. Clear all cookies:
  1a. Force Safari closed (http://support.apple.com/kb/ht5137); this is important because Safari keeps a copy of cookies in memory while it's open and in the background; the Settings app only edits the persistent cookie storage.
  1b. Open the Settings app
  1c. Scroll down and tap on "Safari"
  1d. Tap on "Clear Cookies and Data"
  1e. Approve the action by tapping the "Clear Cookies and Data" button

2. Press the home button then start Safari
3. Tap Safari's address bar, type "en.wikipedia.org" and press "Go"
4. Notice that Wikipedia redirects your browser to "en.m.wikipedia.org"

Now we're ready to reproduce/cause the problem:
5. Scroll to the bottom of the page, expand the "WikipediA  more" section and tap on the "Desktop" link.

*** At this point, the toggle_view_desktop parameter to index.php causes Wikipedia to set the "stopMobileRedirect=true" cookie with an expire date six months in the future and that "locks" the mobile browser to the Desktop version of Wikipedia because the cookie is quite difficult to unset.

6. Scroll to the bottom of the desktop version of en.wikipedia.org that you'e viewing and tap on the "Mobile" link.

  This takes you to the mobile version of the home page as expected, but the stopMobileRedirect cookie remains true (even with the new MediaWiki:common.js click handler; apparently Safari ignores the null cookie).

7. To demonstrate the problem, either search Google for something that points back to Wikipedia or enter the url "en.wikipedia.org".  In either case, the user expects to return to the mobile view as that's what they last saw in the step above.
Comment 5 Mark W. 2012-08-16 06:29:37 UTC
If it helps, here are a bunch of common.js experiments
http://en.wikipedia.org/w/index.php?title=User:Mwarren_us/common.js

The simplest working javascript I found was this:

$('a[href$="toggle_view_mobile"]').click(function(){
         document.cookie = 'stopMobileRedirect=false; domain=.wikipedia.org;'
                         + 'path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;'
                                                   });

Unfortunately, none of my attempts succeeded using $.cookie().
Comment 6 Arthur Richards 2012-08-16 15:46:31 UTC
Thanks for all the contributions - and nice hacks! I was going to suggest that we add some javascript to delete the cookie when the 'Mobile view' link gets clicked. This could be added to the MobileFrontend code so it gets loaded on the desktop version of the site via ResourceLoader.

The code that was added to common.js does not appear to be working, at least for me. In fact, it looks like it's setting an additional cookie, which is really just going to cause more problems for people. I didn't dig into this too deeply but I suspect it's because the path and/or domain of the cookie being set in common.js does not match that of the initially set stopMobileRedirect cooki. I made some quick modifications and this appears to work (from User:Awjrichards/common.js):

mw.loader.using( 'jquery.cookie', function() {
    $('a[href$="toggle_view_mobile"]').click(function(){
        $.cookie( 'stopMobileRedirect', false, 'Thu, 01-Jan-1970 00:00:00 GMT', '/' );
    });
});

There have been a number of changes in MobileFrontend that negatively affected how the toggling cookies work, plus we've had extra complications with the cluster's caching infrastructure. But the solution you all came up with is pretty much exactly what I would've done - now let's just get it into MobileFrontend! Are any of you interested in making a patch to get this little bit of js loaded on the desktop view? This will help alleviate problems for the other sites as well.

I apologize that this is something that has gone unfixed for so long - we've had our hands full with other work that has been given higher priority and we have not had the chance to get this resolved. But for me, this shows how awesome the project and open source software in general is. It was broken, and you fixed it :)
Comment 7 Mark W. 2012-08-16 19:45:53 UTC
I add your code to [[w:User:Mwarren_us/common.js]], however, it does not solve the problem under iOS 5.1.1 either.  For some reason, all  variants of $.cookie() running under iOS 5.1.1 fail to unset the stopMobileRedirect cookie; only directly setting document.cookie seems to get the job done. I've attached a version of Common.js with the fix that works in my testing.
Comment 8 Mark W. 2012-08-16 19:49:21 UTC
Created attachment 10976 [details]
MediaWiki:Common.js with code to unset stopMobileRedirect cookie in iOS

Since this fix does not need jQuery.cookie, I also removed the mw.loader.using() wrapper.
Comment 9 Mark W. 2012-08-16 20:01:58 UTC
Created attachment 10977 [details]
2nd version of iOS stopMobileRedirect cookie fix - follow Quirksmode advice...

Quirksmode (http://www.quirksmode.org/js/cookies.html#document.cookie ) says that document.cookie strings need to follow a strict format - this version of Common.js follows that.
Comment 10 Mark W. 2012-08-16 21:34:24 UTC
The latest version of MediaWiki:Common.js worked for me.

https://en.wikipedia.org/w/index.php?title=MediaWiki%3ACommon.js&action=view&diff=507736959
Comment 11 Arthur Richards 2012-08-16 21:41:57 UTC
Quick tests on my end look good with android 4.0.4. I think this fine to live in common.js for the short term, but we should get this into MobileFrontend as well. Mark, are you interested in trying to take that on with some support from the mobile team?
Comment 12 Mark W. 2012-08-16 21:57:48 UTC
Created attachment 10978 [details]
Change stopMobileRedirect cookie using $.cookie() function.

Finally found a way to call $.cookie() that works on iOS 5.1.1. This version of uses $.cookie() to change stopMediaRedirect to false but does not try to remove/expire the cookie.
Comment 13 Mark W. 2012-08-16 23:04:44 UTC
Created attachment 10979 [details]
Suggested patch to MobileContext.php

I don't have a sandbox area to test this suggestion for MobileContext.php (https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/MobileFrontend.git;a=blob;f=MobileContext.php;h=8c768a14ab52922825c55ac379f9c79b64d382b6;hb=HEAD ), so please take it with a grain of salt. The PHP change tries to do something similar to the javascript workaround: set stopMobileRedirect to false as well as use a date in the past.
Comment 14 Mark W. 2012-08-17 02:10:31 UTC
(In reply to comment #11)
> Mark, are you interested in trying to take that on with some support from
> the mobile team?

Sure, I can take a crack at that. Pointers about where to start reading about the MobileFronted maintenance process would be welcome.  Thank you!
Comment 15 Sumana Harihareswara 2012-08-17 10:39:17 UTC
Mark, you might also want to check out https://www.mediawiki.org/wiki/Git/Tutorial so you can more easily submit future patches directly into our source control system. Thanks!
Comment 16 Arthur Richards 2012-08-17 16:17:54 UTC
Mark, thanks for taking a crack at it!

What I can tell you real quick now is that there is already good cookie setting/unsetting code in PHP in MobileFrontend, as well as in some Javascript which loads only for the mobile version of the site. The problem is, due to the cluster's caching infrastructure, there are issues unsetting the stopMobileRedirect cookie on the server side (in PHP). We should instead take the solution you refined in common.js on en.wikipedia and have MobileFrontend load that bit of javascript on the desktop version of the site. This will require using resource loader (http://www.mediawiki.org/wiki/ResourceLoader) and ensuring that it only gets loaded for non-mobile page views. It's not very clear in the code, but the decision about whether or not to show the mobile version of the site gets made in ExtMobileFrontend::requestContextCreateSkin().

I hope that's enough to get you started - I'll help dig in deeper later when I have some more time, likely this weekend or early next week.
Comment 17 Jon 2012-09-04 18:50:21 UTC
*** Bug 37308 has been marked as a duplicate of this bug. ***
Comment 18 Arthur Richards 2012-09-05 17:15:17 UTC
Comment on attachment 10979 [details]
Suggested patch to MobileContext.php

This will not work on the WMF infrastructure. A better solution would be to take the JS used in common.js and place it into a ResourceLoader module that gets added in MobileFrontend.
Comment 19 Jon 2012-09-13 23:48:47 UTC
*** Bug 36734 has been marked as a duplicate of this bug. ***
Comment 20 Arthur Richards 2012-09-28 00:13:54 UTC
I believe https://gerrit.wikimedia.org/r/#/c/25596/4 should fix this. When the changes get merged, I'd like to enable the changes on a single wiki (maybe mediawiki.org?) to test for a week to ensure this fully resolves the issue before pushing out everywhere since we don't really have the ability to test the efficacy of this change for the production cluster outside of the production cluster, unless someone else has a better testing strategy. The next MobileFrontend deployment is scheduled for the upcoming Tuesday, hopefully we'll get this out then.
Comment 21 Arthur Richards 2012-09-28 00:16:07 UTC
PS big thanks to everyone who's been helping with this - I basically took the JS that's being used on enwiki in common.js and integrated it with MobileFrontend to get loaded on the desktop version of the site.
Comment 22 Arthur Richards 2012-10-02 01:07:09 UTC
This fix has now been deployed to simple.wikimedia.org, and appears to be working for me. Can folks who've been experiencing this issue please test there and report back your findings? If everything looks OK, we can push the change out everywhere on the cluster next week.
Comment 23 Jakob Unterwurzacher 2012-10-02 08:16:20 UTC
For other testers, I think http://simple.wikipedia.org/ was meant.
And it works for me there!
Comment 24 Arthur Richards 2012-10-02 17:01:41 UTC
Whoops, thanks Jakob - you're correct!
Comment 25 Arthur Richards 2012-10-03 23:22:18 UTC
Dave, Derk, Mark - can you please test this on simple.wikipedia.org and confirm if the problem is resolved there?
Comment 26 Arthur Richards 2012-10-03 23:35:31 UTC
This is also confirmed working with ios6, android 4.1.1, android 2.3.6 (stock, opera mobile, opera mini)
Comment 27 Arthur Richards 2012-10-09 23:39:52 UTC
This has now been deployed everywhere.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links