Begin exposing SiteConfiguration via site contexts
[lhc/web/wiklou.git] / includes / context / ContextSource.php
1 <?php
2 /**
3 * Request-dependant objects containers.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @since 1.18
21 *
22 * @author Happy-melon
23 * @file
24 */
25
26 /**
27 * The simplest way of implementing IContextSource is to hold a RequestContext as a
28 * member variable and provide accessors to it.
29 */
30 abstract class ContextSource implements IContextSource {
31 /**
32 * @var IContextSource
33 */
34 private $context;
35
36 /**
37 * Get the RequestContext object
38 * @since 1.18
39 * @return RequestContext
40 */
41 public function getContext() {
42 if ( $this->context === null ) {
43 $class = get_class( $this );
44 wfDebug( __METHOD__ . " ($class): called and \$context is null. Using RequestContext::getMain() for sanity\n" );
45 $this->context = RequestContext::getMain();
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 SiteConfiguration object
62 *
63 * @since 1.23
64 * @return SiteConfiguration
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
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 * @deprecated since 1.19 Use getLanguage instead
139 * @return Language
140 */
141 public function getLang() {
142 wfDeprecated( __METHOD__, '1.19' );
143 return $this->getLanguage();
144 }
145
146 /**
147 * Get the Language object
148 *
149 * @since 1.19
150 * @return Language
151 */
152 public function getLanguage() {
153 return $this->getContext()->getLanguage();
154 }
155
156 /**
157 * Get the Skin object
158 *
159 * @since 1.18
160 * @return Skin
161 */
162 public function getSkin() {
163 return $this->getContext()->getSkin();
164 }
165
166 /**
167 * Get a Message object with context set
168 * Parameters are the same as wfMessage()
169 *
170 * @since 1.18
171 * @return Message
172 */
173 public function msg( /* $args */ ) {
174 $args = func_get_args();
175 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
176 }
177
178 /**
179 * Export the resolved user IP, HTTP headers, user ID, and session ID.
180 * The result will be reasonably sized to allow for serialization.
181 *
182 * @return Array
183 * @since 1.21
184 */
185 public function exportSession() {
186 return $this->getContext()->exportSession();
187 }
188 }