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