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
23 * The simplest way of implementing IContextSource is to hold a RequestContext as a
24 * member variable and provide accessors to it.
28 abstract class ContextSource
implements IContextSource
{
35 * Get the base IContextSource object
37 * @return IContextSource
39 public function getContext() {
40 if ( $this->context
=== null ) {
41 $class = get_class( $this );
42 wfDebug( __METHOD__
. " ($class): called and \$context is null. " .
43 "Using RequestContext::getMain() for sanity\n" );
44 $this->context
= RequestContext
::getMain();
47 return $this->context
;
51 * Set the IContextSource object
54 * @param IContextSource $context
56 public function setContext( IContextSource
$context ) {
57 $this->context
= $context;
61 * Get the Config object
66 public function getConfig() {
67 return $this->getContext()->getConfig();
71 * Get the WebRequest object
76 public function getRequest() {
77 return $this->getContext()->getRequest();
81 * Get the Title object
86 public function getTitle() {
87 return $this->getContext()->getTitle();
91 * Check whether a WikiPage object can be get with getWikiPage().
92 * Callers should expect that an exception is thrown from getWikiPage()
93 * if this method returns false.
98 public function canUseWikiPage() {
99 return $this->getContext()->canUseWikiPage();
103 * Get the WikiPage object.
104 * May throw an exception if there's no Title object set or the Title object
105 * belongs to a special namespace that doesn't have WikiPage, so use first
106 * canUseWikiPage() to check whether this method can be called safely.
111 public function getWikiPage() {
112 return $this->getContext()->getWikiPage();
116 * Get the OutputPage object
121 public function getOutput() {
122 return $this->getContext()->getOutput();
126 * Get the User object
131 public function getUser() {
132 return $this->getContext()->getUser();
136 * Get the Language object
141 public function getLanguage() {
142 return $this->getContext()->getLanguage();
146 * Get the Skin object
151 public function getSkin() {
152 return $this->getContext()->getSkin();
156 * Get the Timing object
161 public function getTiming() {
162 return $this->getContext()->getTiming();
166 * Get the Stats object
169 * @return BufferingStatsdDataFactory
171 public function getStats() {
172 return $this->getContext()->getStats();
176 * Get a Message object with context set
177 * Parameters are the same as wfMessage()
183 public function msg( /* $args */ ) {
184 $args = func_get_args();
186 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
190 * Export the resolved user IP, HTTP headers, user ID, and session ID.
191 * The result will be reasonably sized to allow for serialization.
196 public function exportSession() {
197 return $this->getContext()->exportSession();