MediaWiki  master
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 }
DerivativeContext\__construct
__construct(IContextSource $context)
Stable to call.
Definition: DerivativeContext.php:81
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:42
RequestContext\sanitizeLangCode
static sanitizeLangCode( $code)
Accepts a language code and ensures it's sane.
Definition: RequestContext.php:294
DerivativeContext\$config
Config $config
Definition: DerivativeContext.php:70
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
DerivativeContext\$wikipage
WikiPage $wikipage
Definition: DerivativeContext.php:45
DerivativeContext\setWikiPage
setWikiPage(WikiPage $wikiPage)
Definition: DerivativeContext.php:167
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:52
DerivativeContext\setConfig
setConfig(Config $config)
Definition: DerivativeContext.php:88
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
DerivativeContext\setSkin
setSkin(Skin $skin)
Definition: DerivativeContext.php:240
DerivativeContext\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: DerivativeContext.php:180
DerivativeContext\getStats
getStats()
Definition: DerivativeContext.php:104
DerivativeContext\getUser
getUser()
Definition: DerivativeContext.php:208
DerivativeContext\getOutput
getOutput()
Definition: DerivativeContext.php:194
DerivativeContext\getTitle
getTitle()
Definition: DerivativeContext.php:139
DerivativeContext\$output
OutputPage $output
Definition: DerivativeContext.php:50
DerivativeContext\setRequest
setRequest(WebRequest $request)
Definition: DerivativeContext.php:118
Config
Interface for configuration instances.
Definition: Config.php:30
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
MWException
MediaWiki exception.
Definition: MWException.php:29
DerivativeContext\$title
Title $title
Definition: DerivativeContext.php:40
DerivativeContext\$skin
Skin $skin
Definition: DerivativeContext.php:65
DerivativeContext\getTiming
getTiming()
Definition: DerivativeContext.php:111
Timing
An interface to help developers measure the performance of their applications.
Definition: Timing.php:45
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
DerivativeContext\setUser
setUser(User $user)
Definition: DerivativeContext.php:201
DerivativeContext\msg
msg( $key,... $params)
Get a message using the current context.
Definition: DerivativeContext.php:264
DerivativeContext\getRequest
getRequest()
Definition: DerivativeContext.php:125
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:58
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:47
MutableContext
Definition: MutableContext.php:25
DerivativeContext\setTitle
setTitle(Title $title)
Definition: DerivativeContext.php:132
DerivativeContext\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: DerivativeContext.php:151
DerivativeContext\getConfig
getConfig()
Definition: DerivativeContext.php:95
DerivativeContext\getSkin
getSkin()
Definition: DerivativeContext.php:248
DerivativeContext\$timing
Timing $timing
Definition: DerivativeContext.php:75
DerivativeContext\$user
User $user
Definition: DerivativeContext.php:55
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:42
Title
Represents a title within MediaWiki.
Definition: Title.php:42
DerivativeContext\setLanguage
setLanguage( $language)
Definition: DerivativeContext.php:217
Skin
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:41
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
DerivativeContext\setOutput
setOutput(OutputPage $output)
Definition: DerivativeContext.php:187
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
DerivativeContext\getLanguage
getLanguage()
Definition: DerivativeContext.php:233
DerivativeContext\$request
WebRequest $request
Definition: DerivativeContext.php:35
DerivativeContext\$lang
Language $lang
Definition: DerivativeContext.php:60