|
MobileFrontend
Mobile optimised frontend for MediaWiki
|
Provide various request-dependant methods to use in mobile context. More...
Inheritance diagram for MobileContext:
Collaboration diagram for MobileContext: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. | |
| shouldDisplayMobileView () | |
| Determine whether 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 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. | |
| doToggling () | |
| Set the toggling cookie and redirect, as requested by toggleView() | |
| checkToggleView () | |
| Determine whether we need to toggle the view, and toggle it. | |
| isLocalUrl ( $url) | |
| Determine whether 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. | |
Public Attributes | |
| const | STOP_MOBILE_REDIRECT_COOKIE_NAME = 'stopMobileRedirect' |
| const | USEFORMAT_COOKIE_NAME = 'mf_useformat' |
Static Public Attributes | |
| static string | $mfStopRedirectCookieHost = null |
Protected Member Functions | |
| __construct (IContextSource $context, private readonly 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 | |
| string | $useFormat = null |
| Save explicitly requested format. | |
| array | $analyticsLogItems = [] |
| string | $mobileAction = null |
| Saves requested Mobile action. | |
Provide various request-dependant methods to use in mobile context.
| 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 the result of getCookieDomain()
| MobileContext::getUseFormatCookie | ( | ) |
This cookie can determine whether 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::isLocalUrl | ( | $url | ) |
Determine whether 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::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 a user should see the mobile version of pages.
| string | $cookieFormat | should user see the mobile version of pages? |
| int | null | $expiry | Expiration of cookie |
| MobileContext::shouldDisplayMobileView | ( | ) |
Determine whether 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 the mobile view for page edits or page history. 'useformat' 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.
|
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 should use the mobile format. This means that the traffic routing layer can rewrite any m-dot hostnames to be canonical, allowing non-MobileFrontend-aware code in MediaWiki to work as-is.