MediaWiki  master
ContextSource.php
Go to the documentation of this file.
1 <?php
24 use Wikimedia\NonSerializable\NonSerializableTrait;
25 
33 abstract class ContextSource implements IContextSource {
34  use NonSerializableTrait;
35 
39  private $context;
40 
47  public function getContext() {
48  if ( $this->context === null ) {
49  $class = static::class;
50  wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
51  "Using RequestContext::getMain() for sanity" );
52  $this->context = RequestContext::getMain();
53  }
54 
55  return $this->context;
56  }
57 
63  public function setContext( IContextSource $context ) {
64  $this->context = $context;
65  }
66 
72  public function getConfig() {
73  return $this->getContext()->getConfig();
74  }
75 
81  public function getRequest() {
82  return $this->getContext()->getRequest();
83  }
84 
90  public function getTitle() {
91  return $this->getContext()->getTitle();
92  }
93 
103  public function canUseWikiPage() {
104  return $this->getContext()->canUseWikiPage();
105  }
106 
117  public function getWikiPage() {
118  return $this->getContext()->getWikiPage();
119  }
120 
126  public function getOutput() {
127  return $this->getContext()->getOutput();
128  }
129 
136  public function getUser() {
137  return $this->getContext()->getUser();
138  }
139 
144  public function getAuthority(): Authority {
145  return $this->getContext()->getAuthority();
146  }
147 
153  public function getLanguage() {
154  return $this->getContext()->getLanguage();
155  }
156 
162  public function getSkin() {
163  return $this->getContext()->getSkin();
164  }
165 
171  public function getTiming() {
172  return $this->getContext()->getTiming();
173  }
174 
182  public function getStats() {
183  return MediaWikiServices::getInstance()->getStatsdDataFactory();
184  }
185 
197  public function msg( $key, ...$params ) {
198  return $this->getContext()->msg( $key, ...$params );
199  }
200 
209  public function exportSession() {
210  return $this->getContext()->exportSession();
211  }
212 
219  public function getCsrfTokenSet(): CsrfTokenSet {
220  return $this->getContext()->getCsrfTokenSet();
221  }
222 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:39
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:47
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:103
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:81
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:90
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:153
ContextSource\getStats
getStats()
Definition: ContextSource.php:182
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:126
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:33
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:117
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:162
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:63
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:197
MediaWiki\Session\CsrfTokenSet
Definition: CsrfTokenSet.php:31
ContextSource\getAuthority
getAuthority()
Definition: ContextSource.php:144
ContextSource\getCsrfTokenSet
getCsrfTokenSet()
Get a repository to obtain and match CSRF tokens.
Definition: ContextSource.php:219
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
ContextSource\getTiming
getTiming()
Definition: ContextSource.php:171
ContextSource\exportSession
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
Definition: ContextSource.php:209