MediaWiki  1.23.6
RequestContext Class Reference

Group all the pieces relevant to the context of a request into one instance. More...

Inheritance diagram for RequestContext:
Collaboration diagram for RequestContext:

Public Member Functions

 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage(). More...
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID. More...
 
 getConfig ()
 Get the Config object. More...
 
 getLang ()
 
 getLanguage ()
 Get the Language object. More...
 
 getOutput ()
 Get the OutputPage object. More...
 
 getRequest ()
 Get the WebRequest object. More...
 
 getSkin ()
 Get the Skin object. More...
 
 getTitle ()
 Get the Title object. More...
 
 getUser ()
 Get the User object. More...
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ()
 Helpful methods. More...
 
 setConfig (Config $c)
 Set the Config object. More...
 
 setLang ( $l)
 Set the Language object. More...
 
 setLanguage ( $l)
 Set the Language object. More...
 
 setOutput (OutputPage $o)
 
 setRequest (WebRequest $r)
 Set the WebRequest object. More...
 
 setSkin (Skin $s)
 Set the Skin object. More...
 
 setTitle ( $t)
 Set the Title object. More...
 
 setUser (User $u)
 Set the User object. More...
 
 setWikiPage (WikiPage $p)
 Set the WikiPage object. More...
 

Static Public Member Functions

static getMain ()
 Static methods. More...
 
static importScopedSession (array $params)
 Import the resolved user IP, HTTP headers, user ID, and session ID. More...
 
static newExtraneousContext (Title $title, $request=array())
 Create a new extraneous context. More...
 
static sanitizeLangCode ( $code)
 Accepts a language code and ensures it's sane. More...
 

Private Attributes

Config $config
 
Language $lang
 
OutputPage $output
 
WebRequest $request
 
Skin $skin
 
Title $title
 
User $user
 
WikiPage $wikipage
 

Detailed Description

Group all the pieces relevant to the context of a request into one instance.

Definition at line 30 of file RequestContext.php.

Member Function Documentation

◆ canUseWikiPage()

RequestContext::canUseWikiPage ( )

Check whether a WikiPage object can be get with getWikiPage().

Callers should expect that an exception is thrown from getWikiPage() if this method returns false.

Since
1.19
Returns
bool

Implements IContextSource.

Definition at line 147 of file RequestContext.php.

References $title, Title\canExist(), and getTitle().

◆ exportSession()

RequestContext::exportSession ( )

Export the resolved user IP, HTTP headers, user ID, and session ID.

The result will be reasonably sized to allow for serialization.

Returns
Array
Since
1.21

Implements IContextSource.

Definition at line 436 of file RequestContext.php.

References array(), getRequest(), and getUser().

◆ getConfig()

RequestContext::getConfig ( )

Get the Config object.

Returns
Config

Implements IContextSource.

Definition at line 77 of file RequestContext.php.

References $config, and ConfigFactory\getDefaultInstance().

◆ getLang()

RequestContext::getLang ( )
Deprecated:
since 1.19 Use getLanguage instead
Returns
Language

Implements IContextSource.

Definition at line 297 of file RequestContext.php.

References getLanguage(), and wfDeprecated().

◆ getLanguage()

RequestContext::getLanguage ( )

Get the Language object.

Initialization of user or request objects can depend on this.

Returns
Language
Since
1.19

Implements IContextSource.

Definition at line 310 of file RequestContext.php.

References $e, $lang, $request, $user, $wgContLang, array(), Language\factory(), User\getOption(), getRequest(), getUser(), WebRequest\getVal(), global, sanitizeLangCode(), wfDebugLog(), and wfRunHooks().

Referenced by getLang().

◆ getMain()

◆ getOutput()

RequestContext::getOutput ( )

Get the OutputPage object.

Returns
OutputPage

Implements IContextSource.

Definition at line 212 of file RequestContext.php.

References $output, and output().

◆ getRequest()

RequestContext::getRequest ( )

Get the WebRequest object.

Returns
WebRequest

Implements IContextSource.

Definition at line 101 of file RequestContext.php.

References $request, global, and request.

Referenced by exportSession(), getLanguage(), getSkin(), and getUser().

◆ getSkin()

RequestContext::getSkin ( )

◆ getTitle()

RequestContext::getTitle ( )

Get the Title object.

Returns
Title

Implements IContextSource.

Definition at line 130 of file RequestContext.php.

References $title, $wgTitle, global, and title.

Referenced by canUseWikiPage(), getWikiPage(), and setWikiPage().

◆ getUser()

RequestContext::getUser ( )

Get the User object.

Returns
User

Implements IContextSource.

Definition at line 234 of file RequestContext.php.

References $user, getRequest(), User\newFromSession(), and user.

Referenced by exportSession(), getLanguage(), and getSkin().

◆ getWikiPage()

RequestContext::getWikiPage ( )

Get the WikiPage object.

May throw an exception if there's no Title object set or the Title object belongs to a special namespace that doesn't have WikiPage, so use first canUseWikiPage() to check whether this method can be called safely.

Since
1.19
Exceptions
MWException
Returns
WikiPage

Implements IContextSource.

Definition at line 188 of file RequestContext.php.

References $title, $wikipage, WikiPage\factory(), and getTitle().

◆ importScopedSession()

static RequestContext::importScopedSession ( array  $params)
static

Import the resolved user IP, HTTP headers, user ID, and session ID.

This sets the current session and sets $wgUser and $wgRequest. Once the return value falls out of scope, the old context is restored. This function can only be called within CLI mode scripts.

This will setup the session from the given ID. This is useful when background scripts inherit context when acting on behalf of a user.

Note
suhosin.session.encrypt may interfere with this method.
Parameters
array$paramsResult of RequestContext::exportSession()
Returns
ScopedCallback
Exceptions
MWException
Since
1.21

Definition at line 461 of file RequestContext.php.

References $name, $params, $request, $user, $value, $wgUser, array(), as, getMain(), global, IP\isValid(), User\newFromId(), User\newFromName(), WebRequest\setIP(), and wfSetupSession().

Referenced by AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), and RequestContextTest\testImportScopedSession().

◆ msg()

RequestContext::msg ( )

Helpful methods.

Get a Message object with context set Parameters are the same as wfMessage()

Returns
Message

Implements IContextSource.

Definition at line 407 of file RequestContext.php.

References $args.

◆ newExtraneousContext()

static RequestContext::newExtraneousContext ( Title  $title,
  $request = array() 
)
static

Create a new extraneous context.

The context is filled with information external to the current session.

  • Title is specified by argument
  • Request is a FauxRequest, or a FauxRequest can be specified by argument
  • User is an anonymous user, for separation IPv4 localhost is used
  • Language will be based on the anonymous user and request, may be content language or a uselang param in the fauxrequest data may change the lang
  • Skin will be based on the anonymous user, should be the wiki's default skin
Parameters
Title$titleTitle to use for the extraneous request
WebRequest | array$requestA WebRequest or data to use for a FauxRequest
Returns
RequestContext

Definition at line 535 of file RequestContext.php.

References $request, $title, and User\newFromName().

Referenced by RecentChangeTest\__construct(), LogPage\addEntry(), ManualLogEntry\getRecentChange(), and Title\moveToInternal().

◆ sanitizeLangCode()

static RequestContext::sanitizeLangCode (   $code)
static

Accepts a language code and ensures it's sane.

Outputs a cleaned up language code and replaces with $wgLanguageCode if not sane.

Parameters
string$codeLanguage code
Returns
string

Definition at line 248 of file RequestContext.php.

References global, Language\isValidCode(), and wfDebug().

Referenced by ResourceLoaderContext\getLanguage(), getLanguage(), DerivativeContext\setLanguage(), and setLanguage().

◆ setConfig()

RequestContext::setConfig ( Config  $c)

Set the Config object.

Parameters
Config$c

Definition at line 68 of file RequestContext.php.

◆ setLang()

RequestContext::setLang (   $l)

Set the Language object.

Deprecated:
since 1.19 Use setLanguage instead
Parameters
Language | string$lLanguage instance or language code

Definition at line 269 of file RequestContext.php.

References setLanguage(), and wfDeprecated().

◆ setLanguage()

RequestContext::setLanguage (   $l)

Set the Language object.

Parameters
Language | string$lLanguage instance or language code
Exceptions
MWException
Since
1.19

Definition at line 281 of file RequestContext.php.

References Language\factory(), and sanitizeLangCode().

Referenced by setLang().

◆ setOutput()

RequestContext::setOutput ( OutputPage  $o)
Parameters
$oOutputPage

Definition at line 203 of file RequestContext.php.

References output().

◆ setRequest()

RequestContext::setRequest ( WebRequest  $r)

Set the WebRequest object.

Parameters
WebRequest$r

Definition at line 92 of file RequestContext.php.

References request.

Referenced by SpecialRecentchangesTest\assertConditions(), and ApiEditPage\execute().

◆ setSkin()

RequestContext::setSkin ( Skin  $s)

Set the Skin object.

Parameters
Skin$s

Definition at line 350 of file RequestContext.php.

References $s, ContextSource\setContext(), and skin().

◆ setTitle()

RequestContext::setTitle (   $t)

Set the Title object.

Parameters
Title$t
Exceptions
MWException

Definition at line 116 of file RequestContext.php.

References $t, and title.

Referenced by PreferencesTest\__construct(), RebuildFileCache\execute(), and setWikiPage().

◆ setUser()

RequestContext::setUser ( User  $u)

Set the User object.

Parameters
User$u

Definition at line 225 of file RequestContext.php.

References user.

Referenced by SpecialSearchTest\testProfileAndNamespaceLoading().

◆ setWikiPage()

RequestContext::setWikiPage ( WikiPage  $p)

Set the WikiPage object.

Since
1.19
Parameters
WikiPage$p

Definition at line 168 of file RequestContext.php.

References getTitle(), WikiPage\getTitle(), and setTitle().

Member Data Documentation

◆ $config

Config RequestContext::$config
private

Definition at line 61 of file RequestContext.php.

Referenced by getConfig().

◆ $lang

Language RequestContext::$lang
private

Definition at line 53 of file RequestContext.php.

Referenced by getLanguage().

◆ $output

OutputPage RequestContext::$output
private

Definition at line 45 of file RequestContext.php.

Referenced by getOutput().

◆ $request

WebRequest RequestContext::$request
private

◆ $skin

Skin RequestContext::$skin
private

Definition at line 57 of file RequestContext.php.

Referenced by getSkin().

◆ $title

Title RequestContext::$title
private

Definition at line 37 of file RequestContext.php.

Referenced by canUseWikiPage(), getTitle(), getWikiPage(), and newExtraneousContext().

◆ $user

User RequestContext::$user
private

◆ $wikipage

WikiPage RequestContext::$wikipage
private

Definition at line 41 of file RequestContext.php.

Referenced by getWikiPage().


The documentation for this class was generated from the following file: