Go to the documentation of this file.
25 use Wikimedia\AtEase\AtEase;
28 use Wikimedia\ScopedCallback;
101 if ( $this->config ===
null ) {
104 $this->config = MediaWikiServices::getInstance()->getMainConfig();
121 if ( $this->request ===
null ) {
140 return MediaWikiServices::getInstance()->getStatsdDataFactory();
147 if ( $this->timing ===
null ) {
148 $this->timing =
new Timing( [
149 'logger' => LoggerFactory::getInstance(
'Timing' )
161 $this->wikipage =
null;
168 if ( $this->title ===
null ) {
169 global
$wgTitle; # fallback to $wg till we can improve
this
173 __METHOD__ .
' called by ' .
wfGetAllCallers( 5 ) .
' with no title set.'
187 return $this->title !==
null;
199 if ( $this->wikipage ) {
215 if ( !$this->
hasTitle() || !$pageTitle->equals( $this->getTitle() ) ) {
219 $this->wikipage = $wikiPage;
233 if ( $this->wikipage ===
null ) {
236 throw new MWException( __METHOD__ .
' called without Title object set' );
255 if ( $this->output ===
null ) {
256 $this->output =
new OutputPage( $this );
275 if ( $this->user ===
null ) {
292 $code = strtolower( $code );
308 if ( $language instanceof
Language ) {
309 $this->lang = $language;
310 } elseif ( is_string( $language ) ) {
315 throw new MWException( __METHOD__ .
" was passed an invalid type of data." );
327 if ( $this->languageRecursion ===
true ) {
328 trigger_error(
"Recursion detected in " . __METHOD__, E_USER_WARNING );
330 wfDebugLog(
'recursion-guard',
"Recursion detected:\n" . $e->getTraceAsString() );
332 $code = $this->
getConfig()->get(
'LanguageCode' ) ?:
'en';
334 } elseif ( $this->lang ===
null ) {
335 $this->languageRecursion =
true;
343 if ( $code ===
'user' ) {
350 if ( $code === $this->
getConfig()->
get(
'LanguageCode' ) ) {
351 $this->lang = MediaWikiServices::getInstance()->getContentLanguage();
357 $this->languageRecursion =
false;
368 $this->skin = clone
$skin;
376 if ( $this->skin ===
null ) {
379 $factory = MediaWikiServices::getInstance()->getSkinFactory();
384 } elseif ( is_string(
$skin ) ) {
388 $this->skin = $factory->makeSkin( $normalized );
391 if ( !in_array(
'skin', $this->
getConfig()->
get(
'HiddenPrefs' ) ) ) {
392 $userSkin = $this->
getUser()->getOption(
'skin' );
394 $userSkin = $this->
getRequest()->getRawVal(
'useskin', $userSkin );
396 $userSkin = $this->
getConfig()->get(
'DefaultSkin' );
403 $this->skin = $factory->makeSkin( $normalized );
407 $this->skin->setContext( $this );
422 public function msg( $key, ...$params ) {
423 return wfMessage( $key, ...$params )->setContext( $this );
432 if ( self::$instance ===
null ) {
433 self::$instance =
new self;
448 wfDebug( $func .
' called without context. ' .
449 "Using RequestContext::getMain() for sanity\n" );
458 if ( !( defined(
'MW_PHPUNIT_TEST' ) || defined(
'MW_PARSER_TEST' ) ) ) {
459 throw new MWException( __METHOD__ .
'() should be called only from unit tests!' );
461 self::$instance =
null;
475 'headers' => $this->
getRequest()->getAllHeaders(),
476 'sessionId' => $session->isPersistent() ? $session->getId() :
'',
477 'userId' => $this->
getUser()->getId()
504 if ( strlen( $params[
'sessionId'] ) &&
505 MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent()
509 throw new MWException(
"Sessions can only be imported when none is active." );
511 throw new MWException(
"Invalid client IP address '{$params['ip']}'." );
514 if ( $params[
'userId'] ) {
518 throw new MWException(
"No user with ID '{$params['userId']}'." );
524 $importSessionFunc =
function (
User $user, array $params ) {
530 if (
MediaWiki\Session\PHPSessionHandler::isEnabled() ) {
531 session_write_close();
538 if ( strlen( $params[
'sessionId'] ) ) {
540 $session = $manager->getSessionById( $params[
'sessionId'],
true )
541 ?: $manager->getEmptySession();
555 if ( $session &&
MediaWiki\Session\PHPSessionHandler::isEnabled() ) {
556 session_id( $session->getId() );
557 AtEase::quietCall(
'session_start' );
561 foreach ( $params[
'headers'] as $name => $value ) {
562 $request->setHeader( $name, $value );
573 $importSessionFunc(
$user, $params );
576 return new ScopedCallback(
577 function () use ( $importSessionFunc, $oUser, $oParams, $oRequest ) {
579 $importSessionFunc( $oUser, $oParams );
load( $flags=self::READ_NORMAL)
Load the user table data for this object from the source given by mFrom.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
WebRequest clone which takes values from a provided array.
static newFromId( $id)
Static factory method for creation from a given user ID.
static sanitizeLangCode( $code)
Accepts a language code and ensures it's sane.
setRequest(WebRequest $request)
getId()
Get the user's ID.
setWikiPage(WikiPage $wikiPage)
static newFromSession(WebRequest $request=null)
Create a new user object using data from session.
static RequestContext $instance
Class representing a MediaWiki article and history.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
if(! $wgRequest->checkUrlExtension()) if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Interface for configuration instances.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
static normalizeKey( $key)
Normalize a skin preference value to a form that can be loaded.
An interface to help developers measure the performance of their applications.
global $wgCommandLineMode
getWikiPage()
Get the WikiPage object.
getTitle()
Get the title object of the article.
Group all the pieces relevant to the context of a request into one instance.
canExist()
Is this in a namespace that allows actual pages?
getLanguage()
Get the Language object.
static getMainAndWarn( $func=__METHOD__)
Get the RequestContext object associated with the main request and gives a warning to the log,...
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
setContext(IContextSource $context)
getRawVal( $name, $default=null)
Fetch a scalar from the input without normalization, or return $default if it's not set.
static resetMain()
Resets singleton returned by getMain().
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
$wgLanguageCode
Site language code.
static getMain()
Get the RequestContext object associated with the main request.
static isValid( $ip)
Validate an IP address.
static isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
static importScopedSession(array $params)
Import an client IP address, HTTP headers, user ID, and session ID.
Interface for objects which can provide a MediaWiki context on request.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
wfGetAllCallers( $limit=3)
Return a string consisting of callers in the stack.
Represents a title within MediaWiki.
bool $languageRecursion
Boolean flag to guard against recursion in getLanguage.
setOutput(OutputPage $output)
static factory( $code)
Get a cached or new language object for a given language code.
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
if(! $wgDBerrorLogTZ) $wgRequest
The main skin class which provides methods and properties for all other skins.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
setConfig(Config $config)
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Internationalisation code.
exportSession()
Export the resolved user IP, HTTP headers, user ID, and session ID.
hasTitle()
Check, if a Title object is set.
setTitle(Title $title=null)