MediaWiki  1.33.0
DerivativeContext.php
Go to the documentation of this file.
1 <?php
22 
34  private $request;
35 
39  private $title;
40 
44  private $wikipage;
45 
49  private $output;
50 
54  private $user;
55 
59  private $lang;
60 
64  private $skin;
65 
69  private $config;
70 
74  private $timing;
75 
79  public function __construct( IContextSource $context ) {
80  $this->setContext( $context );
81  }
82 
86  public function setConfig( Config $config ) {
87  $this->config = $config;
88  }
89 
93  public function getConfig() {
94  return $this->config ?: $this->getContext()->getConfig();
95  }
96 
102  public function getStats() {
103  return MediaWikiServices::getInstance()->getStatsdDataFactory();
104  }
105 
109  public function getTiming() {
110  return $this->timing ?: $this->getContext()->getTiming();
111  }
112 
116  public function setRequest( WebRequest $request ) {
117  $this->request = $request;
118  }
119 
123  public function getRequest() {
124  return $this->request ?: $this->getContext()->getRequest();
125  }
126 
130  public function setTitle( Title $title ) {
131  $this->title = $title;
132  }
133 
137  public function getTitle() {
138  return $this->title ?: $this->getContext()->getTitle();
139  }
140 
149  public function canUseWikiPage() {
150  if ( $this->wikipage !== null ) {
151  return true;
152  }
153 
154  if ( $this->title !== null ) {
155  return $this->title->canExist();
156  }
157 
158  return $this->getContext()->canUseWikiPage();
159  }
160 
165  public function setWikiPage( WikiPage $wikiPage ) {
166  $this->wikipage = $wikiPage;
167  }
168 
178  public function getWikiPage() {
179  return $this->wikipage ?: $this->getContext()->getWikiPage();
180  }
181 
185  public function setOutput( OutputPage $output ) {
186  $this->output = $output;
187  }
188 
192  public function getOutput() {
193  return $this->output ?: $this->getContext()->getOutput();
194  }
195 
199  public function setUser( User $user ) {
200  $this->user = $user;
201  }
202 
206  public function getUser() {
207  return $this->user ?: $this->getContext()->getUser();
208  }
209 
215  public function setLanguage( $language ) {
216  if ( $language instanceof Language ) {
217  $this->lang = $language;
218  } elseif ( is_string( $language ) ) {
219  $language = RequestContext::sanitizeLangCode( $language );
220  $obj = Language::factory( $language );
221  $this->lang = $obj;
222  } else {
223  throw new MWException( __METHOD__ . " was passed an invalid type of data." );
224  }
225  }
226 
231  public function getLanguage() {
232  return $this->lang ?: $this->getContext()->getLanguage();
233  }
234 
238  public function setSkin( Skin $skin ) {
239  $this->skin = clone $skin;
240  $this->skin->setContext( $this );
241  }
242 
246  public function getSkin() {
247  return $this->skin ?: $this->getContext()->getSkin();
248  }
249 
262  public function msg( $key ) {
263  $args = func_get_args();
264 
265  // phpcs:ignore MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage
266  return wfMessage( ...$args )->setContext( $this );
267  }
268 }
DerivativeContext\msg
msg( $key)
Get a message using the current context.
Definition: DerivativeContext.php:262
DerivativeContext\__construct
__construct(IContextSource $context)
Definition: DerivativeContext.php:79
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
RequestContext\sanitizeLangCode
static sanitizeLangCode( $code)
Accepts a language code and ensures it's sane.
Definition: RequestContext.php:281
DerivativeContext\$config
Config $config
Definition: DerivativeContext.php:69
DerivativeContext\$wikipage
WikiPage $wikipage
Definition: DerivativeContext.php:44
DerivativeContext\setWikiPage
setWikiPage(WikiPage $wikiPage)
Definition: DerivativeContext.php:165
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:45
DerivativeContext\setConfig
setConfig(Config $config)
Definition: DerivativeContext.php:86
DerivativeContext\setSkin
setSkin(Skin $skin)
Definition: DerivativeContext.php:238
request
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment or false if none Defaults to false if not set multiOccurrence Can this option be passed multiple times Defaults to false if not set this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2162
DerivativeContext\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: DerivativeContext.php:178
DerivativeContext\getStats
getStats()
Definition: DerivativeContext.php:102
DerivativeContext\getUser
getUser()
Definition: DerivativeContext.php:206
DerivativeContext\getOutput
getOutput()
Definition: DerivativeContext.php:192
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
DerivativeContext\getTitle
getTitle()
Definition: DerivativeContext.php:137
DerivativeContext\$output
OutputPage $output
Definition: DerivativeContext.php:49
DerivativeContext\setRequest
setRequest(WebRequest $request)
Definition: DerivativeContext.php:116
Config
Interface for configuration instances.
Definition: Config.php:28
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
MWException
MediaWiki exception.
Definition: MWException.php:26
DerivativeContext\$title
Title $title
Definition: DerivativeContext.php:39
DerivativeContext\$skin
Skin $skin
Definition: DerivativeContext.php:64
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
DerivativeContext\getTiming
getTiming()
Definition: DerivativeContext.php:109
Timing
An interface to help developers measure the performance of their applications.
Definition: Timing.php:45
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
DerivativeContext\setUser
setUser(User $user)
Definition: DerivativeContext.php:199
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
DerivativeContext\getRequest
getRequest()
Definition: DerivativeContext.php:123
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
MutableContext
Definition: MutableContext.php:25
DerivativeContext\setTitle
setTitle(Title $title)
Definition: DerivativeContext.php:130
DerivativeContext\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: DerivativeContext.php:149
title
title
Definition: parserTests.txt:245
DerivativeContext\getConfig
getConfig()
Definition: DerivativeContext.php:93
DerivativeContext\getSkin
getSkin()
Definition: DerivativeContext.php:246
DerivativeContext\$timing
Timing $timing
Definition: DerivativeContext.php:74
DerivativeContext\$user
User $user
Definition: DerivativeContext.php:54
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:41
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:40
DerivativeContext\setLanguage
setLanguage( $language)
Definition: DerivativeContext.php:215
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
captcha-old.output
output
Definition: captcha-old.py:240
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
Skin
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:38
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
DerivativeContext\setOutput
setOutput(OutputPage $output)
Definition: DerivativeContext.php:185
Language
Internationalisation code.
Definition: Language.php:36
DerivativeContext\getLanguage
getLanguage()
Definition: DerivativeContext.php:231
DerivativeContext\$request
WebRequest $request
Definition: DerivativeContext.php:34
DerivativeContext\$lang
Language $lang
Definition: DerivativeContext.php:59