Fixing dump tests for non-wikitext in NS_MAIN.
[lhc/web/wiklou.git] / includes / context / ContextSource.php
1 <?php
2 /**
3 * Request-dependant objects containers.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @since 1.18
21 *
22 * @author Happy-melon
23 * @file
24 */
25
26 /**
27 * The simplest way of implementing IContextSource is to hold a RequestContext as a
28 * member variable and provide accessors to it.
29 */
30 abstract class ContextSource implements IContextSource {
31
32 /**
33 * @var IContextSource
34 */
35 private $context;
36
37 /**
38 * Get the RequestContext object
39 * @since 1.18
40 * @return RequestContext
41 */
42 public function getContext() {
43 if ( $this->context === null ) {
44 $class = get_class( $this );
45 wfDebug( __METHOD__ . " ($class): called and \$context is null. Using RequestContext::getMain() for sanity\n" );
46 $this->context = RequestContext::getMain();
47 }
48 return $this->context;
49 }
50
51 /**
52 * Set the IContextSource object
53 *
54 * @since 1.18
55 * @param $context IContextSource
56 */
57 public function setContext( IContextSource $context ) {
58 $this->context = $context;
59 }
60
61 /**
62 * Get the WebRequest object
63 *
64 * @since 1.18
65 * @return WebRequest
66 */
67 public function getRequest() {
68 return $this->getContext()->getRequest();
69 }
70
71 /**
72 * Get the Title object
73 *
74 * @since 1.18
75 * @return Title
76 */
77 public function getTitle() {
78 return $this->getContext()->getTitle();
79 }
80
81 /**
82 * Check whether a WikiPage object can be get with getWikiPage().
83 * Callers should expect that an exception is thrown from getWikiPage()
84 * if this method returns false.
85 *
86 * @since 1.19
87 * @return bool
88 */
89 public function canUseWikiPage() {
90 return $this->getContext()->canUseWikiPage();
91 }
92
93 /**
94 * Get the WikiPage object.
95 * May throw an exception if there's no Title object set or the Title object
96 * belongs to a special namespace that doesn't have WikiPage, so use first
97 * canUseWikiPage() to check whether this method can be called safely.
98 *
99 * @since 1.19
100 * @return WikiPage
101 */
102 public function getWikiPage() {
103 return $this->getContext()->getWikiPage();
104 }
105
106 /**
107 * Get the OutputPage object
108 *
109 * @since 1.18
110 * @return OutputPage object
111 */
112 public function getOutput() {
113 return $this->getContext()->getOutput();
114 }
115
116 /**
117 * Get the User object
118 *
119 * @since 1.18
120 * @return User
121 */
122 public function getUser() {
123 return $this->getContext()->getUser();
124 }
125
126 /**
127 * Get the Language object
128 *
129 * @deprecated 1.19 Use getLanguage instead
130 * @return Language
131 */
132 public function getLang() {
133 wfDeprecated( __METHOD__, '1.19' );
134 return $this->getLanguage();
135 }
136
137 /**
138 * Get the Language object
139 *
140 * @since 1.19
141 * @return Language
142 */
143 public function getLanguage() {
144 return $this->getContext()->getLanguage();
145 }
146
147 /**
148 * Get the Skin object
149 *
150 * @since 1.18
151 * @return Skin
152 */
153 public function getSkin() {
154 return $this->getContext()->getSkin();
155 }
156
157 /**
158 * Get a Message object with context set
159 * Parameters are the same as wfMessage()
160 *
161 * @since 1.18
162 * @return Message object
163 */
164 public function msg( /* $args */ ) {
165 $args = func_get_args();
166 return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
167 }
168
169 }
170