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
21 use Liuggio\StatsdClient\Factory\StatsdDataFactory
;
24 * The simplest way of implementing IContextSource is to hold a RequestContext as a
25 * member variable and provide accessors to it.
29 abstract class ContextSource
implements IContextSource
{
36 * Get the base IContextSource object
38 * @return IContextSource
40 public function getContext() {
41 if ( $this->context
=== null ) {
42 $class = get_class( $this );
43 wfDebug( __METHOD__
. " ($class): called and \$context is null. " .
44 "Using RequestContext::getMain() for sanity\n" );
45 $this->context
= RequestContext
::getMain();
48 return $this->context
;
52 * Set the IContextSource object
55 * @param IContextSource $context
57 public function setContext( IContextSource
$context ) {
58 $this->context
= $context;
62 * Get the Config object
67 public function getConfig() {
68 return $this->getContext()->getConfig();
72 * Get the WebRequest object
77 public function getRequest() {
78 return $this->getContext()->getRequest();
82 * Get the Title object
87 public function getTitle() {
88 return $this->getContext()->getTitle();
92 * Check whether a WikiPage object can be get with getWikiPage().
93 * Callers should expect that an exception is thrown from getWikiPage()
94 * if this method returns false.
99 public function canUseWikiPage() {
100 return $this->getContext()->canUseWikiPage();
104 * Get the WikiPage object.
105 * May throw an exception if there's no Title object set or the Title object
106 * belongs to a special namespace that doesn't have WikiPage, so use first
107 * canUseWikiPage() to check whether this method can be called safely.
112 public function getWikiPage() {
113 return $this->getContext()->getWikiPage();
117 * Get the OutputPage object
122 public function getOutput() {
123 return $this->getContext()->getOutput();
127 * Get the User object
132 public function getUser() {
133 return $this->getContext()->getUser();
137 * Get the Language object
142 public function getLanguage() {
143 return $this->getContext()->getLanguage();
147 * Get the Skin object
152 public function getSkin() {
153 return $this->getContext()->getSkin();
157 * Get the Timing object
162 public function getTiming() {
163 return $this->getContext()->getTiming();
167 * Get the Stats object
169 * @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
172 * @return StatsdDataFactory
174 public function getStats() {
175 return $this->getContext()->getStats();
179 * Get a Message object with context set
180 * Parameters are the same as wfMessage()
186 public function msg( /* $args */ ) {
187 $args = func_get_args();
189 return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
193 * Export the resolved user IP, HTTP headers, user ID, and session ID.
194 * The result will be reasonably sized to allow for serialization.
199 public function exportSession() {
200 return $this->getContext()->exportSession();