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. | |
hasMobileDomain () | |
True if the current wiki has separate mobile and desktop domains (regardless of which domain is used by the current request). | |
getMobileUrl ( $url, $forceHttps=false) | |
Take a URL and return the equivalent mobile URL (ie. | |
usingMobileDomain () | |
Checks whether the current request is using the mobile domain. | |
getDesktopUrl ( $url) | |
Take a URL and return a copy that removes any mobile tokens. | |
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. | |
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. | |
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.
This only works with URLs of the current wiki.
string | $url | representing a page on the mobile domain e.g. https://en.m.wikipedia.org/ |
MobileContext::getMobileAction | ( | ) |
Get requested mobile action.
MobileContext::getMobileUrl | ( | $url, | |
$forceHttps = false ) |
Take a URL and return the equivalent mobile URL (ie.
replace the domain with the mobile domain).
Typically this is a URL for the current wiki, but it can be anything as long as $wgMobileUrlCallback can convert its domain (so e.g. interwiki links can be converted). If the domain is already a mobile domain, or not recognized by $wgMobileUrlCallback, or the wiki does not use mobile domains and so $wgMobileUrlCallback is not set, the URL will be returned unchanged (except $forceHttps will still be applied).
string | $url | URL to convert |
bool | $forceHttps | Force HTTPS, even if the original URL used HTTP |
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::hasMobileDomain | ( | ) |
True if the current wiki has separate mobile and desktop domains (regardless of which domain is used by the current request).
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::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 UrlUtils::parse() |
|
protected |
Update the query portion of a given URL to remove any 'useformat' params.
array | &$parsedUrl | Result of parseUrl() or UrlUtils::parse() |
MobileContext::usingMobileDomain | ( | ) |
Checks whether the current request is using the mobile domain.
This assumes that some infrastructure outside MediaWiki will set a header (specified by $wgMFMobileHeader) on requests which use the mobile domain. This means that the traffic routing layer can rewrite hostnames to be canonical, so non-MobileFrontend-aware code can still work.