Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / context / IContextSource.php
blobab8f19270d6b0d5229cfd016fedd2509fe66c7cf
1 <?php
2 /**
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
18 * @file
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;
32 use Skin;
33 use Timing;
34 use WikiPage;
36 /**
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.
67 * @since 1.18
68 * @stable to type
69 * @author Happy-melon
71 interface IContextSource extends LocalizationContext, CsrfTokenSetProvider {
73 /**
74 * @return WebRequest
76 public function getRequest();
78 /**
79 * @return Title|null
81 public function getTitle();
83 /**
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.
89 * @since 1.19
90 * @return bool
92 public function canUseWikiPage();
94 /**
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.
101 * @since 1.19
102 * @return WikiPage
104 public function getWikiPage();
107 * Get the action name for the current web request.
109 * @since 1.38
110 * @return string
112 public function getActionName(): string;
115 * @return OutputPage
117 public function getOutput();
120 * @return User
122 public function getUser();
125 * @since 1.36
126 * @return Authority
128 public function getAuthority(): Authority;
131 * @since 1.19
132 * @return Language
134 public function getLanguage();
137 * @return Skin
139 public function getSkin();
142 * Get the site configuration
144 * @since 1.23
145 * @return Config
147 public function getConfig();
150 * @since 1.27
151 * @return Timing
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.
160 * @return array
161 * @since 1.21
163 public function exportSession();
166 /** @deprecated class alias since 1.42 */
167 class_alias( IContextSource::class, 'IContextSource' );