MobileFrontend
Mobile optimised frontend for MediaWiki
|
Provide various request-dependant methods to use in mobile context. More...
Public Member Functions | |
isMobileDevice () | |
Detects whether the UA is sending the request from a device and, if so, whether to display the mobile view to that device. | |
setForceMobileView ( $value) | |
Save whether mobile view should always be enforced. | |
setMobileMode ( $mode) | |
Sets testing group membership, both cookie and this class variables. | |
isBetaGroupMember () | |
Whether user is Beta group member. | |
shouldDisplayMobileView () | |
Determine whether or not we should display the mobile view. | |
getMobileAction () | |
Get requested mobile action. | |
setStopMobileRedirectCookie ( $expiry=null) | |
Set Cookie to stop automatically redirect to mobile page. | |
unsetStopMobileRedirectCookie () | |
Remove cookie and continue automatic redirect to mobile page. | |
getStopMobileRedirectCookie () | |
Read cookie for stop automatic mobile redirect. | |
getUseFormatCookie () | |
This cookie can determine whether or not a user should see the mobile version of a page. | |
getCookieDomain () | |
Return the base level domain or IP address. | |
getStopMobileRedirectCookieDomain () | |
Determine the correct domain to use for the stopMobileRedirect cookie. | |
setUseFormatCookie ( $cookieFormat='true', $expiry=null) | |
Set the mf_useformat cookie. | |
unsetUseFormatCookie () | |
Remove cookie based saved useformat value. | |
getUseFormatCookieDuration () | |
Determine the duration the cookie should last. | |
getMobileHostToken ( $mobileUrlHostTemplate) | |
Take a URL Host Template and return the mobile token portion. | |
getMobileUrlTemplate () | |
Get the template for mobile URLs. | |
getMobileUrl ( $url, $forceHttps=false) | |
Take a URL and return a copy that conforms to the mobile URL template. | |
usingMobileDomain () | |
If a mobile-domain is specified by the $wgMobileUrlTemplate and there's a mobile header, then we assume the user is accessing the site from the mobile-specific domain (because why would the desktop site set the header?). | |
getDesktopUrl ( $url) | |
Take a URL and return a copy that removes any mobile tokens. | |
parseMobileUrlTemplate ( $part=null) | |
Parse mobile URL template into its host and path components. | |
toggleView ( $view) | |
Toggles view to one specified by the user. | |
doToggling () | |
Performs view change as requested vy toggleView() | |
checkToggleView () | |
Determine whether or not we need to toggle the view, and toggle it. | |
isLocalUrl ( $url) | |
Determine whether or not a given URL is local. | |
addAnalyticsLogItem ( $key, $val) | |
Add key/value pairs for analytics purposes to $this->analyticsLogItems. | |
getAnalyticsLogItems () | |
Read key/value pairs for analytics purposes from $this->analyticsLogItems. | |
getXAnalyticsHeader () | |
Get HTTP header string for X-Analytics. | |
addAnalyticsLogItemFromXAnalytics ( $xanalytics_item) | |
Take a key/val pair in string format and add it to $this->analyticsLogItems. | |
logMobileMode () | |
Adds analytics log items depending on which modes are enabled for the user. | |
shouldShowWikibaseDescriptions ( $feature, Config $config) | |
Gets whether Wikibase descriptions should be shown in search results, and watchlists; or as taglines on article pages. | |
Static Public Member Functions | |
static | singleton () |
Returns the actual MobileContext Instance or create a new if no exists. | |
static | resetInstanceForTesting () |
Resets the singleton instance. | |
Static Public Attributes | |
static | $mfStopRedirectCookieHost = null |
Protected Member Functions | |
__construct (IContextSource $context, Config $config) | |
getUseFormatCookieExpiry ( $startTime=null, $cookieDuration=null) | |
Get the expiration time for the mf_useformat cookie. | |
updateMobileUrlHost (array &$parsedUrl) | |
Update host of given URL to conform to mobile URL template. | |
updateDesktopUrlHost (array &$parsedUrl) | |
Update the host of a given URL to strip out any mobile tokens. | |
updateDesktopUrlQuery (array &$parsedUrl) | |
Update the query portion of a given URL to remove any 'useformat' params. | |
updateMobileUrlPath (array &$parsedUrl) | |
Update path of given URL to conform to mobile URL template. | |
Protected Attributes | |
$mobileMode = null | |
$useFormat = null | |
$analyticsLogItems = [] | |
$mobileAction = null | |
Provide various request-dependant methods to use in mobile context.
|
protected |
IContextSource | $context | |
Config | $config |
MobileContext::addAnalyticsLogItem | ( | $key, | |
$val ) |
Add key/value pairs for analytics purposes to $this->analyticsLogItems.
Pre-existing entries are appended to as sets delimited by commas.
string | $key | for <key> in X-Analytics: <key>=<value> |
string | $val | for |
in X-Analytics: <key>=<value>
MobileContext::addAnalyticsLogItemFromXAnalytics | ( | $xanalytics_item | ) |
Take a key/val pair in string format and add it to $this->analyticsLogItems.
string | $xanalytics_item | In the format key=value |
MobileContext::getAnalyticsLogItems | ( | ) |
Read key/value pairs for analytics purposes from $this->analyticsLogItems.
MobileContext::getCookieDomain | ( | ) |
Return the base level domain or IP address.
MobileContext::getDesktopUrl | ( | $url | ) |
Take a URL and return a copy that removes any mobile tokens.
string | $url | representing a page on the mobile domain e.g. https://en.m.wikipedia.org/ |
MobileContext::getMobileAction | ( | ) |
Get requested mobile action.
MobileContext::getMobileHostToken | ( | $mobileUrlHostTemplate | ) |
Take a URL Host Template and return the mobile token portion.
Eg if a desktop domain is en.wikipedia.org, but the mobile variant is en.m.wikipedia.org, the mobile token is 'm.'
string | $mobileUrlHostTemplate | URL host |
MobileContext::getMobileUrl | ( | $url, | |
$forceHttps = false ) |
Take a URL and return a copy that conforms to the mobile URL template.
string | $url | URL to convert |
bool | $forceHttps | should force HTTPS? |
MobileContext::getMobileUrlTemplate | ( | ) |
Get the template for mobile URLs.
MobileContext::getStopMobileRedirectCookie | ( | ) |
Read cookie for stop automatic mobile redirect.
MobileContext::getStopMobileRedirectCookieDomain | ( | ) |
Determine the correct domain to use for the stopMobileRedirect cookie.
Will use $wgMFStopRedirectCookieHost if it's set, otherwise will use result of getCookieDomain()
MobileContext::getUseFormatCookie | ( | ) |
This cookie can determine whether or not a user should see the mobile version of a page.
MobileContext::getUseFormatCookieDuration | ( | ) |
Determine the duration the cookie should last.
If $wgMobileFrontendFormatcookieExpiry has a non-0 value, use that for the duration. Otherwise, fall back to $wgCookieExpiration.
|
protected |
Get the expiration time for the mf_useformat cookie.
int | null | $startTime | The base time (in seconds since Epoch) from which to calculate cookie expiration. If null, time() is used. |
int | null | $cookieDuration | The time (in seconds) the cookie should last |
MobileContext::getXAnalyticsHeader | ( | ) |
Get HTTP header string for X-Analytics.
This is made up of key/value pairs and is used for analytics purposes.
MobileContext::isBetaGroupMember | ( | ) |
Whether user is Beta group member.
MobileContext::isLocalUrl | ( | $url | ) |
Determine whether or not a given URL is local.
string | $url | URL to check against |
MobileContext::isMobileDevice | ( | ) |
Detects whether the UA is sending the request from a device and, if so, whether to display the mobile view to that device.
The mobile view will always be displayed to mobile devices. However, it will only be displayed to tablet devices if $wgMFShowMobileViewToTablets
is truthy.
@fixme This should be renamed to something more appropriate, e.g. shouldDisplayMobileViewToDevice
.
MobileContext::logMobileMode | ( | ) |
Adds analytics log items depending on which modes are enabled for the user.
Invoked from MobileFrontendHooks::onRequestContextCreateSkin()
Making changes to what this method logs? Make sure you update the documentation for the X-Analytics header: https://wikitech.wikimedia.org/wiki/X-Analytics
MobileContext::parseMobileUrlTemplate | ( | $part = null | ) |
Parse mobile URL template into its host and path components.
Optionally specify which portion of the template you want returned.
string | null | $part | which part to return? |
This if/else block exists because of an annoying aspect of substr() Even if you pass 'null' or 'false' into the 'length' param, it will return an empty string. http://www.stopgeek.com/wp-content/uploads/2007/07/sense.jpg
MobileContext::setForceMobileView | ( | $value | ) |
Save whether mobile view should always be enforced.
bool | $value | should mobile view be enforced? |
MobileContext::setMobileMode | ( | $mode | ) |
Sets testing group membership, both cookie and this class variables.
WARNING: Does not persist the updated user preference to the database. The caller must handle this by calling User::saveSettings() after all preference updates associated with this web request are made.
string | $mode | Mode to set |
MobileContext::setStopMobileRedirectCookie | ( | $expiry = null | ) |
Set Cookie to stop automatically redirect to mobile page.
int | null | $expiry | Expire time of cookie |
MobileContext::setUseFormatCookie | ( | $cookieFormat = 'true', | |
$expiry = null ) |
Set the mf_useformat cookie.
This cookie can determine whether or not a user should see the mobile version of pages.
string | $cookieFormat | should user see mobile version of pages? |
int | null | $expiry | Expiration of cookie |
MobileContext::shouldDisplayMobileView | ( | ) |
Determine whether or not we should display the mobile view.
Step through the hierarchy of what should or should not trigger the mobile view.
Primacy is given to the page action - we will never show mobile view for page edits or page history. 'userformat' request param is then honored, followed by cookie settings, then actual device detection, finally falling back on false.
MobileContext::shouldShowWikibaseDescriptions | ( | $feature, | |
Config | $config ) |
Gets whether Wikibase descriptions should be shown in search results, and watchlists; or as taglines on article pages.
Doesn't take into account whether the wikidata descriptions feature has been enabled.
string | $feature | which description to show? |
Config | $config |
DomainException | If feature isn't one that shows Wikidata descriptions. See the wgMFDisplayWikibaseDescriptions configuration variable for detail |
|
static |
Returns the actual MobileContext Instance or create a new if no exists.
MobileContext::toggleView | ( | $view | ) |
Toggles view to one specified by the user.
If a user has requested a particular view (eg clicked 'Desktop' from a mobile page), set the requested view for this particular request and set a cookie to keep them on that view for subsequent requests.
string | $view | User requested particular view |
|
protected |
Update the host of a given URL to strip out any mobile tokens.
array | &$parsedUrl | Result of parseUrl() or wfParseUrl() |
|
protected |
Update the query portion of a given URL to remove any 'useformat' params.
array | &$parsedUrl | Result of parseUrl() or wfParseUrl() |
|
protected |
Update host of given URL to conform to mobile URL template.
array | &$parsedUrl | Result of parseUrl() or wfParseUrl() |
|
protected |
Update path of given URL to conform to mobile URL template.
NB: this is not actually being used anywhere at the moment. It will take some magic to get MW to properly handle path modifications like this is intended to provide. This will hopefully be implemented someday in the not to distant future.
array | &$parsedUrl | Result of parseUrl() or wfParseUrl() |
MobileContext::usingMobileDomain | ( | ) |
If a mobile-domain is specified by the $wgMobileUrlTemplate and there's a mobile header, then we assume the user is accessing the site from the mobile-specific domain (because why would the desktop site set the header?).