MediaWiki  REL1_31
ContextSource.php
Go to the documentation of this file.
1 <?php
22 
29 abstract class ContextSource implements IContextSource {
33  private $context;
34 
40  public function getContext() {
41  if ( $this->context === null ) {
42  $class = static::class;
43  wfDebug( __METHOD__ . " ($class): called and \$context is null. " .
44  "Using RequestContext::getMain() for sanity\n" );
45  $this->context = RequestContext::getMain();
46  }
47 
48  return $this->context;
49  }
50 
55  public function setContext( IContextSource $context ) {
56  $this->context = $context;
57  }
58 
63  public function getConfig() {
64  return $this->getContext()->getConfig();
65  }
66 
71  public function getRequest() {
72  return $this->getContext()->getRequest();
73  }
74 
79  public function getTitle() {
80  return $this->getContext()->getTitle();
81  }
82 
91  public function canUseWikiPage() {
92  return $this->getContext()->canUseWikiPage();
93  }
94 
104  public function getWikiPage() {
105  return $this->getContext()->getWikiPage();
106  }
107 
112  public function getOutput() {
113  return $this->getContext()->getOutput();
114  }
115 
120  public function getUser() {
121  return $this->getContext()->getUser();
122  }
123 
128  public function getLanguage() {
129  return $this->getContext()->getLanguage();
130  }
131 
136  public function getSkin() {
137  return $this->getContext()->getSkin();
138  }
139 
144  public function getTiming() {
145  return $this->getContext()->getTiming();
146  }
147 
154  public function getStats() {
155  return MediaWikiServices::getInstance()->getStatsdDataFactory();
156  }
157 
168  public function msg( $key /* $args */ ) {
169  $args = func_get_args();
170 
171  return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
172  }
173 
181  public function exportSession() {
182  return $this->getContext()->exportSession();
183  }
184 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:91
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:71
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:79
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:37
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:128
ContextSource\getStats
getStats()
Definition: ContextSource.php:154
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:104
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:136
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:994
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:434
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
ContextSource\getTiming
getTiming()
Definition: ContextSource.php:144
$args
if( $line===false) $args
Definition: cdb.php:64
ContextSource\exportSession
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
Definition: ContextSource.php:181
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:56
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:25