Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Madagascar/frwp/Démographie_de_Madagascar_files/MobileRedirect.js
blob: 2dde20109f6c320e818a8ad46f9f9b87609338a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** Mobile Redirect Helper
 *
 *  Redirects to a wikimedia-mobile installation for viewers on iPhone, iPod 
 *  Touch, Palm Pre, and Android devices.
 *
 *  You can turn off the redirect by setting the cookie "stopMobileRedirect=true"
 */
if ( /(Android|iPhone|iPod|webOS|NetFront|Opera Mini|SEMC-Browser|PlayStation Portable|Nintendo Wii|BlackBerry)/
	.test( navigator.userAgent ) )
{
	(function () {
		function haveStopCookie() {
			return (document.cookie.indexOf("stopMobileRedirect=true") >= 0);
		}

		function getMobileUrl() {
			var mainPage = wgMainPageTitle.replace(/ /g, '_');
			var url = wgWikimediaMobileUrl + '/';
			if (wgPageName == mainPage) {
				url += '::Home'; // Special case
			} else {
				url += encodeURIComponent(wgPageName).replace('%2F','/').replace('%3A',':');
			}
			url += '?wasRedirected=true';
			return url;
		}

		// Don't redirect if we have the stop cookie
		if (haveStopCookie()) return;

		// Don't redirect special pages
		if (wgNamespaceNumber < 0) return;

		// Don't redirect URLs that aren't simple page views
		if (document.location.search && document.location.search.length > 0) {
			var params = document.location.search.substr(1).split('&');
			for (var i = 0; i < params.length; i++) {
				var paramParts = params[i].split('=');
				if (paramParts.length && paramParts[0] != 'title') {
					return;
				}
			}
		}

		document.location = getMobileUrl();
	})();
}