Release notes for Iabf4873f
[mediawiki.git] / includes / context / ContextSource.php
blob0a3f18ff0fb7ec28191dd50bd079e55d1924c7e1
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 {
31 /**
32 * @var IContextSource
34 private $context;
36 /**
37 * Get the RequestContext object
38 * @since 1.18
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;
52 /**
53 * Set the IContextSource object
55 * @since 1.18
56 * @param IContextSource $context
58 public function setContext( IContextSource $context ) {
59 $this->context = $context;
62 /**
63 * Get the WebRequest object
65 * @since 1.18
66 * @return WebRequest
68 public function getRequest() {
69 return $this->getContext()->getRequest();
72 /**
73 * Get the Title object
75 * @since 1.18
76 * @return Title
78 public function getTitle() {
79 return $this->getContext()->getTitle();
82 /**
83 * Check whether a WikiPage object can be get with getWikiPage().
84 * Callers should expect that an exception is thrown from getWikiPage()
85 * if this method returns false.
87 * @since 1.19
88 * @return bool
90 public function canUseWikiPage() {
91 return $this->getContext()->canUseWikiPage();
94 /**
95 * Get the WikiPage object.
96 * May throw an exception if there's no Title object set or the Title object
97 * belongs to a special namespace that doesn't have WikiPage, so use first
98 * canUseWikiPage() to check whether this method can be called safely.
100 * @since 1.19
101 * @return WikiPage
103 public function getWikiPage() {
104 return $this->getContext()->getWikiPage();
108 * Get the OutputPage object
110 * @since 1.18
111 * @return OutputPage
113 public function getOutput() {
114 return $this->getContext()->getOutput();
118 * Get the User object
120 * @since 1.18
121 * @return User
123 public function getUser() {
124 return $this->getContext()->getUser();
128 * Get the Language object
130 * @deprecated since 1.19 Use getLanguage instead
131 * @return Language
133 public function getLang() {
134 wfDeprecated( __METHOD__, '1.19' );
136 return $this->getLanguage();
140 * Get the Language object
142 * @since 1.19
143 * @return Language
145 public function getLanguage() {
146 return $this->getContext()->getLanguage();
150 * Get the Skin object
152 * @since 1.18
153 * @return Skin
155 public function getSkin() {
156 return $this->getContext()->getSkin();
160 * Get a Message object with context set
161 * Parameters are the same as wfMessage()
163 * @since 1.18
164 * @return Message
166 public function msg( /* $args */ ) {
167 $args = func_get_args();
169 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
173 * Export the resolved user IP, HTTP headers, user ID, and session ID.
174 * The result will be reasonably sized to allow for serialization.
176 * @return Array
177 * @since 1.21
179 public function exportSession() {
180 return $this->getContext()->exportSession();