http://www.mediawiki.org/wiki/Special:Code/MediaWiki/67329
Revision: 67329 Author: tstarling Date: 2010-06-04 09:21:47 +0000 (Fri, 04 Jun 2010) Log Message: ----------- Redirect script for integration with wikimedia-mobile, packaged as an extension so it can be version controlled, and enabled and disabled by sysadmins. Based on the site JS hack by Hampton and Brion at http://meta.wikimedia.org/w/index.php?title=Mobile&oldid=1959389#Redirecting_users This module is not itself Wikimedia-specific, it's just called WikimediaMobile because it's for integration with a thing called wikimedia-mobile (which by the way is currently Wikimedia-specific). Added Paths: ----------- trunk/extensions/WikimediaMobile/ trunk/extensions/WikimediaMobile/MobileRedirect.js trunk/extensions/WikimediaMobile/WikimediaMobile.php Added: trunk/extensions/WikimediaMobile/MobileRedirect.js =================================================================== --- trunk/extensions/WikimediaMobile/MobileRedirect.js (rev 0) +++ trunk/extensions/WikimediaMobile/MobileRedirect.js 2010-06-04 09:21:47 UTC (rev 67329) @@ -0,0 +1,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)/ + .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(); + })(); +} Property changes on: trunk/extensions/WikimediaMobile/MobileRedirect.js ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/extensions/WikimediaMobile/WikimediaMobile.php =================================================================== --- trunk/extensions/WikimediaMobile/WikimediaMobile.php (rev 0) +++ trunk/extensions/WikimediaMobile/WikimediaMobile.php 2010-06-04 09:21:47 UTC (rev 67329) @@ -0,0 +1,36 @@ +<?php + +/** + * MediaWiki support functions for the wikimedia-mobile project hosted + * at http://github.com/hcatlin/wikimedia-mobile + */ + +/** + * Increment this when the JS file changes + */ +$wgWikimediaMobileVersion = '1'; + +/** + * The base URL of the mobile gateway + */ +$wgWikimediaMobileUrl = 'http://en.m.wikipedia.org/wiki'; + + +$wgHooks['BeforePageDisplay'][] = 'wfWikimediaMobileAddJs'; +$wgHooks['MakeGlobalVariablesScript'][] = 'wfWikimediaMobileVars'; + +function wfWikimediaMobileAddJs( &$outputPage, &$skin ) { + global $wgOut, $wgExtensionAssetsPath, $wgWikimediaMobileVersion; + + $wgOut->addScript( Html::linkedScript( + "$wgExtensionAssetsPath/WikimediaMobile/MobileRedirect.js?$wgWikimediaMobileVersion" + ) ); + return true; +} + +function wfWikimediaMobileVars( &$vars ) { + global $wgWikimediaMobileUrl; + $vars['wgWikimediaMobileUrl'] = $wgWikimediaMobileUrl; + return true; +} + Property changes on: trunk/extensions/WikimediaMobile/WikimediaMobile.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs