MediaWiki  REL1_24
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:

List of all members.

Public Member Functions

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

Static Public Member Functions

static getMain ()
 Static methods.
static getMainAndWarn ($func=__METHOD__)
 Get the RequestContext object associated with the main request and gives a warning to the log, to find places, where a context maybe is missing.
static importScopedSession (array $params)
 Import the resolved user IP, HTTP headers, user ID, and session ID.
static newExtraneousContext (Title $title, $request=array())
 Create a new extraneous context.
static resetMain ()
 Resets singleton returned by getMain().
static sanitizeLangCode ($code)
 Accepts a language code and ensures it's sane.

Private Attributes

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

Static Private Attributes

static $instance = null

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

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 148 of file RequestContext.php.

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 448 of file RequestContext.php.

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

Get the Config object.

Returns:
Config

Implements IContextSource.

Definition at line 82 of file RequestContext.php.

Referenced by 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 286 of file RequestContext.php.

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

Referenced by UploadFromUrlTestSuite\setUp().

static RequestContext::getMainAndWarn ( func = __METHOD__) [static]

Get the RequestContext object associated with the main request and gives a warning to the log, to find places, where a context maybe is missing.

Parameters:
string$func
Returns:
RequestContext
Since:
1.24

Definition at line 424 of file RequestContext.php.

Get the OutputPage object.

Returns:
OutputPage

Implements IContextSource.

Definition at line 209 of file RequestContext.php.

Get the WebRequest object.

Returns:
WebRequest

Implements IContextSource.

Definition at line 106 of file RequestContext.php.

Referenced by exportSession(), and getLanguage().

Get the Skin object.

Returns:
Skin

Implements IContextSource.

Definition at line 341 of file RequestContext.php.

Get the Title object.

Returns:
Title|null

Implements IContextSource.

Definition at line 131 of file RequestContext.php.

Get the User object.

Returns:
User

Implements IContextSource.

Definition at line 231 of file RequestContext.php.

Referenced by exportSession(), and getLanguage().

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 185 of file RequestContext.php.

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 473 of file RequestContext.php.

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

Helpful methods.

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

Returns:
Message

Implements IContextSource.

Definition at line 395 of file RequestContext.php.

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 548 of file RequestContext.php.

Referenced by RecentChangeTest\__construct().

static RequestContext::resetMain ( ) [static]

Resets singleton returned by getMain().

Should be called only from unit tests.

Definition at line 434 of file RequestContext.php.

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 245 of file RequestContext.php.

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

Set the Config object.

Parameters:
Config$c

Definition at line 73 of file RequestContext.php.

Set the Language object.

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

Definition at line 267 of file RequestContext.php.

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

Parameters:
OutputPage$o

Definition at line 200 of file RequestContext.php.

Set the WebRequest object.

Parameters:
WebRequest$r

Definition at line 97 of file RequestContext.php.

Referenced by ApiEditPage\execute().

Set the Skin object.

Parameters:
Skin$s

Definition at line 331 of file RequestContext.php.

Set the Title object.

Parameters:
Title$title

Definition at line 120 of file RequestContext.php.

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

Set the User object.

Parameters:
User$u

Definition at line 222 of file RequestContext.php.

Referenced by SpecialSearchTest\testProfileAndNamespaceLoading().

Set the WikiPage object.

Since:
1.19
Parameters:
WikiPage$p

Definition at line 165 of file RequestContext.php.


Member Data Documentation

Config RequestContext::$config [private]

Definition at line 61 of file RequestContext.php.

RequestContext::$instance = null [static, private]

Definition at line 66 of file RequestContext.php.

Referenced by getMain().

Language RequestContext::$lang [private]

Definition at line 53 of file RequestContext.php.

OutputPage RequestContext::$output [private]

Definition at line 45 of file RequestContext.php.

WebRequest RequestContext::$request [private]

Definition at line 33 of file RequestContext.php.

Referenced by getLanguage().

Skin RequestContext::$skin [private]

Definition at line 57 of file RequestContext.php.

Title RequestContext::$title [private]

Definition at line 37 of file RequestContext.php.

User RequestContext::$user [private]

Definition at line 49 of file RequestContext.php.

Referenced by getLanguage(), and ApiTestContext\newTestContext().

WikiPage RequestContext::$wikipage [private]

Definition at line 41 of file RequestContext.php.


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