MediaWiki  REL1_31
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  if ( !is_null( $this->config ) ) {
95  return $this->config;
96  } else {
97  return $this->getContext()->getConfig();
98  }
99  }
100 
106  public function getStats() {
107  return MediaWikiServices::getInstance()->getStatsdDataFactory();
108  }
109 
113  public function getTiming() {
114  if ( !is_null( $this->timing ) ) {
115  return $this->timing;
116  } else {
117  return $this->getContext()->getTiming();
118  }
119  }
120 
124  public function setRequest( WebRequest $request ) {
125  $this->request = $request;
126  }
127 
131  public function getRequest() {
132  if ( !is_null( $this->request ) ) {
133  return $this->request;
134  } else {
135  return $this->getContext()->getRequest();
136  }
137  }
138 
142  public function setTitle( Title $title ) {
143  $this->title = $title;
144  }
145 
149  public function getTitle() {
150  if ( !is_null( $this->title ) ) {
151  return $this->title;
152  } else {
153  return $this->getContext()->getTitle();
154  }
155  }
156 
165  public function canUseWikiPage() {
166  if ( $this->wikipage !== null ) {
167  return true;
168  } elseif ( $this->title !== null ) {
169  return $this->title->canExist();
170  } else {
171  return $this->getContext()->canUseWikiPage();
172  }
173  }
174 
179  public function setWikiPage( WikiPage $wikiPage ) {
180  $this->wikipage = $wikiPage;
181  }
182 
192  public function getWikiPage() {
193  if ( !is_null( $this->wikipage ) ) {
194  return $this->wikipage;
195  } else {
196  return $this->getContext()->getWikiPage();
197  }
198  }
199 
203  public function setOutput( OutputPage $output ) {
204  $this->output = $output;
205  }
206 
210  public function getOutput() {
211  if ( !is_null( $this->output ) ) {
212  return $this->output;
213  } else {
214  return $this->getContext()->getOutput();
215  }
216  }
217 
221  public function setUser( User $user ) {
222  $this->user = $user;
223  }
224 
228  public function getUser() {
229  if ( !is_null( $this->user ) ) {
230  return $this->user;
231  } else {
232  return $this->getContext()->getUser();
233  }
234  }
235 
241  public function setLanguage( $language ) {
242  if ( $language instanceof Language ) {
243  $this->lang = $language;
244  } elseif ( is_string( $language ) ) {
245  $language = RequestContext::sanitizeLangCode( $language );
246  $obj = Language::factory( $language );
247  $this->lang = $obj;
248  } else {
249  throw new MWException( __METHOD__ . " was passed an invalid type of data." );
250  }
251  }
252 
257  public function getLanguage() {
258  if ( !is_null( $this->lang ) ) {
259  return $this->lang;
260  } else {
261  return $this->getContext()->getLanguage();
262  }
263  }
264 
268  public function setSkin( Skin $skin ) {
269  $this->skin = clone $skin;
270  $this->skin->setContext( $this );
271  }
272 
276  public function getSkin() {
277  if ( !is_null( $this->skin ) ) {
278  return $this->skin;
279  } else {
280  return $this->getContext()->getSkin();
281  }
282  }
283 
296  public function msg( $key ) {
297  $args = func_get_args();
298 
299  return call_user_func_array( 'wfMessage', $args )->setContext( $this );
300  }
301 }
DerivativeContext\msg
msg( $key)
Get a message using the current context.
Definition: DerivativeContext.php:296
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:279
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
DerivativeContext\$config
Config $config
Definition: DerivativeContext.php:69
DerivativeContext\$wikipage
WikiPage $wikipage
Definition: DerivativeContext.php:44
DerivativeContext\setWikiPage
setWikiPage(WikiPage $wikiPage)
Definition: DerivativeContext.php:179
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
DerivativeContext\setConfig
setConfig(Config $config)
Definition: DerivativeContext.php:86
DerivativeContext\setSkin
setSkin(Skin $skin)
Definition: DerivativeContext.php:268
DerivativeContext\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: DerivativeContext.php:192
DerivativeContext\getStats
getStats()
Definition: DerivativeContext.php:106
DerivativeContext\getUser
getUser()
Definition: DerivativeContext.php:228
DerivativeContext\getOutput
getOutput()
Definition: DerivativeContext.php:210
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
DerivativeContext\getTitle
getTitle()
Definition: DerivativeContext.php:149
DerivativeContext\$output
OutputPage $output
Definition: DerivativeContext.php:49
DerivativeContext\setRequest
setRequest(WebRequest $request)
Definition: DerivativeContext.php:124
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
Wikitext formatted, in the key only.
Definition: distributors.txt:25
DerivativeContext\getTiming
getTiming()
Definition: DerivativeContext.php:113
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
title
title
Definition: parserTests.txt:219
DerivativeContext\setUser
setUser(User $user)
Definition: DerivativeContext.php:221
DerivativeContext\getRequest
getRequest()
Definition: DerivativeContext.php:131
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
OutputPage
This class should be covered by a general architecture document which does not exist as of January 20...
Definition: OutputPage.php:45
MutableContext
Definition: MutableContext.php:25
DerivativeContext\setTitle
setTitle(Title $title)
Definition: DerivativeContext.php:142
DerivativeContext\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: DerivativeContext.php:165
request
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2224
skin
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a skin(according to that user 's preference)
DerivativeContext\getConfig
getConfig()
Definition: DerivativeContext.php:93
DerivativeContext\getSkin
getSkin()
Definition: DerivativeContext.php:276
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:38
$args
if( $line===false) $args
Definition: cdb.php:64
Title
Represents a title within MediaWiki.
Definition: Title.php:39
output
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
DerivativeContext\setLanguage
setLanguage( $language)
Definition: DerivativeContext.php:241
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
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
Skin
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:36
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
DerivativeContext\setOutput
setOutput(OutputPage $output)
Definition: DerivativeContext.php:203
Language
Internationalisation code.
Definition: Language.php:35
DerivativeContext\getLanguage
getLanguage()
Definition: DerivativeContext.php:257
DerivativeContext\$request
WebRequest $request
Definition: DerivativeContext.php:34
DerivativeContext\$lang
Language $lang
Definition: DerivativeContext.php:59