Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / context / DerivativeContext.php
blob5adf3621b3f719e4cf4906595da942bd079ef87e
1 <?php
2 /**
3 * Request-dependant objects containers.
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.
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.
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
20 * @since 1.19
22 * @author Daniel Friesen
23 * @file
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.
32 class DerivativeContext extends ContextSource {
34 /**
35 * @var WebRequest
37 private $request;
39 /**
40 * @var Title
42 private $title;
44 /**
45 * @var WikiPage
47 private $wikipage;
49 /**
50 * @var OutputPage
52 private $output;
54 /**
55 * @var User
57 private $user;
59 /**
60 * @var Language
62 private $lang;
64 /**
65 * @var Skin
67 private $skin;
69 /**
70 * Constructor
71 * @param $context IContextSource Context to inherit from
73 public function __construct( IContextSource $context ) {
74 $this->setContext( $context );
77 /**
78 * Set the WebRequest object
80 * @param $r WebRequest object
82 public function setRequest( WebRequest $r ) {
83 $this->request = $r;
86 /**
87 * Get the WebRequest object
89 * @return WebRequest
91 public function getRequest() {
92 if ( !is_null( $this->request ) ) {
93 return $this->request;
94 } else {
95 return $this->getContext()->getRequest();
99 /**
100 * Set the Title object
102 * @param $t Title object
104 public function setTitle( Title $t ) {
105 $this->title = $t;
109 * Get the Title object
111 * @return Title
113 public function getTitle() {
114 if ( !is_null( $this->title ) ) {
115 return $this->title;
116 } else {
117 return $this->getContext()->getTitle();
122 * Check whether a WikiPage object can be get with getWikiPage().
123 * Callers should expect that an exception is thrown from getWikiPage()
124 * if this method returns false.
126 * @since 1.19
127 * @return bool
129 public function canUseWikiPage() {
130 if ( $this->wikipage !== null ) {
131 return true;
132 } elseif ( $this->title !== null ) {
133 return $this->title->canExist();
134 } else {
135 return $this->getContext()->canUseWikiPage();
140 * Set the WikiPage object
142 * @since 1.19
143 * @param $p WikiPage object
145 public function setWikiPage( WikiPage $p ) {
146 $this->wikipage = $p;
150 * Get the WikiPage object.
151 * May throw an exception if there's no Title object set or the Title object
152 * belongs to a special namespace that doesn't have WikiPage, so use first
153 * canUseWikiPage() to check whether this method can be called safely.
155 * @since 1.19
156 * @return WikiPage
158 public function getWikiPage() {
159 if ( !is_null( $this->wikipage ) ) {
160 return $this->wikipage;
161 } else {
162 return $this->getContext()->getWikiPage();
167 * Set the OutputPage object
169 * @param $o OutputPage
171 public function setOutput( OutputPage $o ) {
172 $this->output = $o;
176 * Get the OutputPage object
178 * @return OutputPage object
180 public function getOutput() {
181 if ( !is_null( $this->output ) ) {
182 return $this->output;
183 } else {
184 return $this->getContext()->getOutput();
189 * Set the User object
191 * @param $u User
193 public function setUser( User $u ) {
194 $this->user = $u;
198 * Get the User object
200 * @return User
202 public function getUser() {
203 if ( !is_null( $this->user ) ) {
204 return $this->user;
205 } else {
206 return $this->getContext()->getUser();
211 * Set the Language object
213 * @deprecated 1.19 Use setLanguage instead
214 * @param $l Mixed Language instance or language code
216 public function setLang( $l ) {
217 wfDeprecated( __METHOD__, '1.19' );
218 $this->setLanguage( $l );
222 * Set the Language object
224 * @param $l Mixed Language instance or language code
225 * @since 1.19
227 public function setLanguage( $l ) {
228 if ( $l instanceof Language ) {
229 $this->lang = $l;
230 } elseif ( is_string( $l ) ) {
231 $l = RequestContext::sanitizeLangCode( $l );
232 $obj = Language::factory( $l );
233 $this->lang = $obj;
234 } else {
235 throw new MWException( __METHOD__ . " was passed an invalid type of data." );
240 * @deprecated 1.19 Use getLanguage instead
241 * @return Language
243 public function getLang() {
244 wfDeprecated( __METHOD__, '1.19' );
245 $this->getLanguage();
249 * Get the Language object
251 * @return Language
252 * @since 1.19
254 public function getLanguage() {
255 if ( !is_null( $this->lang ) ) {
256 return $this->lang;
257 } else {
258 return $this->getContext()->getLanguage();
263 * Set the Skin object
265 * @param $s Skin
267 public function setSkin( Skin $s ) {
268 $this->skin = clone $s;
269 $this->skin->setContext( $this );
273 * Get the Skin object
275 * @return Skin
277 public function getSkin() {
278 if ( !is_null( $this->skin ) ) {
279 return $this->skin;
280 } else {
281 return $this->getContext()->getSkin();