MediaWiki
1.30.0
|
Group all the pieces relevant to the context of a request into one instance. More...
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... | |
getLanguage () | |
Get the Language object. More... | |
getOutput () | |
Get the OutputPage object. More... | |
getRequest () | |
Get the WebRequest object. More... | |
getSkin () | |
Get the Skin object. More... | |
getStats () | |
Get the Stats object. More... | |
getTiming () | |
Get the timing object. More... | |
getTitle () | |
Get the Title object. More... | |
getUser () | |
Get the User object. More... | |
getWikiPage () | |
Get the WikiPage object. More... | |
hasTitle () | |
Check, if a Title object is set. More... | |
msg ( $key) | |
Helpful methods. More... | |
setConfig (Config $c) | |
Set the Config 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 (Title $title=null) | |
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 | 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. More... | |
static | importScopedSession (array $params) |
Import an client IP address, HTTP headers, user ID, and session ID. More... | |
static | newExtraneousContext (Title $title, $request=[]) |
Create a new extraneous context. More... | |
static | resetMain () |
Resets singleton returned by getMain(). 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 |
Timing | $timing |
Title | $title |
User | $user |
WikiPage | $wikipage |
Static Private Attributes | |
static RequestContext | $instance = null |
Group all the pieces relevant to the context of a request into one instance.
Definition at line 33 of file RequestContext.php.
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.
Implements IContextSource.
Definition at line 208 of file RequestContext.php.
References $title, Title\canExist(), and getTitle().
RequestContext::exportSession | ( | ) |
Export the resolved user IP, HTTP headers, user ID, and session ID.
The result will be reasonably sized to allow for serialization.
Implements IContextSource.
Definition at line 510 of file RequestContext.php.
References MediaWiki\Session\SessionManager\getGlobalSession(), getRequest(), and getUser().
RequestContext::getConfig | ( | ) |
Get the Config object.
Implements IContextSource.
Definition at line 98 of file RequestContext.php.
References $config.
Referenced by getLanguage(), and getSkin().
RequestContext::getLanguage | ( | ) |
Get the Language object.
Initialization of user or request objects can depend on this.
Exception |
Implements IContextSource.
Definition at line 345 of file RequestContext.php.
References $code, $e, $lang, $request, $user, $wgContLang, Language\factory(), getConfig(), User\getOption(), getRequest(), getUser(), WebRequest\getVal(), global, Hooks\run(), sanitizeLangCode(), and wfDebugLog().
|
static |
Static methods.
Get the RequestContext object associated with the main request
Definition at line 470 of file RequestContext.php.
References $instance.
Referenced by UserBlockedError\__construct(), PermissionsError\__construct(), MediaWiki\__construct(), MediaWiki\Session\PHPSessionHandler\__construct(), Pingback\__construct(), MediaWiki\Session\SessionBackend\__construct(), LogFormatter\__construct(), ApiMain\__construct(), Installer\__construct(), StubUserLang\_newObject(), BotPasswordTest\addDBData(), ApiParseTest\addDBDataOnce(), ApiComparePagesTest\addDBDataOnce(), MediaWiki\Session\BotPasswordSessionProviderTest\addDBDataOnce(), Linker\buildRollbackLink(), ChangeTags\buildTagFilterSelector(), Preprocessor\cacheGetTree(), Preprocessor\cacheSetTree(), SpecialPageFactory\capturePath(), Title\checkUserBlock(), TitleBlacklistHooks\displayBlacklistOverrideNotice(), ApiTestCase\doApiRequest(), ApiTestCase\doLogin(), Undelete\execute(), SpecialUserLogout\execute(), WrapOldPasswords\execute(), RebuildFileCache\execute(), UpdateMediaWiki\execute(), DeferredUpdates\execute(), LoginSignupSpecialPage\execute(), ChangesList\flag(), CaptchaPreAuthenticationProviderTest\flagSession(), FeedUtils\formatDiffRow(), ChangeTags\formatSummaryRow(), Linker\formatTemplates(), Linker\generateRollback(), MediaWiki\Auth\AuthManager\getAuthenticationRequestsInternal(), User\getBlockFromCookieValue(), ActionTest\getContext(), ContextSource\getContext(), Profiler\getContext(), Action\getContext(), SpecialPage\getContext(), Article\getContext(), Block\getCookieValue(), HTMLFancyCaptchaFieldTest\getForm(), MediaWiki\Session\SessionManager\getGlobalSession(), MWTimestamp\getHumanTimestamp(), Language\getHumanTimestamp(), Block\getIdFromCookieValue(), ApiStructureTest\getMain(), getMainAndWarn(), ApiContinuationManagerTest\getManager(), BotPassword\getPassword(), User\getPasswordFactory(), MediaWiki\Session\BotPasswordSessionProviderTest\getProvider(), MWTimestamp\getRelativeTimestamp(), User\getRights(), SpecialPageFactory\getUsablePages(), ApiMain\handleApiBeforeMainException(), importScopedSession(), HTMLButtonField\isBadIE(), WikitextContent\isCountable(), User\loadFromSession(), PageDataRequestHandlerTest\makeOutputPage(), SpecialPageExecutor\newContext(), User\newFatalPermissionDeniedStatus(), EmailNotification\notifyOnPageChange(), CategoryMembershipChangeJob\notifyUpdatesForRevision(), MessageCache\replace(), UserNotLoggedIn\report(), User\resetOptions(), ChangeTags\restrictedTagError(), AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), SpecialBotPasswords\save(), MediaWiki\Auth\AuthManager\setDefaultUserOptions(), TestUser\setPasswordForUser(), MediaWiki\Session\TestBagOStuff\setRawSession(), LoginSignupSpecialPage\setSessionUserForCurrentRequest(), UploadFromUrlTestSuite\setUp(), LogFormatterTest\setUp(), WebInstaller\setupLanguage(), MediaWikiTestCase\setUserLang(), SimpleCaptcha\shouldCheck(), ChangesList\showCharacterDifference(), LogEventsList\showLogExtract(), MediaWiki\Auth\AuthManager\singleton(), MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest\testBeginLinkAttempt(), ApiLoginTest\testBotPassword(), MediaWiki\Session\SessionManagerTest\testConstructor(), ApiStructureTest\testDocumentationExists(), HTMLRestrictionsFieldTest\testForm(), ImageListPagerTest\testFormatValuesThrowException(), ActionTest\testGetActionName_whenCanNotUseWikiPage_defaultsToView(), CaptchaPreAuthenticationProviderTest\testGetAuthenticationRequests(), MediaWiki\Session\SessionManagerTest\testGetGlobalSession(), RequestContextTest\testImportScopedSession(), BotPasswordTest\testLogin(), MediaWiki\Session\SessionBackendTest\testResetIdOfGlobalSession(), BotPasswordTest\testSave(), MediaWiki\Auth\AuthManagerTest\testSetDefaultUserOptions(), MediaWiki\Auth\AuthManagerTest\testSingleton(), HTMLSubmittedValueFieldTest\testSubmit(), HTMLReCaptchaNoCaptchaFieldTest\testSubmit(), MediaWiki\Session\SessionBackendTest\testTakeOverGlobalSession(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestUserCanAuthenticate(), MediaWikiTest\testTryNormaliseRedirect(), MediaWiki\Session\SessionBackendTest\testUnpersistOfGlobalSession(), TitleBlacklistPreAuthenticationProvider\testUserForCreation(), WikiPage\triggerOpportunisticLinksUpdate(), EmailNotification\updateWatchlistTimestamp(), MWExceptionRenderer\useOutputPage(), wfInstallerMain(), and wfStreamThumb().
|
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.
string | $func |
Definition at line 486 of file RequestContext.php.
References getMain(), and wfDebug().
Referenced by ImageGalleryBase\factory().
RequestContext::getOutput | ( | ) |
Get the OutputPage object.
Implements IContextSource.
Definition at line 268 of file RequestContext.php.
RequestContext::getRequest | ( | ) |
Get the WebRequest object.
Implements IContextSource.
Definition at line 122 of file RequestContext.php.
References $request, $wgCommandLineMode, global, and request.
Referenced by exportSession(), getLanguage(), getSkin(), and getUser().
RequestContext::getSkin | ( | ) |
Get the Skin object.
Implements IContextSource.
Definition at line 403 of file RequestContext.php.
References $skin, getConfig(), SkinFactory\getDefaultInstance(), getRequest(), getUser(), Skin\normalizeKey(), Hooks\run(), ContextSource\setContext(), and skin().
RequestContext::getStats | ( | ) |
Get the Stats object.
Implements IContextSource.
Definition at line 143 of file RequestContext.php.
RequestContext::getTiming | ( | ) |
Get the timing object.
Implements IContextSource.
Definition at line 152 of file RequestContext.php.
References $timing.
RequestContext::getTitle | ( | ) |
Get the Title object.
Implements IContextSource.
Definition at line 177 of file RequestContext.php.
References $title, $wgTitle, global, title, wfDebugLog(), and wfGetAllCallers().
Referenced by canUseWikiPage(), and getWikiPage().
RequestContext::getUser | ( | ) |
Get the User object.
Implements IContextSource.
Definition at line 290 of file RequestContext.php.
References $user, getRequest(), User\newFromSession(), and user.
Referenced by exportSession(), getLanguage(), and getSkin().
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.
MWException |
Implements IContextSource.
Definition at line 244 of file RequestContext.php.
References $title, $wikipage, WikiPage\factory(), and getTitle().
RequestContext::hasTitle | ( | ) |
Check, if a Title object is set.
Definition at line 196 of file RequestContext.php.
References title.
Referenced by setWikiPage().
|
static |
Import an client IP address, HTTP headers, user ID, and session ID.
This sets the current session, $wgUser, and $wgRequest from $params. Once the return value falls out of scope, the old context is restored. This method should only be called in contexts where there is no session ID or end user receiving the response (CLI or HTTP job runners). This is partly enforced, and is done so to avoid leaking cookies if certain error conditions arise.
This is useful when background scripts inherit context when acting on behalf of a user. In general the 'sessionId' parameter should be set to an empty string unless session importing is truly needed. This feature is somewhat deprecated.
array | $params | Result of RequestContext::exportSession() |
MWException |
Definition at line 542 of file RequestContext.php.
References $context, $name, $params, $request, $user, $value, $wgRequest, $wgUser, array(), as, User\getId(), getMain(), global, IP\isValid(), User\load(), User\newFromId(), User\newFromName(), WebRequest\setIP(), MediaWiki\Session\SessionManager\singleton(), and use.
Referenced by AssembleUploadChunksJob\run(), PublishStashedFileJob\run(), and RequestContextTest\testImportScopedSession().
RequestContext::msg | ( | $key | ) |
Helpful methods.
Get a Message object with context set Parameters are the same as wfMessage()
string | string[] | MessageSpecifier | $key | Message key, or array of keys, or a MessageSpecifier. |
mixed | $args,... |
Implements MessageLocalizer.
Definition at line 457 of file RequestContext.php.
References $args.
|
static |
Create a new extraneous context.
The context is filled with information external to the current session.
Title | $title | Title to use for the extraneous request |
WebRequest | array | $request | A WebRequest or data to use for a FauxRequest |
Definition at line 640 of file RequestContext.php.
References $context, $request, $title, and User\newFromName().
Referenced by LogPage\addEntry(), ManualLogEntry\getRecentChange(), MovePage\moveToInternal(), SpecialChangeContentModel\onSubmit(), LocalFile\recordUpload2(), and RecentChangeTest\setUp().
|
static |
Resets singleton returned by getMain().
Should be called only from unit tests.
Definition at line 496 of file RequestContext.php.
Referenced by MediaWikiTestCase\doLightweightServiceReset(), LogFormatterTestCase\doTestLogFormatter(), UploadFromUrlTestSuite\setUp(), TitlePermissionTest\setUp(), and MediaWikiTestCase\tearDown().
|
static |
Accepts a language code and ensures it's sane.
Outputs a cleaned up language code and replaces with $wgLanguageCode if not sane.
string | $code | Language code |
Definition at line 304 of file RequestContext.php.
References $code, $wgLanguageCode, global, Language\isValidCode(), and wfDebug().
Referenced by ApiMain\__construct(), getLanguage(), DerivativeContext\setLanguage(), and setLanguage().
RequestContext::setConfig | ( | Config | $c | ) |
Set the Config object.
Config | $c |
Implements MutableContext.
Definition at line 89 of file RequestContext.php.
RequestContext::setLanguage | ( | $l | ) |
Set the Language object.
MWException |
Implements MutableContext.
Definition at line 326 of file RequestContext.php.
References Language\factory(), and sanitizeLangCode().
RequestContext::setOutput | ( | OutputPage | $o | ) |
OutputPage | $o |
Implements MutableContext.
Definition at line 259 of file RequestContext.php.
References output().
RequestContext::setRequest | ( | WebRequest | $r | ) |
Set the WebRequest object.
WebRequest | $r |
Implements MutableContext.
Definition at line 113 of file RequestContext.php.
References request.
Referenced by ApiEditPage\execute().
RequestContext::setSkin | ( | Skin | $s | ) |
Set the Skin object.
Skin | $s |
Implements MutableContext.
Definition at line 393 of file RequestContext.php.
References $s, ContextSource\setContext(), and skin().
RequestContext::setTitle | ( | Title | $title = null | ) |
Set the Title object.
Title | null | $title |
Implements MutableContext.
Definition at line 166 of file RequestContext.php.
Referenced by PreferencesTest\__construct(), and setWikiPage().
RequestContext::setUser | ( | User | $u | ) |
Set the User object.
User | $u |
Implements MutableContext.
Definition at line 281 of file RequestContext.php.
References user.
Referenced by ApiParamInfo\execute().
RequestContext::setWikiPage | ( | WikiPage | $p | ) |
Set the WikiPage object.
WikiPage | $p |
Implements MutableContext.
Definition at line 225 of file RequestContext.php.
References WikiPage\getTitle(), hasTitle(), and setTitle().
|
private |
Definition at line 77 of file RequestContext.php.
Referenced by getConfig().
|
staticprivate |
Definition at line 82 of file RequestContext.php.
Referenced by getMain().
|
private |
Definition at line 62 of file RequestContext.php.
Referenced by getLanguage().
|
private |
Definition at line 52 of file RequestContext.php.
Referenced by getOutput().
|
private |
Definition at line 37 of file RequestContext.php.
Referenced by getLanguage(), getRequest(), importScopedSession(), newExtraneousContext(), and ApiTestContext\newTestContext().
|
private |
Definition at line 67 of file RequestContext.php.
Referenced by getSkin().
|
private |
Definition at line 72 of file RequestContext.php.
Referenced by getTiming().
|
private |
Definition at line 42 of file RequestContext.php.
Referenced by canUseWikiPage(), getTitle(), getWikiPage(), newExtraneousContext(), and setTitle().
|
private |
Definition at line 57 of file RequestContext.php.
Referenced by getLanguage(), getUser(), importScopedSession(), and ApiTestContext\newTestContext().
|
private |
Definition at line 47 of file RequestContext.php.
Referenced by getWikiPage().