MediaWiki REL1_34
DerivativeContext.php
Go to the documentation of this file.
1<?php
22
34 private $request;
35
39 private $title;
40
44 private $wikipage;
45
49 private $output;
50
54 private $user;
55
59 private $lang;
60
64 private $skin;
65
69 private $config;
70
74 private $timing;
75
79 public function __construct( IContextSource $context ) {
80 $this->setContext( $context );
81 }
82
86 public function setConfig( Config $config ) {
87 $this->config = $config;
88 }
89
93 public function getConfig() {
94 return $this->config ?: $this->getContext()->getConfig();
95 }
96
102 public function getStats() {
103 return MediaWikiServices::getInstance()->getStatsdDataFactory();
104 }
105
109 public function getTiming() {
110 return $this->timing ?: $this->getContext()->getTiming();
111 }
112
116 public function setRequest( WebRequest $request ) {
117 $this->request = $request;
118 }
119
123 public function getRequest() {
124 return $this->request ?: $this->getContext()->getRequest();
125 }
126
130 public function setTitle( Title $title ) {
131 $this->title = $title;
132 }
133
137 public function getTitle() {
138 return $this->title ?: $this->getContext()->getTitle();
139 }
140
149 public function canUseWikiPage() {
150 if ( $this->wikipage !== null ) {
151 return true;
152 }
153
154 if ( $this->title !== null ) {
155 return $this->title->canExist();
156 }
157
158 return $this->getContext()->canUseWikiPage();
159 }
160
165 public function setWikiPage( WikiPage $wikiPage ) {
166 $this->wikipage = $wikiPage;
167 }
168
178 public function getWikiPage() {
179 return $this->wikipage ?: $this->getContext()->getWikiPage();
180 }
181
185 public function setOutput( OutputPage $output ) {
186 $this->output = $output;
187 }
188
192 public function getOutput() {
193 return $this->output ?: $this->getContext()->getOutput();
194 }
195
199 public function setUser( User $user ) {
200 $this->user = $user;
201 }
202
206 public function getUser() {
207 return $this->user ?: $this->getContext()->getUser();
208 }
209
215 public function setLanguage( $language ) {
216 if ( $language instanceof Language ) {
217 $this->lang = $language;
218 } elseif ( is_string( $language ) ) {
219 $language = RequestContext::sanitizeLangCode( $language );
220 $obj = Language::factory( $language );
221 $this->lang = $obj;
222 } else {
223 throw new MWException( __METHOD__ . " was passed an invalid type of data." );
224 }
225 }
226
231 public function getLanguage() {
232 return $this->lang ?: $this->getContext()->getLanguage();
233 }
234
238 public function setSkin( Skin $skin ) {
239 $this->skin = clone $skin;
240 $this->skin->setContext( $this );
241 }
242
246 public function getSkin() {
247 return $this->skin ?: $this->getContext()->getSkin();
248 }
249
262 public function msg( $key, ...$params ) {
263 // phpcs:ignore MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage
264 return wfMessage( $key, ...$params )->setContext( $this );
265 }
266}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getContext()
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
An IContextSource implementation which will inherit context from another source but allow individual ...
setRequest(WebRequest $request)
setWikiPage(WikiPage $wikiPage)
getWikiPage()
Get the WikiPage object.
msg( $key,... $params)
Get a message using the current context.
__construct(IContextSource $context)
setConfig(Config $config)
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
setOutput(OutputPage $output)
Internationalisation code.
Definition Language.php:37
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This is one of the Core classes and should be read at least once by any new developers.
The main skin class which provides methods and properties for all other skins.
Definition Skin.php:38
An interface to help developers measure the performance of their applications.
Definition Timing.php:45
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Class representing a MediaWiki article and history.
Definition WikiPage.php:47
Interface for configuration instances.
Definition Config.php:28
Interface for objects which can provide a MediaWiki context on request.
$context
Definition load.php:45