MediaWiki REL1_35
DerivativeContext.php
Go to the documentation of this file.
1<?php
22
35 private $request;
36
40 private $title;
41
45 private $wikipage;
46
50 private $output;
51
55 private $user;
56
60 private $lang;
61
65 private $skin;
66
70 private $config;
71
75 private $timing;
76
81 public function __construct( IContextSource $context ) {
82 $this->setContext( $context );
83 }
84
88 public function setConfig( Config $config ) {
89 $this->config = $config;
90 }
91
95 public function getConfig() {
96 return $this->config ?: $this->getContext()->getConfig();
97 }
98
104 public function getStats() {
105 return MediaWikiServices::getInstance()->getStatsdDataFactory();
106 }
107
111 public function getTiming() {
112 return $this->timing ?: $this->getContext()->getTiming();
113 }
114
118 public function setRequest( WebRequest $request ) {
119 $this->request = $request;
120 }
121
125 public function getRequest() {
126 return $this->request ?: $this->getContext()->getRequest();
127 }
128
132 public function setTitle( Title $title ) {
133 $this->title = $title;
134 }
135
139 public function getTitle() {
140 return $this->title ?: $this->getContext()->getTitle();
141 }
142
151 public function canUseWikiPage() {
152 if ( $this->wikipage !== null ) {
153 return true;
154 }
155
156 if ( $this->title !== null ) {
157 return $this->title->canExist();
158 }
159
160 return $this->getContext()->canUseWikiPage();
161 }
162
167 public function setWikiPage( WikiPage $wikiPage ) {
168 $this->wikipage = $wikiPage;
169 }
170
180 public function getWikiPage() {
181 return $this->wikipage ?: $this->getContext()->getWikiPage();
182 }
183
187 public function setOutput( OutputPage $output ) {
188 $this->output = $output;
189 }
190
194 public function getOutput() {
195 return $this->output ?: $this->getContext()->getOutput();
196 }
197
201 public function setUser( User $user ) {
202 $this->user = $user;
203 }
204
208 public function getUser() {
209 return $this->user ?: $this->getContext()->getUser();
210 }
211
217 public function setLanguage( $language ) {
218 if ( $language instanceof Language ) {
219 $this->lang = $language;
220 } elseif ( is_string( $language ) ) {
221 $language = RequestContext::sanitizeLangCode( $language );
222 $obj = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $language );
223 $this->lang = $obj;
224 } else {
225 throw new MWException( __METHOD__ . " was passed an invalid type of data." );
226 }
227 }
228
233 public function getLanguage() {
234 return $this->lang ?: $this->getContext()->getLanguage();
235 }
236
240 public function setSkin( Skin $skin ) {
241 $this->skin = clone $skin;
242 $this->skin->setContext( $this );
243 }
244
248 public function getSkin() {
249 return $this->skin ?: $this->getContext()->getSkin();
250 }
251
264 public function msg( $key, ...$params ) {
265 // phpcs:ignore MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage
266 return wfMessage( $key, ...$params )->setContext( $this );
267 }
268}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
IContextSource $context
getContext()
Get the base IContextSource object.
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)
Stable to call.
setConfig(Config $config)
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
setOutput(OutputPage $output)
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:41
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:41
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:60
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:51
Interface for configuration instances.
Definition Config.php:30
Interface for objects which can provide a MediaWiki context on request.