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