add missing deprecation notices and added deprecation version to existing ones
[lhc/web/wiklou.git] / includes / context / DerivativeContext.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.19
21 *
22 * @author Daniel Friesen
23 * @file
24 */
25
26 /**
27 * An IContextSource implementation which will inherit context from another source
28 * but allow individual pieces of context to be changed locally
29 * eg: A ContextSource that can inherit from the main RequestContext but have
30 * a different Title instance set on it.
31 */
32 class DerivativeContext extends ContextSource {
33
34 /**
35 * @var WebRequest
36 */
37 private $request;
38
39 /**
40 * @var Title
41 */
42 private $title;
43
44 /**
45 * @var OutputPage
46 */
47 private $output;
48
49 /**
50 * @var User
51 */
52 private $user;
53
54 /**
55 * @var Language
56 */
57 private $lang;
58
59 /**
60 * @var Skin
61 */
62 private $skin;
63
64 /**
65 * Constructor
66 * @param $context IContextSource Context to inherit from
67 */
68 public function __construct( IContextSource $context ) {
69 $this->setContext( $context );
70 }
71
72 /**
73 * Set the WebRequest object
74 *
75 * @param $r WebRequest object
76 */
77 public function setRequest( WebRequest $r ) {
78 $this->request = $r;
79 }
80
81 /**
82 * Get the WebRequest object
83 *
84 * @return WebRequest
85 */
86 public function getRequest() {
87 if ( !is_null( $this->request ) ) {
88 return $this->request;
89 } else {
90 return $this->getContext()->getRequest();
91 }
92 }
93
94 /**
95 * Set the Title object
96 *
97 * @param $t Title object
98 */
99 public function setTitle( Title $t ) {
100 $this->title = $t;
101 }
102
103 /**
104 * Get the Title object
105 *
106 * @return Title
107 */
108 public function getTitle() {
109 if ( !is_null( $this->title ) ) {
110 return $this->title;
111 } else {
112 return $this->getContext()->getTitle();
113 }
114 }
115
116 /**
117 * @param $o OutputPage
118 */
119 public function setOutput( OutputPage $o ) {
120 $this->output = $o;
121 }
122
123 /**
124 * Get the OutputPage object
125 *
126 * @return OutputPage object
127 */
128 public function getOutput() {
129 if ( !is_null( $this->output ) ) {
130 return $this->output;
131 } else {
132 return $this->getContext()->getOutput();
133 }
134 }
135
136 /**
137 * Set the User object
138 *
139 * @param $u User
140 */
141 public function setUser( User $u ) {
142 $this->user = $u;
143 }
144
145 /**
146 * Get the User object
147 *
148 * @return User
149 */
150 public function getUser() {
151 if ( !is_null( $this->user ) ) {
152 return $this->user;
153 } else {
154 return $this->getContext()->getUser();
155 }
156 }
157
158 /**
159 * Set the Language object
160 *
161 * @deprecated 1.19 Use setLanguage instead
162 * @param $l Mixed Language instance or language code
163 */
164 public function setLang( $l ) {
165 wfDeprecated( __METHOD__, '1.19' );
166 $this->setLanguage( $l );
167 }
168
169 /**
170 * Set the Language object
171 *
172 * @param $l Mixed Language instance or language code
173 * @since 1.19
174 */
175 public function setLanguage( $l ) {
176 if ( $l instanceof Language ) {
177 $this->lang = $l;
178 } elseif ( is_string( $l ) ) {
179 $l = RequestContext::sanitizeLangCode( $l );
180 $obj = Language::factory( $l );
181 $this->lang = $obj;
182 } else {
183 throw new MWException( __METHOD__ . " was passed an invalid type of data." );
184 }
185 }
186
187 /**
188 * @deprecated 1.19 Use getLanguage instead
189 * @return Language
190 */
191 public function getLang() {
192 wfDeprecated( __METHOD__, '1.19' );
193 $this->getLanguage();
194 }
195
196 /**
197 * Get the Language object
198 *
199 * @return Language
200 * @since 1.19
201 */
202 public function getLanguage() {
203 if ( !is_null( $this->lang ) ) {
204 return $this->lang;
205 } else {
206 return $this->getContext()->getLanguage();
207 }
208 }
209
210 /**
211 * Set the Skin object
212 *
213 * @param $s Skin
214 */
215 public function setSkin( Skin $s ) {
216 $this->skin = clone $s;
217 $this->skin->setContext( $this );
218 }
219
220 /**
221 * Get the Skin object
222 *
223 * @return Skin
224 */
225 public function getSkin() {
226 if ( !is_null( $this->skin ) ) {
227 return $this->skin;
228 } else {
229 return $this->getContext()->getSkin();
230 }
231 }
232
233 }
234