Skip to content

Commit

Permalink
Use CreateWikiDataFactory (T12718) (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Oct 8, 2024
1 parent 1340cd3 commit 2cec896
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 101 deletions.
13 changes: 6 additions & 7 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
"SpecialPages": {
"DeletedWikis": "Miraheze\\ManageWiki\\Specials\\SpecialDeletedWikis",
"ManageWiki": "Miraheze\\ManageWiki\\Specials\\SpecialManageWiki",
"ManageWikiDefaultPermissions": "Miraheze\\ManageWiki\\Specials\\SpecialManageWikiDefaultPermissions"
"ManageWikiDefaultPermissions": {
"class": "Miraheze\\ManageWiki\\Specials\\SpecialManageWikiDefaultPermissions",
"services": [
"CreateWikiDataFactory"
]
}
},
"JobClasses": {
"MWScriptJob": "Miraheze\\ManageWiki\\Jobs\\MWScriptJob",
Expand Down Expand Up @@ -121,12 +126,6 @@
"CreateWikiDataFactoryBuilder": [
"Miraheze\\ManageWiki\\Hooks::onCreateWikiDataFactoryBuilder"
],
"CreateWikiJsonBuilder": [
"Miraheze\\ManageWiki\\Hooks::onCreateWikiDataFactoryBuilder"
],
"CreateWikiPhpBuilder": [
"Miraheze\\ManageWiki\\Hooks::onCreateWikiDataFactoryBuilder"
],
"CreateWikiStatePrivate": [
"Miraheze\\ManageWiki\\Hooks::onCreateWikiStatePrivate"
],
Expand Down
15 changes: 5 additions & 10 deletions includes/Helpers/ManageWikiExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Miraheze\CreateWiki\RemoteWiki;
use Wikimedia\Rdbms\DBConnRef;

Expand Down Expand Up @@ -141,7 +139,6 @@ public function hasChanges(): bool {
*/
public function commit() {
$createWikiHookRunner = MediaWikiServices::getInstance()->get( 'CreateWikiHookRunner' );

$remoteWiki = new RemoteWiki( $this->wiki, $createWikiHookRunner );

foreach ( $this->liveExts as $name => $extConfig ) {
Expand Down Expand Up @@ -196,13 +193,11 @@ public function commit() {
}

$this->write();
if ( $this->config->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp( $this->wiki, $createWikiHookRunner );
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson( $this->wiki, $createWikiHookRunner );
$cWJ->resetWiki();
}

$dataFactory = MediaWikiServices::getInstance()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->wiki );
$data->resetWikiData( isNewChanges: true );

$this->committed = true;

$this->logParams = [
Expand Down
15 changes: 4 additions & 11 deletions includes/Helpers/ManageWikiNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use MediaWiki\SpecialPage\SpecialPage;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Miraheze\ManageWiki\Jobs\NamespaceMigrationJob;
use Wikimedia\Rdbms\DBConnRef;

Expand Down Expand Up @@ -243,21 +241,16 @@ public function commit( bool $runNamespaceMigrationJob = true ) {
}
}

if ( $this->wiki != 'default' && $runNamespaceMigrationJob ) {
if ( $this->wiki !== 'default' && $runNamespaceMigrationJob ) {
$job = new NamespaceMigrationJob( SpecialPage::getTitleFor( 'ManageWiki' ), $jobParams );
MediaWikiServices::getInstance()->getJobQueueGroupFactory()->makeJobQueueGroup()->push( $job );
}
}

if ( $this->wiki !== 'default' ) {
$createWikiHookRunner = MediaWikiServices::getInstance()->get( 'CreateWikiHookRunner' );
if ( $this->config->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp( $this->wiki, $createWikiHookRunner );
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson( $this->wiki, $createWikiHookRunner );
$cWJ->resetWiki();
}
$dataFactory = MediaWikiServices::getInstance()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->wiki );
$data->resetWikiData( isNewChanges: true );
}

$this->committed = true;
Expand Down
14 changes: 4 additions & 10 deletions includes/Helpers/ManageWikiPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\User;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Wikimedia\Rdbms\DBConnRef;

/**
Expand Down Expand Up @@ -214,15 +212,11 @@ public function commit() {
}

if ( $this->wiki !== 'default' ) {
$createWikiHookRunner = MediaWikiServices::getInstance()->get( 'CreateWikiHookRunner' );
if ( $this->config->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp( $this->wiki, $createWikiHookRunner );
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson( $this->wiki, $createWikiHookRunner );
$cWJ->resetWiki();
}
$dataFactory = MediaWikiServices::getInstance()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->wiki );
$data->resetWikiData( isNewChanges: true );
}

$this->committed = true;
}

Expand Down
14 changes: 4 additions & 10 deletions includes/Helpers/ManageWikiSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use MediaWiki\Config\Config;
use MediaWiki\MediaWikiServices;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Wikimedia\Rdbms\DBConnRef;

/**
Expand Down Expand Up @@ -166,14 +164,10 @@ public function commit() {
ManageWikiInstaller::process( $this->wiki, [ 'mwscript' => $this->scripts ] );
}

$createWikiHookRunner = MediaWikiServices::getInstance()->get( 'CreateWikiHookRunner' );
if ( $this->config->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp( $this->wiki, $createWikiHookRunner );
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson( $this->wiki, $createWikiHookRunner );
$cWJ->resetWiki();
}
$dataFactory = MediaWikiServices::getInstance()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->wiki );
$data->resetWikiData( isNewChanges: true );

$this->committed = true;

$this->logParams = [
Expand Down
33 changes: 10 additions & 23 deletions includes/Specials/SpecialManageWikiDefaultPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@
use MediaWiki\HTMLForm\HTMLForm;
use MediaWiki\MediaWikiServices;
use MediaWiki\SpecialPage\SpecialPage;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Miraheze\CreateWiki\Hooks\CreateWikiHookRunner;
use Miraheze\CreateWiki\RemoteWiki;
use Miraheze\CreateWiki\Services\CreateWikiDataFactory;
use Miraheze\ManageWiki\FormFactory\ManageWikiFormFactory;
use Miraheze\ManageWiki\Helpers\ManageWikiPermissions;
use Miraheze\ManageWiki\Hooks;
use Miraheze\ManageWiki\ManageWiki;

class SpecialManageWikiDefaultPermissions extends SpecialPage {

/** @var Config */
private $config;
private Config $config;
private CreateWikiDataFactory $dataFactory;
private CreateWikiHookRunner $createWikiHookRunner;

/** @var CreateWikiHookRunner */
private $createWikiHookRunner;

public function __construct() {
public function __construct( CreateWikiDataFactory $dataFactory ) {
parent::__construct( 'ManageWikiDefaultPermissions' );

$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'managewiki' );
$this->createWikiHookRunner = MediaWikiServices::getInstance()->get( 'CreateWikiHookRunner' );
$this->dataFactory = $dataFactory;
}

public function canModify() {
Expand Down Expand Up @@ -224,19 +222,8 @@ public function onSubmitSettingsResetForm( $formData ) {
);

// Reset the cache or else the changes won't work
if ( $this->config->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp(
$this->config->get( 'DBname' ),
$this->createWikiHookRunner
);
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson(
$this->config->get( 'DBname' ),
$this->createWikiHookRunner
);
$cWJ->resetWiki();
}
$data = $this->dataFactory->newInstance( $this->config->get( 'DBname' ) );
$data->resetWikiData( isNewChanges: true );

$logEntry = new ManualLogEntry( 'managewiki', 'settings-reset' );
$logEntry->setPerformer( $this->getContext()->getUser() );
Expand Down Expand Up @@ -267,8 +254,8 @@ public function onSubmitCacheResetForm( $formData ) {
->getMaintenanceConnectionRef( DB_PRIMARY, [], $this->config->get( 'CreateWikiDatabase' ) );

// Reset the cache or else the changes won't work
$cWJ = new CreateWikiJson( $this->config->get( 'DBname' ), $this->createWikiHookRunner );
$cWJ->resetWiki();
$data = $this->dataFactory->newInstance( $this->config->get( 'DBname' ) );
$data->resetWikiData( isNewChanges: true );

$logEntry = new ManualLogEntry( 'managewiki', 'cache-reset' );
$logEntry->setPerformer( $this->getContext()->getUser() );
Expand Down
18 changes: 3 additions & 15 deletions maintenance/populateGroupPermissionsWithDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

use Maintenance;
use MediaWiki\MainConfigNames;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Miraheze\ManageWiki\Helpers\ManageWikiPermissions;

class PopulateGroupPermissionsWithDefaults extends Maintenance {
Expand Down Expand Up @@ -69,19 +67,9 @@ public function execute() {

$mwPermissions->commit();

if ( $this->getConfig()->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp(
$this->getConfig()->get( MainConfigNames::DBname ),
$this->getServiceContainer()->get( 'CreateWikiHookRunner' )
);
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson(
$this->getConfig()->get( MainConfigNames::DBname ),
$this->getServiceContainer()->get( 'CreateWikiHookRunner' )
);
$cWJ->resetWiki();
}
$dataFactory = $this->getServiceContainer()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->getConfig()->get( MainConfigNames::DBname ) );
$data->resetWikiData( isNewChanges: true );
}
}
}
Expand Down
18 changes: 3 additions & 15 deletions maintenance/populateNamespacesWithDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

use Maintenance;
use MediaWiki\MainConfigNames;
use Miraheze\CreateWiki\CreateWikiJson;
use Miraheze\CreateWiki\CreateWikiPhp;
use Miraheze\ManageWiki\Helpers\ManageWikiNamespaces;

class PopulateNamespacesWithDefaults extends Maintenance {
Expand Down Expand Up @@ -57,19 +55,9 @@ public function execute() {
$mwNamespaces->commit();
}

if ( $this->getConfig()->get( 'CreateWikiUsePhpCache' ) ) {
$cWP = new CreateWikiPhp(
$this->getConfig()->get( MainConfigNames::DBname ),
$this->getServiceContainer()->get( 'CreateWikiHookRunner' )
);
$cWP->resetWiki();
} else {
$cWJ = new CreateWikiJson(
$this->getConfig()->get( MainConfigNames::DBname ),
$this->getServiceContainer()->get( 'CreateWikiHookRunner' )
);
$cWJ->resetWiki();
}
$dataFactory = $this->getServiceContainer()->get( 'CreateWikiDataFactory' );
$data = $dataFactory->newInstance( $this->getConfig()->get( MainConfigNames::DBname ) );
$data->resetWikiData( isNewChanges: true );
}
}
}
Expand Down

0 comments on commit 2cec896

Please sign in to comment.