836aef98b4965a99e93d113d7914d5a2fe1b5ac6
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @author Daniel Friesen
23 * An IContextSource implementation which will inherit context from another source
24 * but allow individual pieces of context to be changed locally
25 * eg: A ContextSource that can inherit from the main RequestContext but have
26 * a different Title instance set on it.
29 class DerivativeContext
extends ContextSource
{
72 * @param IContextSource $context Context to inherit from
74 public function __construct( IContextSource
$context ) {
75 $this->setContext( $context );
79 * Set the SiteConfiguration object
83 public function setConfig( Config
$s ) {
88 * Get the Config object
92 public function getConfig() {
93 if ( !is_null( $this->config
) ) {
96 return $this->getContext()->getConfig();
101 * Set the WebRequest object
103 * @param WebRequest $r
105 public function setRequest( WebRequest
$r ) {
110 * Get the WebRequest object
114 public function getRequest() {
115 if ( !is_null( $this->request
) ) {
116 return $this->request
;
118 return $this->getContext()->getRequest();
123 * Set the Title object
127 public function setTitle( Title
$t ) {
132 * Get the Title object
136 public function getTitle() {
137 if ( !is_null( $this->title
) ) {
140 return $this->getContext()->getTitle();
145 * Check whether a WikiPage object can be get with getWikiPage().
146 * Callers should expect that an exception is thrown from getWikiPage()
147 * if this method returns false.
152 public function canUseWikiPage() {
153 if ( $this->wikipage
!== null ) {
155 } elseif ( $this->title
!== null ) {
156 return $this->title
->canExist();
158 return $this->getContext()->canUseWikiPage();
163 * Set the WikiPage object
168 public function setWikiPage( WikiPage
$p ) {
169 $this->wikipage
= $p;
173 * Get the WikiPage object.
174 * May throw an exception if there's no Title object set or the Title object
175 * belongs to a special namespace that doesn't have WikiPage, so use first
176 * canUseWikiPage() to check whether this method can be called safely.
181 public function getWikiPage() {
182 if ( !is_null( $this->wikipage
) ) {
183 return $this->wikipage
;
185 return $this->getContext()->getWikiPage();
190 * Set the OutputPage object
192 * @param OutputPage $o
194 public function setOutput( OutputPage
$o ) {
199 * Get the OutputPage object
203 public function getOutput() {
204 if ( !is_null( $this->output
) ) {
205 return $this->output
;
207 return $this->getContext()->getOutput();
212 * Set the User object
216 public function setUser( User
$u ) {
221 * Get the User object
225 public function getUser() {
226 if ( !is_null( $this->user
) ) {
229 return $this->getContext()->getUser();
234 * Set the Language object
236 * @param Language|string $l Language instance or language code
237 * @throws MWException
240 public function setLanguage( $l ) {
241 if ( $l instanceof Language
) {
243 } elseif ( is_string( $l ) ) {
244 $l = RequestContext
::sanitizeLangCode( $l );
245 $obj = Language
::factory( $l );
248 throw new MWException( __METHOD__
. " was passed an invalid type of data." );
253 * Get the Language object
258 public function getLanguage() {
259 if ( !is_null( $this->lang
) ) {
262 return $this->getContext()->getLanguage();
267 * Set the Skin object
271 public function setSkin( Skin
$s ) {
272 $this->skin
= clone $s;
273 $this->skin
->setContext( $this );
277 * Get the Skin object
281 public function getSkin() {
282 if ( !is_null( $this->skin
) ) {
285 return $this->getContext()->getSkin();
290 * Get a message using the current context.
292 * This can't just inherit from ContextSource, since then
293 * it would set only the original context, and not take
294 * into account any changes.
296 * @param mixed $args,... Arguments to wfMessage
299 public function msg() {
300 $args = func_get_args();
302 return call_user_func_array( 'wfMessage', $args )->setContext( $this );