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
22 * @author Daniel Friesen
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
{
66 * @param $context IContextSource Context to inherit from
68 public function __construct( IContextSource
$context ) {
69 $this->setContext( $context );
73 * Set the WebRequest object
75 * @param $r WebRequest object
77 public function setRequest( WebRequest
$r ) {
82 * Get the WebRequest object
86 public function getRequest() {
87 if ( !is_null( $this->request
) ) {
88 return $this->request
;
90 return $this->getContext()->getRequest();
95 * Set the Title object
97 * @param $t Title object
99 public function setTitle( Title
$t ) {
104 * Get the Title object
108 public function getTitle() {
109 if ( !is_null( $this->title
) ) {
112 return $this->getContext()->getTitle();
117 * @param $o OutputPage
119 public function setOutput( OutputPage
$o ) {
124 * Get the OutputPage object
126 * @return OutputPage object
128 public function getOutput() {
129 if ( !is_null( $this->output
) ) {
130 return $this->output
;
132 return $this->getContext()->getOutput();
137 * Set the User object
141 public function setUser( User
$u ) {
146 * Get the User object
150 public function getUser() {
151 if ( !is_null( $this->user
) ) {
154 return $this->getContext()->getUser();
159 * Set the Language object
161 * @deprecated 1.19 Use setLanguage instead
162 * @param $l Mixed Language instance or language code
164 public function setLang( $l ) {
165 $this->setLanguage( $l );
169 * Set the Language object
171 * @param $l Mixed Language instance or language code
174 public function setLanguage( $l ) {
175 if ( $l instanceof Language
) {
177 } elseif ( is_string( $l ) ) {
178 $l = RequestContext
::sanitizeLangCode( $l );
179 $obj = Language
::factory( $l );
182 throw new MWException( __METHOD__
. " was passed an invalid type of data." );
187 * @deprecated 1.19 Use getLanguage instead
190 public function getLang() {
191 $this->getLanguage();
195 * Get the Language object
200 public function getLanguage() {
201 if ( !is_null( $this->lang
) ) {
204 return $this->getContext()->getLanguage();
209 * Set the Skin object
213 public function setSkin( Skin
$s ) {
214 $this->skin
= clone $s;
215 $this->skin
->setContext( $this );
219 * Get the Skin object
223 public function getSkin() {
224 if ( !is_null( $this->skin
) ) {
227 return $this->getContext()->getSkin();