Get the MainConfig from MediaWikiServices instead of RequestContext
The getConfig of a ContextSource should only be used, if the ContextSource is available. Getting the global context just for the config looks harder to fix/inject as using the MainConfig from MediaWikiServices Change-Id: Iaf14bfc7bd68cc315672e1c256887faf87e22542
This commit is contained in:
parent
a643ac897d
commit
de47d93928
14 changed files with 25 additions and 24 deletions
|
|
@ -594,7 +594,7 @@ class Html {
|
|||
$attrs = [];
|
||||
if ( $nonce !== null ) {
|
||||
$attrs['nonce'] = $nonce;
|
||||
} elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
|
||||
} elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
|
||||
wfWarn( "no nonce set on script. CSP will break it" );
|
||||
}
|
||||
|
||||
|
|
@ -618,7 +618,7 @@ class Html {
|
|||
$attrs = [ 'src' => $url ];
|
||||
if ( $nonce !== null ) {
|
||||
$attrs['nonce'] = $nonce;
|
||||
} elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
|
||||
} elseif ( ContentSecurityPolicy::isNonceRequired( MediaWikiServices::getInstance()->getMainConfig() ) ) {
|
||||
wfWarn( "no nonce set on script. CSP will break it" );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -277,8 +277,8 @@ abstract class AbstractBlock implements Block {
|
|||
* unsure (e.g. unrecognized right or unset property)
|
||||
*/
|
||||
public function appliesToRight( $right ) {
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$blockDisablesLogin = $config->get( MainConfigNames::BlockDisablesLogin );
|
||||
$blockDisablesLogin = MediaWikiServices::getInstance()->getMainConfig()
|
||||
->get( MainConfigNames::BlockDisablesLogin );
|
||||
|
||||
$res = null;
|
||||
switch ( $right ) {
|
||||
|
|
@ -498,8 +498,9 @@ abstract class AbstractBlock implements Block {
|
|||
|
||||
// This is a type of block which uses the ipb_allow_usertalk
|
||||
// flag. The flag can still be overridden by global configs.
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
if ( !$config->get( MainConfigNames::BlockAllowsUTEdit ) ) {
|
||||
if ( !MediaWikiServices::getInstance()->getMainConfig()
|
||||
->get( MainConfigNames::BlockAllowsUTEdit )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return !$this->isUsertalkEditAllowed();
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@ class CategoryMembershipChangeJob extends Job {
|
|||
protected function notifyUpdatesForRevision(
|
||||
LBFactory $lbFactory, WikiPage $page, RevisionRecord $newRev
|
||||
) {
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$title = $page->getTitle();
|
||||
|
||||
// Get the new revision
|
||||
|
|
@ -216,7 +215,7 @@ class CategoryMembershipChangeJob extends Job {
|
|||
$catMembChange = new CategoryMembershipChange( $title, $blc, $newRev );
|
||||
$catMembChange->checkTemplateLinks();
|
||||
|
||||
$batchSize = $config->get( MainConfigNames::UpdateRowsPerQuery );
|
||||
$batchSize = $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
|
||||
$insertCount = 0;
|
||||
|
||||
foreach ( $categoryInserts as $categoryName ) {
|
||||
|
|
|
|||
|
|
@ -3191,7 +3191,7 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
|
|||
return;
|
||||
}
|
||||
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||||
|
||||
$params = [
|
||||
'isOpportunistic' => true,
|
||||
|
|
@ -3216,7 +3216,8 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
|
|||
RefreshLinksJob::newPrioritized( $this->mTitle, $params )
|
||||
);
|
||||
} elseif ( !$config->get( MainConfigNames::MiserMode ) &&
|
||||
$parserOutput->hasReducedExpiry() ) {
|
||||
$parserOutput->hasReducedExpiry()
|
||||
) {
|
||||
// Assume the output contains "dynamic" time/random based magic words.
|
||||
// Only update pages that expired due to dynamic content and NOT due to edits
|
||||
// to referenced templates/files. When the cache expires due to dynamic content,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace MediaWiki\Session;
|
|||
|
||||
use BagOStuff;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Wikimedia\AtEase\AtEase;
|
||||
|
|
@ -58,7 +59,7 @@ class PHPSessionHandler implements \SessionHandlerInterface {
|
|||
|
||||
protected function __construct( SessionManager $manager ) {
|
||||
$this->setEnableFlags(
|
||||
\RequestContext::getMain()->getConfig()->get( MainConfigNames::PHPSessionHandling )
|
||||
MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::PHPSessionHandling )
|
||||
);
|
||||
$manager->setupPHPSessionHandler( $this );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,8 @@ final class SessionBackend {
|
|||
SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger,
|
||||
HookContainer $hookContainer, $lifetime
|
||||
) {
|
||||
$phpSessionHandling = \RequestContext::getMain()->getConfig()->get( MainConfigNames::PHPSessionHandling );
|
||||
$phpSessionHandling = MediaWikiServices::getInstance()->getMainConfig()
|
||||
->get( MainConfigNames::PHPSessionHandling );
|
||||
$this->usePhpSessionHandling = $phpSessionHandling !== 'disable';
|
||||
|
||||
if ( $info->getUserInfo() && !$info->getUserInfo()->isVerified() ) {
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ class ContentSecurityPolicyTest extends MediaWikiIntegrationTestCase {
|
|||
public function testCSPIsEnabled( $main, $reportOnly, $expected ) {
|
||||
$this->setMwGlobals( 'wgCSPReportOnlyHeader', $reportOnly );
|
||||
$this->setMwGlobals( 'wgCSPHeader', $main );
|
||||
$res = ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() );
|
||||
$res = ContentSecurityPolicy::isNonceRequired( $this->getServiceContainer()->getMainConfig() );
|
||||
$this->assertSame( $expected, $res );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use MediaWiki\ResourceLoader\FileModule;
|
|||
use MediaWiki\ResourceLoader\FilePath;
|
||||
use MediaWiki\ResourceLoader\ResourceLoader;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use RequestContext;
|
||||
use ResourceLoaderFileTestModule;
|
||||
use ResourceLoaderTestCase;
|
||||
use RuntimeException;
|
||||
|
|
@ -640,7 +639,7 @@ class FileModuleTest extends ResourceLoaderTestCase {
|
|||
$nosemiScript = file_get_contents( "$basePath/script-nosemi.js" );
|
||||
$vueComponentDebug = trim( file_get_contents( "$basePath/vue-component-output-debug.js.txt" ) );
|
||||
$vueComponentNonDebug = trim( file_get_contents( "$basePath/vue-component-output-nondebug.js.txt" ) );
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$config = \MediaWiki\MediaWikiServices::getInstance()->getMainConfig();
|
||||
return [
|
||||
[
|
||||
$base + [
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati
|
|||
->onlyMethods( [ 'allowsAuthenticationDataChange' ] )
|
||||
->setConstructorArgs( [
|
||||
$request,
|
||||
\RequestContext::getMain()->getConfig(),
|
||||
$mwServices->getMainConfig(),
|
||||
$mwServices->getObjectFactory(),
|
||||
$mwServices->getHookContainer(),
|
||||
$mwServices->getReadOnlyMode(),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace MediaWiki\Session;
|
|||
use MediaWikiIntegrationTestCase;
|
||||
use MultiConfig;
|
||||
use Psr\Log\LogLevel;
|
||||
use RequestContext;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
|
|
@ -45,7 +44,7 @@ class BotPasswordSessionProviderTest extends MediaWikiIntegrationTestCase {
|
|||
] );
|
||||
}
|
||||
$manager = new SessionManager( [
|
||||
'config' => new MultiConfig( [ $this->config, RequestContext::getMain()->getConfig() ] ),
|
||||
'config' => new MultiConfig( [ $this->config, $this->getServiceContainer()->getMainConfig() ] ),
|
||||
'logger' => new \Psr\Log\NullLogger,
|
||||
'store' => new TestBagOStuff,
|
||||
] );
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class SessionManagerTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertSame( $this->store, $manager->store );
|
||||
|
||||
$manager = TestingAccessWrapper::newFromObject( new SessionManager() );
|
||||
$this->assertSame( \RequestContext::getMain()->getConfig(), $manager->config );
|
||||
$this->assertSame( $this->getServiceContainer()->getMainConfig(), $manager->config );
|
||||
|
||||
$manager = TestingAccessWrapper::newFromObject( new SessionManager( [
|
||||
'config' => $this->config,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace MediaWiki\Session;
|
|||
|
||||
use CachedBagOStuff;
|
||||
use HashBagOStuff;
|
||||
use RequestContext;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* BagOStuff with utility functions for MediaWiki\\Session\\* testing
|
||||
|
|
@ -55,7 +55,7 @@ class TestBagOStuff extends CachedBagOStuff {
|
|||
* @param array|mixed $blob Session metadata and data
|
||||
*/
|
||||
public function setRawSession( $id, $blob ) {
|
||||
$expiry = RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
|
||||
$expiry = MediaWikiServices::getInstance()->getMainConfig()->get( 'ObjectCacheSessionExpiry' );
|
||||
$this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
|
|||
ScopedCallback::consume( $reset );
|
||||
|
||||
// Now configure BotPasswordSessionProvider for further tests...
|
||||
$mainConfig = RequestContext::getMain()->getConfig();
|
||||
$mainConfig = $this->getServiceContainer()->getMainConfig();
|
||||
$config = new HashConfig( [
|
||||
'SessionProviders' => $mainConfig->get( 'SessionProviders' ) + [
|
||||
MediaWiki\Session\BotPasswordSessionProvider::class => [
|
||||
|
|
@ -288,7 +288,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
] );
|
||||
$manager = new SessionManager( [
|
||||
'config' => new MultiConfig( [ $config, RequestContext::getMain()->getConfig() ] ),
|
||||
'config' => new MultiConfig( [ $config, $mainConfig ] ),
|
||||
'logger' => new Psr\Log\NullLogger,
|
||||
'store' => new EmptyBagOStuff,
|
||||
] );
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class ApiStructureTest extends MediaWikiIntegrationTestCase {
|
|||
// Set configuration variables
|
||||
$main->getContext()->setConfig( new MultiConfig( [
|
||||
new HashConfig( $globals ),
|
||||
RequestContext::getMain()->getConfig(),
|
||||
$this->getServiceContainer()->getMainConfig(),
|
||||
] ) );
|
||||
foreach ( $globals as $k => $v ) {
|
||||
$this->setMwGlobals( "wg$k", $v );
|
||||
|
|
|
|||
Loading…
Reference in a new issue