From 6f132a088b1fd52b2e39ff7f1197e116f6c72570 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 26 Jan 2026 01:53:02 +0100 Subject: [PATCH 1/9] introduce setupFarm (WIP) --- config/MWCConfig.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/config/MWCConfig.php b/config/MWCConfig.php index 438c4dc..6300566 100644 --- a/config/MWCConfig.php +++ b/config/MWCConfig.php @@ -2,6 +2,8 @@ namespace MediaWikiConfig; +use MediaWiki\Config\SiteConfiguration; + trait MWCConfig { public function allowExternalImages(): self { @@ -87,4 +89,37 @@ public function setMaxArticleSize( int $amount, int $unit ): self { return $this->conf( 'wgMaxArticleSize', $kibibytes ); } + public function setupFarm( + array $wikis, + array $settings, + ): self { + // TODO make more customizable via options to this method + if ( defined( 'MW_DB' ) ) { + $wikiId = MW_DB; + } else { + $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; + if ( !array_key_exists( $subdomain, $wikis ) ) { + throw new \Exception( "Unknown wiki subdomain: $subdomain" ); + } else { + $wikiId = $wikis[$subdomain]; + } + } + + $siteConfiguration = new SiteConfiguration(); + $siteConfiguration->wikis = array_values( array_unique( $wikis ) ); + $this + ->conf( 'wgLocalDatabases', $siteConfiguration->wikis ) + ->conf( 'wgDBname', $wikiId ); + $siteConfiguration->suffixes = [ 'wiki' ]; + $siteConfiguration->settings = $settings; + + foreach ( $siteConfiguration->getAll( $wikiId ) as $key => $value ) { + // TODO check if this works with appending values + $this->conf( $key, $value ); + } + + return $this + ->conf( 'wgConf', $siteConfiguration ); + } + } From cb5b53e341da1907ee95471a95a0ffe2e3260de6 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 26 Jan 2026 02:17:36 +0100 Subject: [PATCH 2/9] wiki map (WIP) --- config/MWCConfig.php | 17 +++++++++++- config/farm/WikiMap.php | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 config/farm/WikiMap.php diff --git a/config/MWCConfig.php b/config/MWCConfig.php index 6300566..e9bc647 100644 --- a/config/MWCConfig.php +++ b/config/MWCConfig.php @@ -89,17 +89,26 @@ public function setMaxArticleSize( int $amount, int $unit ): self { return $this->conf( 'wgMaxArticleSize', $kibibytes ); } + // TODO move all of this to MWCFarm public function setupFarm( array $wikis, array $settings, ): self { + // TODO hacky + $port = $this->env( 'MW_DOCKER_PORT' ); + $serverVals = []; + foreach ( $wikis as $subdomain => $dbname ) { + $serverVals[$dbname] = "http://$subdomain.localhost:$port"; + } + $settings['wgServer'] = $serverVals; + // TODO make more customizable via options to this method if ( defined( 'MW_DB' ) ) { $wikiId = MW_DB; } else { $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; if ( !array_key_exists( $subdomain, $wikis ) ) { - throw new \Exception( "Unknown wiki subdomain: $subdomain" ); + $this->showWikiMap( $wikis ); } else { $wikiId = $wikis[$subdomain]; } @@ -122,4 +131,10 @@ public function setupFarm( ->conf( 'wgConf', $siteConfiguration ); } + public function showWikiMap( array $wikis ): never { + $this->conf( 'mwcWikis', $wikis ); + require_once __DIR__ . '/farm/WikiMap.php'; + die( 1 ); + } + } diff --git a/config/farm/WikiMap.php b/config/farm/WikiMap.php new file mode 100644 index 0000000..4e6d2a6 --- /dev/null +++ b/config/farm/WikiMap.php @@ -0,0 +1,57 @@ + $dbName ) { + $link = Html::element( + 'a', + [ + // TODO un-hardcode + 'href' => "http://$subdomain.localhost:$port/", + 'class' => 'button', + ], + $dbName, + ); + $wikiLinks .= Html::rawElement( 'li', [], $link ); + } + + // TODO include simplecss in repo? + $output = << + + + + + Wiki not found + + + +
+

Wiki not found

+
+
+ No wiki was found at the current subdomain. +

Available wikis

+
    $wikiLinks
+
+
+

+ Powered by mw-dev-kit (GitHub) +

+
+ + + EOF; + header( 'Content-length: ' . strlen( $output ) ); + http_response_code( 404 ); + echo $output; + die( 1 ); +} else { + echo "The wiki database '{$this->getConf('wgDBName')}' was not found." . PHP_EOL; +} From d0c7663e7c777f9ffe3372b009ef0e0469c38096 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Thu, 29 Jan 2026 15:10:51 +0100 Subject: [PATCH 3/9] temp fixes --- config/MWCConfig.php | 5 ++++- config/farm/{WikiMap.php => NotFound.php} | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) rename config/farm/{WikiMap.php => NotFound.php} (87%) diff --git a/config/MWCConfig.php b/config/MWCConfig.php index e9bc647..c6c3676 100644 --- a/config/MWCConfig.php +++ b/config/MWCConfig.php @@ -105,6 +105,9 @@ public function setupFarm( // TODO make more customizable via options to this method if ( defined( 'MW_DB' ) ) { $wikiId = MW_DB; + } elseif ( MW_ENTRY_POINT === 'cli' ) { + // TODO + $wikiId = 'mainwiki'; } else { $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; if ( !array_key_exists( $subdomain, $wikis ) ) { @@ -133,7 +136,7 @@ public function setupFarm( public function showWikiMap( array $wikis ): never { $this->conf( 'mwcWikis', $wikis ); - require_once __DIR__ . '/farm/WikiMap.php'; + require_once __DIR__ . '/farm/NotFound.php'; die( 1 ); } diff --git a/config/farm/WikiMap.php b/config/farm/NotFound.php similarity index 87% rename from config/farm/WikiMap.php rename to config/farm/NotFound.php index 4e6d2a6..e9553e2 100644 --- a/config/farm/WikiMap.php +++ b/config/farm/NotFound.php @@ -8,12 +8,13 @@ $wikiLinks = ''; // TODO bad $port = getenv( 'MW_DOCKER_PORT' ); + $path = parse_url( $_SERVER['REQUEST_URI'] ?? '|', PHP_URL_PATH ) ?? ''; foreach ( $mwcWikis as $subdomain => $dbName ) { $link = Html::element( 'a', [ // TODO un-hardcode - 'href' => "http://$subdomain.localhost:$port/", + 'href' => "http://$subdomain.localhost:$port$path", 'class' => 'button', ], $dbName, @@ -42,7 +43,7 @@

- Powered by mw-dev-kit (GitHub) + Powered by mw-dev-kit (GitHub)

From bdba131229eee1f84a24f5f7788f17f55e5434f5 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:08:31 +0100 Subject: [PATCH 4/9] Move farm logic --- config/Defaults.php | 1 + config/Farm/MWCFarm.php | 69 ++++++++++++++++++++++++++++++ config/{farm => Farm}/NotFound.php | 8 ++-- config/MWCConfig.php | 56 +++--------------------- 4 files changed, 81 insertions(+), 53 deletions(-) create mode 100644 config/Farm/MWCFarm.php rename config/{farm => Farm}/NotFound.php (90%) diff --git a/config/Defaults.php b/config/Defaults.php index 176945b..d9d1e8e 100644 --- a/config/Defaults.php +++ b/config/Defaults.php @@ -109,6 +109,7 @@ # Load other configuration +require_once 'Farm/MWCFarm.php'; require_once 'MWCConfig.php'; require_once 'MWCExtensions.php'; require_once 'MWCFunctions.php'; diff --git a/config/Farm/MWCFarm.php b/config/Farm/MWCFarm.php new file mode 100644 index 0000000..90fb3b3 --- /dev/null +++ b/config/Farm/MWCFarm.php @@ -0,0 +1,69 @@ +env( 'MW_DOCKER_PORT' ); + $serverVals = []; + foreach ( $this->wikis as $subdomain => $dbname ) { + $serverVals[$dbname] = "http://$subdomain.localhost:$port"; + } + $settings['wgServer'] = $serverVals; + + // TODO remove + $mwc->conf( 'mwcWikis', $this->wikis ); + + // TODO make more customizable via options to this method + if ( defined( 'MW_DB' ) ) { + $wikiId = MW_DB; + } elseif ( MW_ENTRY_POINT === 'cli' ) { + // TODO + $wikiId = 'mainwiki'; + } else { + $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; + if ( !array_key_exists( $subdomain, $this->wikis ) ) { + $this->showWikiMap(); + } else { + $wikiId = $this->wikis[$subdomain]; + } + } + + $siteConfiguration = new SiteConfiguration(); + $siteConfiguration->wikis = array_values( array_unique( $this->wikis ) ); + $mwc + ->conf( 'wgLocalDatabases', $siteConfiguration->wikis ) + ->conf( 'wgDBname', $wikiId ); + $siteConfiguration->suffixes = [ 'wiki' ]; + $siteConfiguration->settings = $settings; + + foreach ( $siteConfiguration->getAll( $wikiId ) as $key => $value ) { + $mwc->conf( $key, $value ); + } + + $mwc->conf( 'wgConf', $siteConfiguration ); + } + + private function showWikiMap(): never { + require_once __DIR__ . '/NotFound.php'; + die( 1 ); + } + + /** + * @return array + */ + public function getWikis(): array { + return $this->wikis; + } + +} diff --git a/config/farm/NotFound.php b/config/Farm/NotFound.php similarity index 90% rename from config/farm/NotFound.php rename to config/Farm/NotFound.php index e9553e2..f053223 100644 --- a/config/farm/NotFound.php +++ b/config/Farm/NotFound.php @@ -1,15 +1,17 @@ $dbName ) { + foreach ( $mwcFarm->getWikis() as $subdomain => $dbName ) { $link = Html::element( 'a', [ diff --git a/config/MWCConfig.php b/config/MWCConfig.php index c6c3676..502fc3b 100644 --- a/config/MWCConfig.php +++ b/config/MWCConfig.php @@ -2,7 +2,7 @@ namespace MediaWikiConfig; -use MediaWiki\Config\SiteConfiguration; +use MediaWikiConfig\Farm\MWCFarm; trait MWCConfig { @@ -89,55 +89,11 @@ public function setMaxArticleSize( int $amount, int $unit ): self { return $this->conf( 'wgMaxArticleSize', $kibibytes ); } - // TODO move all of this to MWCFarm - public function setupFarm( - array $wikis, - array $settings, - ): self { - // TODO hacky - $port = $this->env( 'MW_DOCKER_PORT' ); - $serverVals = []; - foreach ( $wikis as $subdomain => $dbname ) { - $serverVals[$dbname] = "http://$subdomain.localhost:$port"; - } - $settings['wgServer'] = $serverVals; - - // TODO make more customizable via options to this method - if ( defined( 'MW_DB' ) ) { - $wikiId = MW_DB; - } elseif ( MW_ENTRY_POINT === 'cli' ) { - // TODO - $wikiId = 'mainwiki'; - } else { - $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; - if ( !array_key_exists( $subdomain, $wikis ) ) { - $this->showWikiMap( $wikis ); - } else { - $wikiId = $wikis[$subdomain]; - } - } - - $siteConfiguration = new SiteConfiguration(); - $siteConfiguration->wikis = array_values( array_unique( $wikis ) ); - $this - ->conf( 'wgLocalDatabases', $siteConfiguration->wikis ) - ->conf( 'wgDBname', $wikiId ); - $siteConfiguration->suffixes = [ 'wiki' ]; - $siteConfiguration->settings = $settings; - - foreach ( $siteConfiguration->getAll( $wikiId ) as $key => $value ) { - // TODO check if this works with appending values - $this->conf( $key, $value ); - } - - return $this - ->conf( 'wgConf', $siteConfiguration ); - } - - public function showWikiMap( array $wikis ): never { - $this->conf( 'mwcWikis', $wikis ); - require_once __DIR__ . '/farm/NotFound.php'; - die( 1 ); + public function setupFarm( MWCFarm $farm ): self { + global $mwcFarm; + $mwcFarm = $farm; + $farm->apply( $this ); + return $this; } } From ddab1b366ac882e948233db002f9ba955790c4a1 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:09:04 +0100 Subject: [PATCH 5/9] Fix --- config/Farm/MWCFarm.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/Farm/MWCFarm.php b/config/Farm/MWCFarm.php index 90fb3b3..44c185e 100644 --- a/config/Farm/MWCFarm.php +++ b/config/Farm/MWCFarm.php @@ -9,7 +9,7 @@ class MWCFarm { public function __construct( private readonly array $wikis, - private readonly array $settings, + private array $settings, ) { } @@ -19,7 +19,7 @@ public function apply( MediaWikiConfig $mwc ): void { foreach ( $this->wikis as $subdomain => $dbname ) { $serverVals[$dbname] = "http://$subdomain.localhost:$port"; } - $settings['wgServer'] = $serverVals; + $this->settings['wgServer'] = $serverVals; // TODO remove $mwc->conf( 'mwcWikis', $this->wikis ); @@ -45,7 +45,7 @@ public function apply( MediaWikiConfig $mwc ): void { ->conf( 'wgLocalDatabases', $siteConfiguration->wikis ) ->conf( 'wgDBname', $wikiId ); $siteConfiguration->suffixes = [ 'wiki' ]; - $siteConfiguration->settings = $settings; + $siteConfiguration->settings = $this->settings; foreach ( $siteConfiguration->getAll( $wikiId ) as $key => $value ) { $mwc->conf( $key, $value ); From 28bc27c83242645cd5a162f497f82c7d4a28cf3a Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:09:37 +0100 Subject: [PATCH 6/9] -mwcWikis --- config/Farm/MWCFarm.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/Farm/MWCFarm.php b/config/Farm/MWCFarm.php index 44c185e..d800c1b 100644 --- a/config/Farm/MWCFarm.php +++ b/config/Farm/MWCFarm.php @@ -21,9 +21,6 @@ public function apply( MediaWikiConfig $mwc ): void { } $this->settings['wgServer'] = $serverVals; - // TODO remove - $mwc->conf( 'mwcWikis', $this->wikis ); - // TODO make more customizable via options to this method if ( defined( 'MW_DB' ) ) { $wikiId = MW_DB; From 62b1e02c42f1d2b4900d0a3fc6e01c5b12b75da2 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:11:08 +0100 Subject: [PATCH 7/9] Allow configuring the default wiki --- config/Farm/MWCFarm.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/Farm/MWCFarm.php b/config/Farm/MWCFarm.php index d800c1b..565095d 100644 --- a/config/Farm/MWCFarm.php +++ b/config/Farm/MWCFarm.php @@ -7,9 +7,15 @@ class MWCFarm { + /** + * @param array $wikis + * @param array $settings + * @param string $defaultWiki The wiki that will be used for maintenance scripts by default + */ public function __construct( private readonly array $wikis, private array $settings, + private readonly string $defaultWiki, ) { } @@ -21,12 +27,10 @@ public function apply( MediaWikiConfig $mwc ): void { } $this->settings['wgServer'] = $serverVals; - // TODO make more customizable via options to this method if ( defined( 'MW_DB' ) ) { $wikiId = MW_DB; } elseif ( MW_ENTRY_POINT === 'cli' ) { - // TODO - $wikiId = 'mainwiki'; + $wikiId = $this->defaultWiki; } else { $subdomain = explode( '.', $_SERVER['SERVER_NAME'] )[0]; if ( !array_key_exists( $subdomain, $this->wikis ) ) { From c211c027e4bd651ebd0a65ca82abaeef86d4d242 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:13:27 +0100 Subject: [PATCH 8/9] Use wg prefix --- config/Farm/NotFound.php | 6 +++--- config/MWCConfig.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/Farm/NotFound.php b/config/Farm/NotFound.php index f053223..2ad92b3 100644 --- a/config/Farm/NotFound.php +++ b/config/Farm/NotFound.php @@ -3,15 +3,15 @@ use MediaWiki\Html\Html; use MediaWikiConfig\Farm\MWCFarm; -global $mwcFarm; -/** @var MWCFarm $mwcFarm */ +global $wgMwcFarm; +/** @var MWCFarm $wgMwcFarm */ if ( MW_ENTRY_POINT !== 'cli' ) { $wikiLinks = ''; // TODO bad $port = getenv( 'MW_DOCKER_PORT' ); $path = parse_url( $_SERVER['REQUEST_URI'] ?? '|', PHP_URL_PATH ) ?? ''; - foreach ( $mwcFarm->getWikis() as $subdomain => $dbName ) { + foreach ( $wgMwcFarm->getWikis() as $subdomain => $dbName ) { $link = Html::element( 'a', [ diff --git a/config/MWCConfig.php b/config/MWCConfig.php index 502fc3b..133eb5b 100644 --- a/config/MWCConfig.php +++ b/config/MWCConfig.php @@ -90,8 +90,8 @@ public function setMaxArticleSize( int $amount, int $unit ): self { } public function setupFarm( MWCFarm $farm ): self { - global $mwcFarm; - $mwcFarm = $farm; + global $wgMwcFarm; + $wgMwcFarm = $farm; $farm->apply( $this ); return $this; } From dca72eeeaeed0cab9891ebfeb937ac7cf9dce082 Mon Sep 17 00:00:00 2001 From: SomeRandomDeveloper Date: Mon, 16 Feb 2026 00:14:22 +0100 Subject: [PATCH 9/9] fix --- config/Farm/NotFound.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/Farm/NotFound.php b/config/Farm/NotFound.php index 2ad92b3..d843448 100644 --- a/config/Farm/NotFound.php +++ b/config/Farm/NotFound.php @@ -45,7 +45,8 @@