mediawiki.Uri: Support names of Object prototypes as keys in query
[mediawiki.git] / includes / context / ContextSource.php
blobcaf5afaa864026f14c5969898099437db93d9e7c
1 <?php
2 /**
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
18 * @author Happy-melon
19 * @file
22 /**
23 * The simplest way of implementing IContextSource is to hold a RequestContext as a
24 * member variable and provide accessors to it.
26 * @since 1.18
28 abstract class ContextSource implements IContextSource {
29 /**
30 * @var IContextSource
32 private $context;
34 /**
35 * Get the base IContextSource object
36 * @since 1.18
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;
50 /**
51 * Set the IContextSource object
53 * @since 1.18
54 * @param IContextSource $context
56 public function setContext( IContextSource $context ) {
57 $this->context = $context;
60 /**
61 * Get the Config object
63 * @since 1.23
64 * @return Config
66 public function getConfig() {
67 return $this->getContext()->getConfig();
70 /**
71 * Get the WebRequest object
73 * @since 1.18
74 * @return WebRequest
76 public function getRequest() {
77 return $this->getContext()->getRequest();
80 /**
81 * Get the Title object
83 * @since 1.18
84 * @return Title|null
86 public function getTitle() {
87 return $this->getContext()->getTitle();
90 /**
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.
95 * @since 1.19
96 * @return bool
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.
108 * @since 1.19
109 * @return WikiPage
111 public function getWikiPage() {
112 return $this->getContext()->getWikiPage();
116 * Get the OutputPage object
118 * @since 1.18
119 * @return OutputPage
121 public function getOutput() {
122 return $this->getContext()->getOutput();
126 * Get the User object
128 * @since 1.18
129 * @return User
131 public function getUser() {
132 return $this->getContext()->getUser();
136 * Get the Language object
138 * @since 1.19
139 * @return Language
141 public function getLanguage() {
142 return $this->getContext()->getLanguage();
146 * Get the Skin object
148 * @since 1.18
149 * @return Skin
151 public function getSkin() {
152 return $this->getContext()->getSkin();
156 * Get the Stats object
158 * @since 1.25
159 * @return BufferingStatsdDataFactory
161 public function getStats() {
162 return $this->getContext()->getStats();
167 * Get a Message object with context set
168 * Parameters are the same as wfMessage()
170 * @since 1.18
171 * @param mixed ...
172 * @return Message
174 public function msg( /* $args */ ) {
175 $args = func_get_args();
177 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
181 * Export the resolved user IP, HTTP headers, user ID, and session ID.
182 * The result will be reasonably sized to allow for serialization.
184 * @return array
185 * @since 1.21
187 public function exportSession() {
188 return $this->getContext()->exportSession();