MediaWiki  master
ContextSource.php
Go to the documentation of this file.
1 <?php
22 use Wikimedia\NonSerializable\NonSerializableTrait;
23 
31 abstract class ContextSource implements IContextSource {
32  use NonSerializableTrait;
33 
37  private $context;
38 
45  public function getContext() {
46  if ( $this->context === null ) {
47  $class = static::class;
48  wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
49  "Using RequestContext::getMain() for sanity" );
50  $this->context = RequestContext::getMain();
51  }
52 
53  return $this->context;
54  }
55 
61  public function setContext( IContextSource $context ) {
62  $this->context = $context;
63  }
64 
70  public function getConfig() {
71  return $this->getContext()->getConfig();
72  }
73 
79  public function getRequest() {
80  return $this->getContext()->getRequest();
81  }
82 
88  public function getTitle() {
89  return $this->getContext()->getTitle();
90  }
91 
101  public function canUseWikiPage() {
102  return $this->getContext()->canUseWikiPage();
103  }
104 
115  public function getWikiPage() {
116  return $this->getContext()->getWikiPage();
117  }
118 
124  public function getOutput() {
125  return $this->getContext()->getOutput();
126  }
127 
134  public function getUser() {
135  return $this->getContext()->getUser();
136  }
137 
143  public function getLanguage() {
144  return $this->getContext()->getLanguage();
145  }
146 
152  public function getSkin() {
153  return $this->getContext()->getSkin();
154  }
155 
161  public function getTiming() {
162  return $this->getContext()->getTiming();
163  }
164 
172  public function getStats() {
173  return MediaWikiServices::getInstance()->getStatsdDataFactory();
174  }
175 
187  public function msg( $key, ...$params ) {
188  return $this->getContext()->msg( $key, ...$params );
189  }
190 
199  public function exportSession() {
200  return $this->getContext()->exportSession();
201  }
202 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:37
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:70
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:45
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:160
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:101
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:79
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:134
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:88
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:143
ContextSource\getStats
getStats()
Definition: ContextSource.php:172
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:124
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:31
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:115
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:152
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:910
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:61
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:454
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
ContextSource\getTiming
getTiming()
Definition: ContextSource.php:161
ContextSource\exportSession
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
Definition: ContextSource.php:199