MediaWiki  1.30.1
DerivativeContext.php
Go to the documentation of this file.
1 <?php
21 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
23 
35  private $request;
36 
40  private $title;
41 
45  private $wikipage;
46 
50  private $output;
51 
55  private $user;
56 
60  private $lang;
61 
65  private $skin;
66 
70  private $config;
71 
75  private $timing;
76 
80  public function __construct( IContextSource $context ) {
81  $this->setContext( $context );
82  }
83 
89  public function setConfig( Config $s ) {
90  $this->config = $s;
91  }
92 
98  public function getConfig() {
99  if ( !is_null( $this->config ) ) {
100  return $this->config;
101  } else {
102  return $this->getContext()->getConfig();
103  }
104  }
105 
113  public function getStats() {
114  return MediaWikiServices::getInstance()->getStatsdDataFactory();
115  }
116 
122  public function getTiming() {
123  if ( !is_null( $this->timing ) ) {
124  return $this->timing;
125  } else {
126  return $this->getContext()->getTiming();
127  }
128  }
129 
135  public function setRequest( WebRequest $r ) {
136  $this->request = $r;
137  }
138 
144  public function getRequest() {
145  if ( !is_null( $this->request ) ) {
146  return $this->request;
147  } else {
148  return $this->getContext()->getRequest();
149  }
150  }
151 
157  public function setTitle( Title $t ) {
158  $this->title = $t;
159  }
160 
166  public function getTitle() {
167  if ( !is_null( $this->title ) ) {
168  return $this->title;
169  } else {
170  return $this->getContext()->getTitle();
171  }
172  }
173 
182  public function canUseWikiPage() {
183  if ( $this->wikipage !== null ) {
184  return true;
185  } elseif ( $this->title !== null ) {
186  return $this->title->canExist();
187  } else {
188  return $this->getContext()->canUseWikiPage();
189  }
190  }
191 
198  public function setWikiPage( WikiPage $p ) {
199  $this->wikipage = $p;
200  }
201 
211  public function getWikiPage() {
212  if ( !is_null( $this->wikipage ) ) {
213  return $this->wikipage;
214  } else {
215  return $this->getContext()->getWikiPage();
216  }
217  }
218 
224  public function setOutput( OutputPage $o ) {
225  $this->output = $o;
226  }
227 
233  public function getOutput() {
234  if ( !is_null( $this->output ) ) {
235  return $this->output;
236  } else {
237  return $this->getContext()->getOutput();
238  }
239  }
240 
246  public function setUser( User $u ) {
247  $this->user = $u;
248  }
249 
255  public function getUser() {
256  if ( !is_null( $this->user ) ) {
257  return $this->user;
258  } else {
259  return $this->getContext()->getUser();
260  }
261  }
262 
270  public function setLanguage( $l ) {
271  if ( $l instanceof Language ) {
272  $this->lang = $l;
273  } elseif ( is_string( $l ) ) {
275  $obj = Language::factory( $l );
276  $this->lang = $obj;
277  } else {
278  throw new MWException( __METHOD__ . " was passed an invalid type of data." );
279  }
280  }
281 
288  public function getLanguage() {
289  if ( !is_null( $this->lang ) ) {
290  return $this->lang;
291  } else {
292  return $this->getContext()->getLanguage();
293  }
294  }
295 
301  public function setSkin( Skin $s ) {
302  $this->skin = clone $s;
303  $this->skin->setContext( $this );
304  }
305 
311  public function getSkin() {
312  if ( !is_null( $this->skin ) ) {
313  return $this->skin;
314  } else {
315  return $this->getContext()->getSkin();
316  }
317  }
318 
331  public function msg( $key ) {
332  $args = func_get_args();
333 
334  return call_user_func_array( 'wfMessage', $args )->setContext( $this );
335  }
336 }
DerivativeContext\msg
msg( $key)
Get a message using the current context.
Definition: DerivativeContext.php:331
DerivativeContext\__construct
__construct(IContextSource $context)
Definition: DerivativeContext.php:80
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
RequestContext\sanitizeLangCode
static sanitizeLangCode( $code)
Accepts a language code and ensures it's sane.
Definition: RequestContext.php:304
DerivativeContext\$config
Config $config
Definition: DerivativeContext.php:70
DerivativeContext\setConfig
setConfig(Config $s)
Set the SiteConfiguration object.
Definition: DerivativeContext.php:89
DerivativeContext\$wikipage
WikiPage $wikipage
Definition: DerivativeContext.php:45
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
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
$s
$s
Definition: mergeMessageFileList.php:188
DerivativeContext\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: DerivativeContext.php:211
DerivativeContext\getStats
getStats()
Get the stats object.
Definition: DerivativeContext.php:113
DerivativeContext\getUser
getUser()
Get the User object.
Definition: DerivativeContext.php:255
DerivativeContext\getOutput
getOutput()
Get the OutputPage object.
Definition: DerivativeContext.php:233
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()
Get the Title object.
Definition: DerivativeContext.php:166
DerivativeContext\$output
OutputPage $output
Definition: DerivativeContext.php:50
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
MWException
MediaWiki exception.
Definition: MWException.php:26
DerivativeContext\$title
Title $title
Definition: DerivativeContext.php:40
DerivativeContext\$skin
Skin $skin
Definition: DerivativeContext.php:65
DerivativeContext\setSkin
setSkin(Skin $s)
Set the Skin object.
Definition: DerivativeContext.php:301
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()
Get the timing object.
Definition: DerivativeContext.php:122
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:30
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:2141
DerivativeContext\getRequest
getRequest()
Get the WebRequest object.
Definition: DerivativeContext.php:144
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
OutputPage
This class should be covered by a general architecture document which does not exist as of January 20...
Definition: OutputPage.php:44
MutableContext
Definition: MutableContext.php:25
DerivativeContext\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: DerivativeContext.php:182
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\setTitle
setTitle(Title $t)
Set the Title object.
Definition: DerivativeContext.php:157
DerivativeContext\getConfig
getConfig()
Get the Config object.
Definition: DerivativeContext.php:98
DerivativeContext\setWikiPage
setWikiPage(WikiPage $p)
Set the WikiPage object.
Definition: DerivativeContext.php:198
DerivativeContext\getSkin
getSkin()
Get the Skin object.
Definition: DerivativeContext.php:311
DerivativeContext\$timing
Timing $timing
Definition: DerivativeContext.php:75
DerivativeContext\$user
User $user
Definition: DerivativeContext.php:55
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
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:63
Title
Represents a title within MediaWiki.
Definition: Title.php:39
DerivativeContext\setUser
setUser(User $u)
Set the User object.
Definition: DerivativeContext.php:246
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\setRequest
setRequest(WebRequest $r)
Set the WebRequest object.
Definition: DerivativeContext.php:135
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
$t
$t
Definition: testCompression.php:67
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:36
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
DerivativeContext\setOutput
setOutput(OutputPage $o)
Set the OutputPage object.
Definition: DerivativeContext.php:224
Language
Internationalisation code.
Definition: Language.php:35
DerivativeContext\getLanguage
getLanguage()
Get the Language object.
Definition: DerivativeContext.php:288
DerivativeContext\$request
WebRequest $request
Definition: DerivativeContext.php:35
DerivativeContext\setLanguage
setLanguage( $l)
Set the Language object.
Definition: DerivativeContext.php:270
DerivativeContext\$lang
Language $lang
Definition: DerivativeContext.php:60