Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / context / ContextSource.php
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 * @author Happy-melon
19 * @file
20 */
21 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
22
23 /**
24 * The simplest way of implementing IContextSource is to hold a RequestContext as a
25 * member variable and provide accessors to it.
26 *
27 * @since 1.18
28 */
29 abstract class ContextSource implements IContextSource {
30 /**
31 * @var IContextSource
32 */
33 private $context;
34
35 /**
36 * Get the base IContextSource object
37 * @since 1.18
38 * @return IContextSource
39 */
40 public function getContext() {
41 if ( $this->context === null ) {
42 $class = get_class( $this );
43 wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
44 "Using RequestContext::getMain() for sanity\n" );
45 $this->context = RequestContext::getMain();
46 }
47
48 return $this->context;
49 }
50
51 /**
52 * Set the IContextSource object
53 *
54 * @since 1.18
55 * @param IContextSource $context
56 */
57 public function setContext( IContextSource $context ) {
58 $this->context = $context;
59 }
60
61 /**
62 * Get the Config object
63 *
64 * @since 1.23
65 * @return Config
66 */
67 public function getConfig() {
68 return $this->getContext()->getConfig();
69 }
70
71 /**
72 * Get the WebRequest object
73 *
74 * @since 1.18
75 * @return WebRequest
76 */
77 public function getRequest() {
78 return $this->getContext()->getRequest();
79 }
80
81 /**
82 * Get the Title object
83 *
84 * @since 1.18
85 * @return Title|null
86 */
87 public function getTitle() {
88 return $this->getContext()->getTitle();
89 }
90
91 /**
92 * Check whether a WikiPage object can be get with getWikiPage().
93 * Callers should expect that an exception is thrown from getWikiPage()
94 * if this method returns false.
95 *
96 * @since 1.19
97 * @return bool
98 */
99 public function canUseWikiPage() {
100 return $this->getContext()->canUseWikiPage();
101 }
102
103 /**
104 * Get the WikiPage object.
105 * May throw an exception if there's no Title object set or the Title object
106 * belongs to a special namespace that doesn't have WikiPage, so use first
107 * canUseWikiPage() to check whether this method can be called safely.
108 *
109 * @since 1.19
110 * @return WikiPage
111 */
112 public function getWikiPage() {
113 return $this->getContext()->getWikiPage();
114 }
115
116 /**
117 * Get the OutputPage object
118 *
119 * @since 1.18
120 * @return OutputPage
121 */
122 public function getOutput() {
123 return $this->getContext()->getOutput();
124 }
125
126 /**
127 * Get the User object
128 *
129 * @since 1.18
130 * @return User
131 */
132 public function getUser() {
133 return $this->getContext()->getUser();
134 }
135
136 /**
137 * Get the Language object
138 *
139 * @since 1.19
140 * @return Language
141 */
142 public function getLanguage() {
143 return $this->getContext()->getLanguage();
144 }
145
146 /**
147 * Get the Skin object
148 *
149 * @since 1.18
150 * @return Skin
151 */
152 public function getSkin() {
153 return $this->getContext()->getSkin();
154 }
155
156 /**
157 * Get the Timing object
158 *
159 * @since 1.27
160 * @return Timing
161 */
162 public function getTiming() {
163 return $this->getContext()->getTiming();
164 }
165
166 /**
167 * Get the Stats object
168 *
169 * @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
170 *
171 * @since 1.25
172 * @return StatsdDataFactory
173 */
174 public function getStats() {
175 return $this->getContext()->getStats();
176 }
177
178 /**
179 * Get a Message object with context set
180 * Parameters are the same as wfMessage()
181 *
182 * @since 1.18
183 * @param mixed ...
184 * @return Message
185 */
186 public function msg( /* $args */ ) {
187 $args = func_get_args();
188
189 return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
190 }
191
192 /**
193 * Export the resolved user IP, HTTP headers, user ID, and session ID.
194 * The result will be reasonably sized to allow for serialization.
195 *
196 * @return array
197 * @since 1.21
198 */
199 public function exportSession() {
200 return $this->getContext()->exportSession();
201 }
202 }