MediaWiki  1.28.3
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 = get_class( $this );
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 
57  public function setContext( IContextSource $context ) {
58  $this->context = $context;
59  }
60 
67  public function getConfig() {
68  return $this->getContext()->getConfig();
69  }
70 
77  public function getRequest() {
78  return $this->getContext()->getRequest();
79  }
80 
87  public function getTitle() {
88  return $this->getContext()->getTitle();
89  }
90 
99  public function canUseWikiPage() {
100  return $this->getContext()->canUseWikiPage();
101  }
102 
112  public function getWikiPage() {
113  return $this->getContext()->getWikiPage();
114  }
115 
122  public function getOutput() {
123  return $this->getContext()->getOutput();
124  }
125 
132  public function getUser() {
133  return $this->getContext()->getUser();
134  }
135 
142  public function getLanguage() {
143  return $this->getContext()->getLanguage();
144  }
145 
152  public function getSkin() {
153  return $this->getContext()->getSkin();
154  }
155 
162  public function getTiming() {
163  return $this->getContext()->getTiming();
164  }
165 
174  public function getStats() {
175  return $this->getContext()->getStats();
176  }
177 
186  public function msg( /* $args */ ) {
187  $args = func_get_args();
188 
189  return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
190  }
191 
199  public function exportSession() {
200  return $this->getContext()->exportSession();
201  }
202 }
setContext(IContextSource $context)
Set the IContextSource object.
getStats()
Get the Stats object.
Interface for objects which can provide a MediaWiki context on request.
getLanguage()
Get the Language object.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
IContextSource $context
getTitle()
Get the Title object.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
if($line===false) $args
Definition: cdb.php:64
getRequest()
Get the WebRequest object.
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getTiming()
Get the Timing object.
static getMain()
Static methods.
getConfig()
Get the Config object.
getContext()
Get the base IContextSource object.
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
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
getWikiPage()
Get the WikiPage object.
getUser()
Get the User object.
getOutput()
Get the OutputPage object.
getSkin()
Get the Skin object.