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
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
{
37 * Get the RequestContext object
39 * @return RequestContext
41 public function getContext() {
42 if ( $this->context
=== null ) {
43 $class = get_class( $this );
44 wfDebug( __METHOD__
. " ($class): called and \$context is null. " .
45 "Using RequestContext::getMain() for sanity\n" );
46 $this->context
= RequestContext
::getMain();
49 return $this->context
;
53 * Set the IContextSource object
56 * @param IContextSource $context
58 public function setContext( IContextSource
$context ) {
59 $this->context
= $context;
63 * Get the Config object
68 public function getConfig() {
69 return $this->getContext()->getConfig();
73 * Get the WebRequest object
78 public function getRequest() {
79 return $this->getContext()->getRequest();
83 * Get the Title object
88 public function getTitle() {
89 return $this->getContext()->getTitle();
93 * Check whether a WikiPage object can be get with getWikiPage().
94 * Callers should expect that an exception is thrown from getWikiPage()
95 * if this method returns false.
100 public function canUseWikiPage() {
101 return $this->getContext()->canUseWikiPage();
105 * Get the WikiPage object.
106 * May throw an exception if there's no Title object set or the Title object
107 * belongs to a special namespace that doesn't have WikiPage, so use first
108 * canUseWikiPage() to check whether this method can be called safely.
113 public function getWikiPage() {
114 return $this->getContext()->getWikiPage();
118 * Get the OutputPage object
123 public function getOutput() {
124 return $this->getContext()->getOutput();
128 * Get the User object
133 public function getUser() {
134 return $this->getContext()->getUser();
138 * Get the Language object
140 * @deprecated since 1.19 Use getLanguage instead
143 public function getLang() {
144 wfDeprecated( __METHOD__
, '1.19' );
146 return $this->getLanguage();
150 * Get the Language object
155 public function getLanguage() {
156 return $this->getContext()->getLanguage();
160 * Get the Skin object
165 public function getSkin() {
166 return $this->getContext()->getSkin();
170 * Get a Message object with context set
171 * Parameters are the same as wfMessage()
176 public function msg( /* $args */ ) {
177 $args = func_get_args();
179 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
183 * Export the resolved user IP, HTTP headers, user ID, and session ID.
184 * The result will be reasonably sized to allow for serialization.
189 public function exportSession() {
190 return $this->getContext()->exportSession();