MediaWiki  master
ContextSource.php
Go to the documentation of this file.
1 <?php
23 use Wikimedia\NonSerializable\NonSerializableTrait;
24 
32 abstract class ContextSource implements IContextSource {
33  use NonSerializableTrait;
34 
38  private $context;
39 
46  public function getContext() {
47  if ( $this->context === null ) {
48  $class = static::class;
49  wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
50  "Using RequestContext::getMain() for sanity" );
51  $this->context = RequestContext::getMain();
52  }
53 
54  return $this->context;
55  }
56 
62  public function setContext( IContextSource $context ) {
63  $this->context = $context;
64  }
65 
71  public function getConfig() {
72  return $this->getContext()->getConfig();
73  }
74 
80  public function getRequest() {
81  return $this->getContext()->getRequest();
82  }
83 
89  public function getTitle() {
90  return $this->getContext()->getTitle();
91  }
92 
102  public function canUseWikiPage() {
103  return $this->getContext()->canUseWikiPage();
104  }
105 
116  public function getWikiPage() {
117  return $this->getContext()->getWikiPage();
118  }
119 
125  public function getOutput() {
126  return $this->getContext()->getOutput();
127  }
128 
135  public function getUser() {
136  return $this->getContext()->getUser();
137  }
138 
142  public function getAuthority(): Authority {
143  return $this->getContext()->getAuthority();
144  }
145 
151  public function getLanguage() {
152  return $this->getContext()->getLanguage();
153  }
154 
160  public function getSkin() {
161  return $this->getContext()->getSkin();
162  }
163 
169  public function getTiming() {
170  return $this->getContext()->getTiming();
171  }
172 
180  public function getStats() {
181  return MediaWikiServices::getInstance()->getStatsdDataFactory();
182  }
183 
195  public function msg( $key, ...$params ) {
196  return $this->getContext()->msg( $key, ...$params );
197  }
198 
207  public function exportSession() {
208  return $this->getContext()->exportSession();
209  }
210 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:38
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:71
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:46
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:172
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:102
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:80
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:135
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:89
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:151
ContextSource\getStats
getStats()
Definition: ContextSource.php:180
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:125
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:32
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:116
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:160
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:915
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:62
MediaWiki\Permissions\Authority
@unstable
Definition: Authority.php:30
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:195
ContextSource\getAuthority
getAuthority()
Definition: ContextSource.php:142
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:476
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:57
ContextSource\getTiming
getTiming()
Definition: ContextSource.php:169
ContextSource\exportSession
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
Definition: ContextSource.php:207