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
{
75 * @param IContextSource $context Context to inherit from
77 public function __construct( IContextSource
$context ) {
78 $this->setContext( $context );
82 * Set the SiteConfiguration object
86 public function setConfig( Config
$s ) {
91 * Get the Config object
95 public function getConfig() {
96 if ( !is_null( $this->config
) ) {
99 return $this->getContext()->getConfig();
104 * Set the WebRequest object
106 * @param WebRequest $r
108 public function setRequest( WebRequest
$r ) {
113 * Get the WebRequest object
117 public function getRequest() {
118 if ( !is_null( $this->request
) ) {
119 return $this->request
;
121 return $this->getContext()->getRequest();
126 * Set the Title object
130 public function setTitle( Title
$t ) {
135 * Get the Title object
139 public function getTitle() {
140 if ( !is_null( $this->title
) ) {
143 return $this->getContext()->getTitle();
148 * Check whether a WikiPage object can be get with getWikiPage().
149 * Callers should expect that an exception is thrown from getWikiPage()
150 * if this method returns false.
155 public function canUseWikiPage() {
156 if ( $this->wikipage
!== null ) {
158 } elseif ( $this->title
!== null ) {
159 return $this->title
->canExist();
161 return $this->getContext()->canUseWikiPage();
166 * Set the WikiPage object
171 public function setWikiPage( WikiPage
$p ) {
172 $this->wikipage
= $p;
176 * Get the WikiPage object.
177 * May throw an exception if there's no Title object set or the Title object
178 * belongs to a special namespace that doesn't have WikiPage, so use first
179 * canUseWikiPage() to check whether this method can be called safely.
184 public function getWikiPage() {
185 if ( !is_null( $this->wikipage
) ) {
186 return $this->wikipage
;
188 return $this->getContext()->getWikiPage();
193 * Set the OutputPage object
195 * @param OutputPage $o
197 public function setOutput( OutputPage
$o ) {
202 * Get the OutputPage object
206 public function getOutput() {
207 if ( !is_null( $this->output
) ) {
208 return $this->output
;
210 return $this->getContext()->getOutput();
215 * Set the User object
219 public function setUser( User
$u ) {
224 * Get the User object
228 public function getUser() {
229 if ( !is_null( $this->user
) ) {
232 return $this->getContext()->getUser();
237 * Set the Language object
239 * @param Language|string $l Language instance or language code
240 * @throws MWException
243 public function setLanguage( $l ) {
244 if ( $l instanceof Language
) {
246 } elseif ( is_string( $l ) ) {
247 $l = RequestContext
::sanitizeLangCode( $l );
248 $obj = Language
::factory( $l );
251 throw new MWException( __METHOD__
. " was passed an invalid type of data." );
256 * Get the Language object
261 public function getLanguage() {
262 if ( !is_null( $this->lang
) ) {
265 return $this->getContext()->getLanguage();
270 * Set the Skin object
274 public function setSkin( Skin
$s ) {
275 $this->skin
= clone $s;
276 $this->skin
->setContext( $this );
280 * Get the Skin object
284 public function getSkin() {
285 if ( !is_null( $this->skin
) ) {
288 return $this->getContext()->getSkin();
293 * Get a message using the current context.
295 * This can't just inherit from ContextSource, since then
296 * it would set only the original context, and not take
297 * into account any changes.
299 * @param mixed $args,... Arguments to wfMessage
302 public function msg() {
303 $args = func_get_args();
305 return call_user_func_array( 'wfMessage', $args )->setContext( $this );