Skip to content

Commit

Permalink
Add a CreateWikiConfig service (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Feb 22, 2025
1 parent 98ac88b commit b4524a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
8 changes: 4 additions & 4 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"RequestWikiAIJob": {
"class": "Miraheze\\CreateWiki\\Jobs\\RequestWikiAIJob",
"services": [
"ConfigFactory",
"CreateWikiConfig",
"CreateWikiHookRunner",
"WikiRequestManager"
],
Expand All @@ -58,7 +58,7 @@
"RequestWikiRemoteAIJob": {
"class": "Miraheze\\CreateWiki\\Jobs\\RequestWikiRemoteAIJob",
"services": [
"ConfigFactory",
"CreateWikiConfig",
"WikiRequestManager",
"HttpRequestFactory"
],
Expand All @@ -67,7 +67,7 @@
"SetContainersAccessJob": {
"class": "Miraheze\\CreateWiki\\Jobs\\SetContainersAccessJob",
"services": [
"ConfigFactory",
"CreateWikiConfig",
"RepoGroup"
],
"needsPage": false
Expand Down Expand Up @@ -225,8 +225,8 @@
"Main": {
"class": "Miraheze\\CreateWiki\\Hooks\\Handlers\\Main",
"services": [
"ConfigFactory",
"ConnectionProvider",
"CreateWikiConfig",
"CreateWikiDatabaseUtils",
"CreateWikiDataFactory",
"RemoteWikiFactory"
Expand Down
6 changes: 1 addition & 5 deletions includes/Hooks/Handlers/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use MediaWiki\Block\Hook\GetAllBlockActionsHook;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use MediaWiki\Hook\GetMagicVariableIDsHook;
use MediaWiki\Hook\LoginFormValidErrorMessagesHook;
use MediaWiki\Hook\ParserGetVariableValueSwitchHook;
Expand All @@ -31,16 +30,13 @@ class Main implements
UserGetReservedNamesHook
{

private readonly Config $config;

public function __construct(
ConfigFactory $configFactory,
private readonly IConnectionProvider $connectionProvider,
private readonly Config $config,
private readonly CreateWikiDatabaseUtils $databaseUtils,
private readonly CreateWikiDataFactory $dataFactory,
private readonly RemoteWikiFactory $remoteWikiFactory
) {
$this->config = $configFactory->makeConfig( 'CreateWiki' );
}

/** @inheritDoc */
Expand Down
7 changes: 1 addition & 6 deletions includes/Jobs/RequestWikiAIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Job;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use MediaWiki\User\User;
use Miraheze\CreateWiki\ConfigNames;
use Miraheze\CreateWiki\CreateWikiRegexConstraint;
Expand All @@ -16,23 +15,19 @@ class RequestWikiAIJob extends Job {

public const JOB_NAME = 'RequestWikiAIJob';

private readonly Config $config;

private readonly int $id;
private readonly string $reason;

public function __construct(
array $params,
ConfigFactory $configFactory,
private readonly Config $config,
private readonly CreateWikiHookRunner $hookRunner,
private readonly WikiRequestManager $wikiRequestManager
) {
parent::__construct( self::JOB_NAME, $params );

$this->id = $params['id'];
$this->reason = $params['reason'];

$this->config = $configFactory->makeConfig( 'CreateWiki' );
}

public function run(): bool {
Expand Down
5 changes: 1 addition & 4 deletions includes/Jobs/RequestWikiRemoteAIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Exception;
use Job;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use MediaWiki\Context\RequestContext;
use MediaWiki\Http\HttpRequestFactory;
use MediaWiki\Logger\LoggerFactory;
Expand All @@ -22,7 +21,6 @@ class RequestWikiRemoteAIJob extends Job {

public const JOB_NAME = 'RequestWikiRemoteAIJob';

private readonly Config $config;
private readonly LoggerInterface $logger;
private readonly MessageLocalizer $messageLocalizer;

Expand All @@ -32,13 +30,12 @@ class RequestWikiRemoteAIJob extends Job {

public function __construct(
array $params,
ConfigFactory $configFactory,
private readonly Config $config,
private readonly WikiRequestManager $wikiRequestManager,
private readonly HttpRequestFactory $httpRequestFactory
) {
parent::__construct( self::JOB_NAME, $params );

$this->config = $configFactory->makeConfig( 'CreateWiki' );
$this->logger = LoggerFactory::getInstance( 'CreateWiki' );
$this->messageLocalizer = RequestContext::getMain();

Expand Down
6 changes: 1 addition & 5 deletions includes/Jobs/SetContainersAccessJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@

use Job;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use Miraheze\CreateWiki\ConfigNames;
use RepoGroup;

class SetContainersAccessJob extends Job {

public const JOB_NAME = 'SetContainersAccessJob';

private readonly Config $config;
private readonly bool $isPrivate;

public function __construct(
array $params,
ConfigFactory $configFactory,
private readonly Config $config,
private readonly RepoGroup $repoGroup
) {
parent::__construct( self::JOB_NAME, $params );

$this->isPrivate = $params['private'];
$this->config = $configFactory->makeConfig( 'CreateWiki' );
}

public function run(): bool {
Expand Down
16 changes: 10 additions & 6 deletions includes/ServiceWiring.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use MediaWiki\Config\Config;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Context\RequestContext;
use MediaWiki\MediaWikiServices;
Expand All @@ -13,6 +14,9 @@
use Miraheze\CreateWiki\Services\WikiRequestManager;

return [
'CreateWikiConfig' => static function ( MediaWikiServices $services ): Config {
return $services->getConfigFactory()->makeConfig( 'CreateWiki' );
},
'CreateWikiDatabaseUtils' => static function ( MediaWikiServices $services ): CreateWikiDatabaseUtils {
return new CreateWikiDatabaseUtils(
$services->getConnectionProvider()
Expand All @@ -25,7 +29,7 @@
$services->get( 'CreateWikiHookRunner' ),
new ServiceOptions(
CreateWikiDataFactory::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
)
);
},
Expand All @@ -40,7 +44,7 @@
RequestContext::getMain(),
new ServiceOptions(
CreateWikiNotificationsManager::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
),
$services->getUserFactory()
);
Expand All @@ -50,7 +54,7 @@
$services->get( 'CreateWikiDatabaseUtils' ),
new ServiceOptions(
CreateWikiRestUtils::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
)
);
},
Expand All @@ -62,7 +66,7 @@
$services->getJobQueueGroupFactory(),
new ServiceOptions(
RemoteWikiFactory::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
)
);
},
Expand All @@ -76,7 +80,7 @@
RequestContext::getMain(),
new ServiceOptions(
WikiManagerFactory::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
)
);
},
Expand All @@ -91,7 +95,7 @@
$services->get( 'WikiManagerFactory' ),
new ServiceOptions(
WikiRequestManager::CONSTRUCTOR_OPTIONS,
$services->getConfigFactory()->makeConfig( 'CreateWiki' )
$services->get( 'CreateWikiConfig' )
)
);
},
Expand Down

0 comments on commit b4524a5

Please sign in to comment.