Currently, application logic accesses information about the current request (such as the identity of the current user, the requested page, etc) primarily via a RequestContextSource singleton obtained from RequestContext::getMain(). RequestContextSource in turn binds to "heavy" classes like Title and User, and RequestContext relies heavily on global state. It also doubles as an i18n facility, implementing MessageLocalizer.
This should be replaced by a RequestInfo service object, that can be injected (or obtained from the global service locator if need be). RequestInfo would be structurally similar to RequestContext, but would bind to lightweight interfaces instead of heavy classes, and would not rely on global state.
Note that ideally, any information derived from the request should be passed to application logic as a parameter, and should not be known to service instances. However, changing MediaWiki's architecture in that regard seems difficult, and PHP's per-request execution model makes it acceptable to treat the user request as a global thing, making it available via a service instance. The same could perhaps be said about the response, but treating the response as global seems more problematic, since it is mutable.
RequestInfo should implement the following methods (similar to the ones found in RequestContext):
- getRequest(): WebRequest. Note however that WebRequest binds to Session, which binds to User. Session::getUser should in time be replaced with Session::getUserIdentity to fix this.
- getTarget(): LinkTarget. Replaces getTitle().
- getUserIdentity(): the identity of the logged in user, if any
- getRequestedLanguage(): get the code of the requested output language. Based on the user's preferences, but may be overwritten per request. Avoid binding against the heavy Language class, though.
- getRequestedSkin(): get the name of the requested skin. Based on the user's preferences, but may be overwritten per request. Avoid binding against the heavy Skin class, though.
- getDiagnostics(): returns a human readable array of diagnostic information about the request, similar to RequestContent::exportSession(). The contents should be treated as serializable, opaque, and for human consumption.
RequestInfo should not implement the following methods found in RequestContext:
- getOutput() - while input can be treated as a global thing, output generally should not.
- getStats(), getTiming() - use separate services or aggregate in some kind of output object
- getWikiPage() and canUseWikiPage - WikiPage (or, in the future, PageRecord, see T195069) should be obtained from a storage service.
- getConfig() - this has nothing at all to do with the request
- msg() - localization should be done elsewhere.
RequestInfo could implement the following additional methods in the future:
- getSession(): Same as getRequest()->getSession(). WebRequest::getSession could perhaps be deprecated in the future, to turn WebRequest into a value object.
- getPageIdentity(): PageIdentity, once PageIdentity exists (T208776). Very similar to getTarget(), perhaps not needed.
- isLoggedIn(): whether the request comes from a logged in user.
- isWebRequest(): whether this is actually a web request, as opposed to a CLI script or async job execution.