Simplify the check to make it more understandable
[mediawiki.git] / includes / context / ContextSource.php
blob2fbc776712627b1ee5b12120a29c436d744bc61d
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.18
22 * @author Happy-melon
23 * @file
26 /**
27 * The simplest way of implementing IContextSource is to hold a RequestContext as a
28 * member variable and provide accessors to it.
30 abstract class ContextSource implements IContextSource {
32 /**
33 * @var IContextSource
35 private $context;
37 /**
38 * Get the RequestContext object
39 * @since 1.18
40 * @return RequestContext
42 public function getContext() {
43 if ( $this->context === null ) {
44 $class = get_class( $this );
45 wfDebug( __METHOD__ . " ($class): called and \$context is null. Using RequestContext::getMain() for sanity\n" );
46 $this->context = RequestContext::getMain();
48 return $this->context;
51 /**
52 * Set the IContextSource object
54 * @since 1.18
55 * @param $context IContextSource
57 public function setContext( IContextSource $context ) {
58 $this->context = $context;
61 /**
62 * Get the WebRequest object
64 * @since 1.18
65 * @return WebRequest
67 public function getRequest() {
68 return $this->getContext()->getRequest();
71 /**
72 * Get the Title object
74 * @since 1.18
75 * @return Title
77 public function getTitle() {
78 return $this->getContext()->getTitle();
81 /**
82 * Get the WikiPage object
84 * @since 1.19
85 * @return WikiPage
87 public function getWikiPage() {
88 return $this->getContext()->getWikiPage();
91 /**
92 * Get the OutputPage object
94 * @since 1.18
95 * @return OutputPage object
97 public function getOutput() {
98 return $this->getContext()->getOutput();
102 * Get the User object
104 * @since 1.18
105 * @return User
107 public function getUser() {
108 return $this->getContext()->getUser();
112 * Get the Language object
114 * @deprecated 1.19 Use getLanguage instead
115 * @return Language
117 public function getLang() {
118 wfDeprecated( __METHOD__, '1.19' );
119 return $this->getLanguage();
123 * Get the Language object
125 * @since 1.19
126 * @return Language
128 public function getLanguage() {
129 return $this->getContext()->getLanguage();
133 * Get the Skin object
135 * @since 1.18
136 * @return Skin
138 public function getSkin() {
139 return $this->getContext()->getSkin();
143 * Get a Message object with context set
144 * Parameters are the same as wfMessage()
146 * @since 1.18
147 * @return Message object
149 public function msg( /* $args */ ) {
150 $args = func_get_args();
151 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );