MediaWiki REL1_29
ContextSource.php
Go to the documentation of this file.
1<?php
21use Liuggio\StatsdClient\Factory\StatsdDataFactory;
23
30abstract 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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:63
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
getSkin()
Get the Skin object.
getStats()
Get the Stats object.
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
getConfig()
Get the Config object.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getTitle()
Get the Title object.
getTiming()
Get the Timing object.
getOutput()
Get the OutputPage object.
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
IContextSource $context
getWikiPage()
Get the WikiPage object.
getLanguage()
Get the Language object.
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
Set the IContextSource object.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getMain()
Static methods.
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
Interface for objects which can provide a MediaWiki context on request.