MediaWiki  1.29.2
ContextSource.php
Go to the documentation of this file.
1 <?php
21 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
23 
30 abstract class ContextSource implements IContextSource {
34  private $context;
35 
41  public function getContext() {
42  if ( $this->context === null ) {
43  $class = static::class;
44  wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
45  "Using RequestContext::getMain() for sanity\n" );
46  $this->context = RequestContext::getMain();
47  }
48 
49  return $this->context;
50  }
51 
58  public function setContext( IContextSource $context ) {
59  $this->context = $context;
60  }
61 
68  public function getConfig() {
69  return $this->getContext()->getConfig();
70  }
71 
78  public function getRequest() {
79  return $this->getContext()->getRequest();
80  }
81 
88  public function getTitle() {
89  return $this->getContext()->getTitle();
90  }
91 
100  public function canUseWikiPage() {
101  return $this->getContext()->canUseWikiPage();
102  }
103 
113  public function getWikiPage() {
114  return $this->getContext()->getWikiPage();
115  }
116 
123  public function getOutput() {
124  return $this->getContext()->getOutput();
125  }
126 
133  public function getUser() {
134  return $this->getContext()->getUser();
135  }
136 
143  public function getLanguage() {
144  return $this->getContext()->getLanguage();
145  }
146 
153  public function getSkin() {
154  return $this->getContext()->getSkin();
155  }
156 
163  public function getTiming() {
164  return $this->getContext()->getTiming();
165  }
166 
175  public function getStats() {
176  return MediaWikiServices::getInstance()->getStatsdDataFactory();
177  }
178 
187  public function msg( /* $args */ ) {
188  $args = func_get_args();
189 
190  return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
191  }
192 
200  public function exportSession() {
201  return $this->getContext()->exportSession();
202  }
203 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:100
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
ContextSource\getTitle
getTitle()
Get the Title object.
Definition: ContextSource.php:88
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
ContextSource\getStats
getStats()
Get the Stats object.
Definition: ContextSource.php:175
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:123
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:113
ContextSource\getSkin
getSkin()
Get the Skin object.
Definition: ContextSource.php:153
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:999
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:468
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
ContextSource\getTiming
getTiming()
Get the Timing object.
Definition: ContextSource.php:163
$args
if( $line===false) $args
Definition: cdb.php:63
ContextSource\exportSession
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
Definition: ContextSource.php:200
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23