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:
Umherirrender 2022-05-24 22:00:50 +02:00 committed by Krinkle
parent a643ac897d
commit de47d93928
14 changed files with 25 additions and 24 deletions

View file

@ -594,7 +594,7 @@ class Html {
$attrs = []; $attrs = [];
if ( $nonce !== null ) { if ( $nonce !== null ) {
$attrs['nonce'] = $nonce; $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" ); wfWarn( "no nonce set on script. CSP will break it" );
} }
@ -618,7 +618,7 @@ class Html {
$attrs = [ 'src' => $url ]; $attrs = [ 'src' => $url ];
if ( $nonce !== null ) { if ( $nonce !== null ) {
$attrs['nonce'] = $nonce; $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" ); wfWarn( "no nonce set on script. CSP will break it" );
} }

View file

@ -277,8 +277,8 @@ abstract class AbstractBlock implements Block {
* unsure (e.g. unrecognized right or unset property) * unsure (e.g. unrecognized right or unset property)
*/ */
public function appliesToRight( $right ) { public function appliesToRight( $right ) {
$config = RequestContext::getMain()->getConfig(); $blockDisablesLogin = MediaWikiServices::getInstance()->getMainConfig()
$blockDisablesLogin = $config->get( MainConfigNames::BlockDisablesLogin ); ->get( MainConfigNames::BlockDisablesLogin );
$res = null; $res = null;
switch ( $right ) { switch ( $right ) {
@ -498,8 +498,9 @@ abstract class AbstractBlock implements Block {
// This is a type of block which uses the ipb_allow_usertalk // This is a type of block which uses the ipb_allow_usertalk
// flag. The flag can still be overridden by global configs. // flag. The flag can still be overridden by global configs.
$config = RequestContext::getMain()->getConfig(); if ( !MediaWikiServices::getInstance()->getMainConfig()
if ( !$config->get( MainConfigNames::BlockAllowsUTEdit ) ) { ->get( MainConfigNames::BlockAllowsUTEdit )
) {
return true; return true;
} }
return !$this->isUsertalkEditAllowed(); return !$this->isUsertalkEditAllowed();

View file

@ -185,7 +185,6 @@ class CategoryMembershipChangeJob extends Job {
protected function notifyUpdatesForRevision( protected function notifyUpdatesForRevision(
LBFactory $lbFactory, WikiPage $page, RevisionRecord $newRev LBFactory $lbFactory, WikiPage $page, RevisionRecord $newRev
) { ) {
$config = RequestContext::getMain()->getConfig();
$title = $page->getTitle(); $title = $page->getTitle();
// Get the new revision // Get the new revision
@ -216,7 +215,7 @@ class CategoryMembershipChangeJob extends Job {
$catMembChange = new CategoryMembershipChange( $title, $blc, $newRev ); $catMembChange = new CategoryMembershipChange( $title, $blc, $newRev );
$catMembChange->checkTemplateLinks(); $catMembChange->checkTemplateLinks();
$batchSize = $config->get( MainConfigNames::UpdateRowsPerQuery ); $batchSize = $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
$insertCount = 0; $insertCount = 0;
foreach ( $categoryInserts as $categoryName ) { foreach ( $categoryInserts as $categoryName ) {

View file

@ -3191,7 +3191,7 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
return; return;
} }
$config = RequestContext::getMain()->getConfig(); $config = MediaWikiServices::getInstance()->getMainConfig();
$params = [ $params = [
'isOpportunistic' => true, 'isOpportunistic' => true,
@ -3216,7 +3216,8 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
RefreshLinksJob::newPrioritized( $this->mTitle, $params ) RefreshLinksJob::newPrioritized( $this->mTitle, $params )
); );
} elseif ( !$config->get( MainConfigNames::MiserMode ) && } elseif ( !$config->get( MainConfigNames::MiserMode ) &&
$parserOutput->hasReducedExpiry() ) { $parserOutput->hasReducedExpiry()
) {
// Assume the output contains "dynamic" time/random based magic words. // Assume the output contains "dynamic" time/random based magic words.
// Only update pages that expired due to dynamic content and NOT due to edits // 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, // to referenced templates/files. When the cache expires due to dynamic content,

View file

@ -25,6 +25,7 @@ namespace MediaWiki\Session;
use BagOStuff; use BagOStuff;
use MediaWiki\MainConfigNames; use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Wikimedia\AtEase\AtEase; use Wikimedia\AtEase\AtEase;
@ -58,7 +59,7 @@ class PHPSessionHandler implements \SessionHandlerInterface {
protected function __construct( SessionManager $manager ) { protected function __construct( SessionManager $manager ) {
$this->setEnableFlags( $this->setEnableFlags(
\RequestContext::getMain()->getConfig()->get( MainConfigNames::PHPSessionHandling ) MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::PHPSessionHandling )
); );
$manager->setupPHPSessionHandler( $this ); $manager->setupPHPSessionHandler( $this );
} }

View file

@ -156,7 +156,8 @@ final class SessionBackend {
SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger, SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger,
HookContainer $hookContainer, $lifetime HookContainer $hookContainer, $lifetime
) { ) {
$phpSessionHandling = \RequestContext::getMain()->getConfig()->get( MainConfigNames::PHPSessionHandling ); $phpSessionHandling = MediaWikiServices::getInstance()->getMainConfig()
->get( MainConfigNames::PHPSessionHandling );
$this->usePhpSessionHandling = $phpSessionHandling !== 'disable'; $this->usePhpSessionHandling = $phpSessionHandling !== 'disable';
if ( $info->getUserInfo() && !$info->getUserInfo()->isVerified() ) { if ( $info->getUserInfo() && !$info->getUserInfo()->isVerified() ) {

View file

@ -370,7 +370,7 @@ class ContentSecurityPolicyTest extends MediaWikiIntegrationTestCase {
public function testCSPIsEnabled( $main, $reportOnly, $expected ) { public function testCSPIsEnabled( $main, $reportOnly, $expected ) {
$this->setMwGlobals( 'wgCSPReportOnlyHeader', $reportOnly ); $this->setMwGlobals( 'wgCSPReportOnlyHeader', $reportOnly );
$this->setMwGlobals( 'wgCSPHeader', $main ); $this->setMwGlobals( 'wgCSPHeader', $main );
$res = ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ); $res = ContentSecurityPolicy::isNonceRequired( $this->getServiceContainer()->getMainConfig() );
$this->assertSame( $expected, $res ); $this->assertSame( $expected, $res );
} }

View file

@ -9,7 +9,6 @@ use MediaWiki\ResourceLoader\FileModule;
use MediaWiki\ResourceLoader\FilePath; use MediaWiki\ResourceLoader\FilePath;
use MediaWiki\ResourceLoader\ResourceLoader; use MediaWiki\ResourceLoader\ResourceLoader;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use RequestContext;
use ResourceLoaderFileTestModule; use ResourceLoaderFileTestModule;
use ResourceLoaderTestCase; use ResourceLoaderTestCase;
use RuntimeException; use RuntimeException;
@ -640,7 +639,7 @@ class FileModuleTest extends ResourceLoaderTestCase {
$nosemiScript = file_get_contents( "$basePath/script-nosemi.js" ); $nosemiScript = file_get_contents( "$basePath/script-nosemi.js" );
$vueComponentDebug = trim( file_get_contents( "$basePath/vue-component-output-debug.js.txt" ) ); $vueComponentDebug = trim( file_get_contents( "$basePath/vue-component-output-debug.js.txt" ) );
$vueComponentNonDebug = trim( file_get_contents( "$basePath/vue-component-output-nondebug.js.txt" ) ); $vueComponentNonDebug = trim( file_get_contents( "$basePath/vue-component-output-nondebug.js.txt" ) );
$config = RequestContext::getMain()->getConfig(); $config = \MediaWiki\MediaWikiServices::getInstance()->getMainConfig();
return [ return [
[ [
$base + [ $base + [

View file

@ -141,7 +141,7 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati
->onlyMethods( [ 'allowsAuthenticationDataChange' ] ) ->onlyMethods( [ 'allowsAuthenticationDataChange' ] )
->setConstructorArgs( [ ->setConstructorArgs( [
$request, $request,
\RequestContext::getMain()->getConfig(), $mwServices->getMainConfig(),
$mwServices->getObjectFactory(), $mwServices->getObjectFactory(),
$mwServices->getHookContainer(), $mwServices->getHookContainer(),
$mwServices->getReadOnlyMode(), $mwServices->getReadOnlyMode(),

View file

@ -5,7 +5,6 @@ namespace MediaWiki\Session;
use MediaWikiIntegrationTestCase; use MediaWikiIntegrationTestCase;
use MultiConfig; use MultiConfig;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
use RequestContext;
use Wikimedia\TestingAccessWrapper; use Wikimedia\TestingAccessWrapper;
/** /**
@ -45,7 +44,7 @@ class BotPasswordSessionProviderTest extends MediaWikiIntegrationTestCase {
] ); ] );
} }
$manager = new SessionManager( [ $manager = new SessionManager( [
'config' => new MultiConfig( [ $this->config, RequestContext::getMain()->getConfig() ] ), 'config' => new MultiConfig( [ $this->config, $this->getServiceContainer()->getMainConfig() ] ),
'logger' => new \Psr\Log\NullLogger, 'logger' => new \Psr\Log\NullLogger,
'store' => new TestBagOStuff, 'store' => new TestBagOStuff,
] ); ] );

View file

@ -122,7 +122,7 @@ class SessionManagerTest extends MediaWikiIntegrationTestCase {
$this->assertSame( $this->store, $manager->store ); $this->assertSame( $this->store, $manager->store );
$manager = TestingAccessWrapper::newFromObject( new SessionManager() ); $manager = TestingAccessWrapper::newFromObject( new SessionManager() );
$this->assertSame( \RequestContext::getMain()->getConfig(), $manager->config ); $this->assertSame( $this->getServiceContainer()->getMainConfig(), $manager->config );
$manager = TestingAccessWrapper::newFromObject( new SessionManager( [ $manager = TestingAccessWrapper::newFromObject( new SessionManager( [
'config' => $this->config, 'config' => $this->config,

View file

@ -4,7 +4,7 @@ namespace MediaWiki\Session;
use CachedBagOStuff; use CachedBagOStuff;
use HashBagOStuff; use HashBagOStuff;
use RequestContext; use MediaWiki\MediaWikiServices;
/** /**
* BagOStuff with utility functions for MediaWiki\\Session\\* testing * BagOStuff with utility functions for MediaWiki\\Session\\* testing
@ -55,7 +55,7 @@ class TestBagOStuff extends CachedBagOStuff {
* @param array|mixed $blob Session metadata and data * @param array|mixed $blob Session metadata and data
*/ */
public function setRawSession( $id, $blob ) { 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 ); $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
} }

View file

@ -277,7 +277,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
ScopedCallback::consume( $reset ); ScopedCallback::consume( $reset );
// Now configure BotPasswordSessionProvider for further tests... // Now configure BotPasswordSessionProvider for further tests...
$mainConfig = RequestContext::getMain()->getConfig(); $mainConfig = $this->getServiceContainer()->getMainConfig();
$config = new HashConfig( [ $config = new HashConfig( [
'SessionProviders' => $mainConfig->get( 'SessionProviders' ) + [ 'SessionProviders' => $mainConfig->get( 'SessionProviders' ) + [
MediaWiki\Session\BotPasswordSessionProvider::class => [ MediaWiki\Session\BotPasswordSessionProvider::class => [
@ -288,7 +288,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
], ],
] ); ] );
$manager = new SessionManager( [ $manager = new SessionManager( [
'config' => new MultiConfig( [ $config, RequestContext::getMain()->getConfig() ] ), 'config' => new MultiConfig( [ $config, $mainConfig ] ),
'logger' => new Psr\Log\NullLogger, 'logger' => new Psr\Log\NullLogger,
'store' => new EmptyBagOStuff, 'store' => new EmptyBagOStuff,
] ); ] );

View file

@ -69,7 +69,7 @@ class ApiStructureTest extends MediaWikiIntegrationTestCase {
// Set configuration variables // Set configuration variables
$main->getContext()->setConfig( new MultiConfig( [ $main->getContext()->setConfig( new MultiConfig( [
new HashConfig( $globals ), new HashConfig( $globals ),
RequestContext::getMain()->getConfig(), $this->getServiceContainer()->getMainConfig(),
] ) ); ] ) );
foreach ( $globals as $k => $v ) { foreach ( $globals as $k => $v ) {
$this->setMwGlobals( "wg$k", $v ); $this->setMwGlobals( "wg$k", $v );