Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
ContextSource | |
0.00% |
0 / 23 |
|
0.00% |
0 / 18 |
380 | |
0.00% |
0 / 1 |
getContext | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
setContext | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRequest | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
canUseWikiPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWikiPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getActionName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOutput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthority | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguageCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSkin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTiming | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
msg | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
exportSession | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCsrfTokenSet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Context; |
22 | |
23 | use MediaWiki\Config\Config; |
24 | use MediaWiki\Language\Language; |
25 | use MediaWiki\Message\Message; |
26 | use MediaWiki\Output\OutputPage; |
27 | use MediaWiki\Permissions\Authority; |
28 | use MediaWiki\Request\WebRequest; |
29 | use MediaWiki\Session\CsrfTokenSet; |
30 | use MediaWiki\Title\Title; |
31 | use MediaWiki\User\User; |
32 | use Skin; |
33 | use Timing; |
34 | use Wikimedia\Bcp47Code\Bcp47Code; |
35 | use Wikimedia\Message\MessageParam; |
36 | use Wikimedia\Message\MessageSpecifier; |
37 | use Wikimedia\NonSerializable\NonSerializableTrait; |
38 | use WikiPage; |
39 | |
40 | /** |
41 | * The simplest way of implementing IContextSource is to hold a RequestContext as a |
42 | * member variable and provide accessors to it. |
43 | * |
44 | * @stable to extend |
45 | * @since 1.18 |
46 | * @author Happy-melon |
47 | */ |
48 | abstract class ContextSource implements IContextSource { |
49 | use NonSerializableTrait; |
50 | |
51 | /** |
52 | * @var IContextSource |
53 | */ |
54 | private $context; |
55 | |
56 | /** |
57 | * Get the base IContextSource object |
58 | * @since 1.18 |
59 | * @stable to override |
60 | * @return IContextSource |
61 | */ |
62 | public function getContext() { |
63 | if ( $this->context === null ) { |
64 | $class = static::class; |
65 | wfDebug( __METHOD__ . " ($class): called and \$context is null. " . |
66 | "Using RequestContext::getMain()" ); |
67 | $this->context = RequestContext::getMain(); |
68 | } |
69 | |
70 | return $this->context; |
71 | } |
72 | |
73 | /** |
74 | * @since 1.18 |
75 | * @stable to override |
76 | * @param IContextSource $context |
77 | */ |
78 | public function setContext( IContextSource $context ) { |
79 | $this->context = $context; |
80 | } |
81 | |
82 | /** |
83 | * @since 1.23 |
84 | * @stable to override |
85 | * @return Config |
86 | */ |
87 | public function getConfig() { |
88 | return $this->getContext()->getConfig(); |
89 | } |
90 | |
91 | /** |
92 | * @since 1.18 |
93 | * @stable to override |
94 | * @return WebRequest |
95 | */ |
96 | public function getRequest() { |
97 | return $this->getContext()->getRequest(); |
98 | } |
99 | |
100 | /** |
101 | * @since 1.18 |
102 | * @stable to override |
103 | * @return Title|null |
104 | */ |
105 | public function getTitle() { |
106 | return $this->getContext()->getTitle(); |
107 | } |
108 | |
109 | /** |
110 | * Check whether a WikiPage object can be get with getWikiPage(). |
111 | * Callers should expect that an exception is thrown from getWikiPage() |
112 | * if this method returns false. |
113 | * |
114 | * @since 1.19 |
115 | * @stable to override |
116 | * @return bool |
117 | */ |
118 | public function canUseWikiPage() { |
119 | return $this->getContext()->canUseWikiPage(); |
120 | } |
121 | |
122 | /** |
123 | * Get the WikiPage object. |
124 | * May throw an exception if there's no Title object set or the Title object |
125 | * belongs to a special namespace that doesn't have WikiPage, so use first |
126 | * canUseWikiPage() to check whether this method can be called safely. |
127 | * |
128 | * @since 1.19 |
129 | * @stable to override |
130 | * @return WikiPage |
131 | */ |
132 | public function getWikiPage() { |
133 | return $this->getContext()->getWikiPage(); |
134 | } |
135 | |
136 | /** |
137 | * Get the action name for the current web request. |
138 | * |
139 | * @since 1.38 |
140 | * @stable to override |
141 | * @return string |
142 | */ |
143 | public function getActionName(): string { |
144 | return $this->getContext()->getActionName(); |
145 | } |
146 | |
147 | /** |
148 | * @since 1.18 |
149 | * @stable to override |
150 | * @return OutputPage |
151 | */ |
152 | public function getOutput() { |
153 | return $this->getContext()->getOutput(); |
154 | } |
155 | |
156 | /** |
157 | * @stable to override |
158 | * @since 1.18 |
159 | * @stable to override |
160 | * @return User |
161 | */ |
162 | public function getUser() { |
163 | return $this->getContext()->getUser(); |
164 | } |
165 | |
166 | /** |
167 | * @since 1.36 |
168 | * @return Authority |
169 | */ |
170 | public function getAuthority(): Authority { |
171 | return $this->getContext()->getAuthority(); |
172 | } |
173 | |
174 | /** |
175 | * @since 1.19 |
176 | * @stable to override |
177 | * @return Language |
178 | */ |
179 | public function getLanguage() { |
180 | return $this->getContext()->getLanguage(); |
181 | } |
182 | |
183 | /** |
184 | * @since 1.42 |
185 | * @stable to override |
186 | * @note When overriding, keep consistent with getLanguage()! |
187 | * @return Bcp47Code |
188 | */ |
189 | public function getLanguageCode(): Bcp47Code { |
190 | return $this->getLanguage(); |
191 | } |
192 | |
193 | /** |
194 | * @since 1.18 |
195 | * @stable to override |
196 | * @return Skin |
197 | */ |
198 | public function getSkin() { |
199 | return $this->getContext()->getSkin(); |
200 | } |
201 | |
202 | /** |
203 | * @since 1.27 |
204 | * @stable to override |
205 | * @return Timing |
206 | */ |
207 | public function getTiming() { |
208 | return $this->getContext()->getTiming(); |
209 | } |
210 | |
211 | /** |
212 | * Get a Message object with context set |
213 | * Parameters are the same as wfMessage() |
214 | * |
215 | * @since 1.18 |
216 | * @stable to override |
217 | * @param string|string[]|MessageSpecifier $key Message key, or array of keys, |
218 | * or a MessageSpecifier. |
219 | * @phpcs:ignore Generic.Files.LineLength |
220 | * @param MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> ...$params |
221 | * See Message::params() |
222 | * @return Message |
223 | */ |
224 | public function msg( $key, ...$params ) { |
225 | return $this->getContext()->msg( $key, ...$params ); |
226 | } |
227 | |
228 | /** |
229 | * Export the resolved user IP, HTTP headers, user ID, and session ID. |
230 | * The result will be reasonably sized to allow for serialization. |
231 | * |
232 | * @since 1.21 |
233 | * @stable to override |
234 | * @return array |
235 | */ |
236 | public function exportSession() { |
237 | return $this->getContext()->exportSession(); |
238 | } |
239 | |
240 | /** |
241 | * Get a repository to obtain and match CSRF tokens. |
242 | * |
243 | * @return CsrfTokenSet |
244 | * @since 1.37 |
245 | */ |
246 | public function getCsrfTokenSet(): CsrfTokenSet { |
247 | return $this->getContext()->getCsrfTokenSet(); |
248 | } |
249 | } |
250 | |
251 | /** @deprecated class alias since 1.42 */ |
252 | class_alias( ContextSource::class, 'ContextSource' ); |