3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Context
;
23 use MediaWiki\Config\Config
;
24 use MediaWiki\Language\Language
;
25 use MediaWiki\Language\LocalizationContext
;
26 use MediaWiki\Output\OutputPage
;
27 use MediaWiki\Permissions\Authority
;
28 use MediaWiki\Request\WebRequest
;
29 use MediaWiki\Session\CsrfTokenSetProvider
;
30 use MediaWiki\Title\Title
;
31 use MediaWiki\User\User
;
37 * Interface for objects which can provide a MediaWiki context on request
39 * Context objects contain request-dependent objects that manage the core
40 * web request/response logic for essentially all requests to MediaWiki.
41 * The contained objects include:
42 * a) Key objects that depend (for construction/loading) on the HTTP request
43 * b) Key objects used for response building and PHP session state control
44 * c) Performance metric deltas accumulated from request execution
45 * d) The site configuration object
46 * All these objects are useful for the vast majority of MediaWiki requests.
47 * The site configuration object is included on grounds of extreme
48 * utility, even though it should not depend on the web request.
50 * More specifically, the scope of the context includes:
51 * a) Objects that represent the HTTP request/response and PHP session state
52 * b) Object representing the MediaWiki user (as determined by the HTTP request)
53 * c) Primary MediaWiki output builder objects (OutputPage, user skin object)
54 * d) The language object for the user/request
55 * e) The title and wiki page objects requested via URL (if any)
56 * f) Performance metric deltas accumulated from request execution
57 * g) The site configuration object
59 * This class is not intended as a service-locator nor a service singleton.
60 * Objects that only depend on site configuration do not belong here (aside
61 * from Config itself). Objects that represent persistent data stores do not
62 * belong here either. Session state changes should only be propagated on
63 * shutdown by separate persistence handler objects, for example.
65 * Must not be implemented directly by extensions, extend ContextSource instead.
71 interface IContextSource
extends LocalizationContext
, CsrfTokenSetProvider
{
76 public function getRequest();
81 public function getTitle();
84 * Check whether a WikiPage object can be obtained with getWikiPage().
86 * Callers should expect that an exception is thrown from getWikiPage()
87 * if this method returns false.
92 public function canUseWikiPage();
95 * Get the WikiPage object.
97 * May throw an exception if there's no Title object set or the Title object
98 * belongs to a special namespace that doesn't have WikiPage, so use first
99 * canUseWikiPage() to check whether this method can be called safely.
104 public function getWikiPage();
107 * Get the action name for the current web request.
112 public function getActionName(): string;
117 public function getOutput();
122 public function getUser();
128 public function getAuthority(): Authority
;
134 public function getLanguage();
139 public function getSkin();
142 * Get the site configuration
147 public function getConfig();
153 public function getTiming();
156 * Export the resolved user IP, HTTP headers, user ID, and session ID.
158 * The result will be reasonably sized to allow for serialization.
163 public function exportSession();
166 /** @deprecated class alias since 1.42 */
167 class_alias( IContextSource
::class, 'IContextSource' );