Seb35 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/361302 )
Change subject: Execute scripts when wikis are path-based ...................................................................... Execute scripts when wikis are path-based Change-Id: Ie54c52d0a57bf0b75fa8566dbcf6913eb83ad15e --- M src/MediaWikiFarm.php M src/MediaWikiFarmScript.php M tests/phpunit/MediaWikiFarmScriptTest.php 3 files changed, 26 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm refs/changes/02/361302/1 diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index f269008..a223352 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -271,7 +271,9 @@ $exists = $wgMediaWikiFarm->checkExistence(); # Compile configuration - $wgMediaWikiFarm->compileConfiguration(); + if( $exists ) { + $wgMediaWikiFarm->compileConfiguration(); + } } catch( Exception $exception ) { @@ -720,6 +722,9 @@ # Sanitise host and path $host = preg_replace( '/[^a-zA-Z0-9\\._-]/', '', $host ); $path = '/' . substr( $path, 1 ); + if( $path === '/' ) { + $path = ''; + } # Set parameters $this->farmDir = dirname( dirname( __FILE__ ) ); @@ -742,9 +747,9 @@ # Shortcut loading // @codingStandardsIgnoreLine - if( $this->cacheDir && ( $result = $this->readFile( $host . '.php', $this->cacheDir . '/wikis', false ) ) ) { + if( $this->cacheDir && ( $result = $this->readFile( $host . ( $path ? $path : '' ) . '.php', $this->cacheDir . '/wikis', false ) ) ) { $fresh = true; - $myfreshness = filemtime( $this->cacheDir . '/wikis/' . $host . '.php' ); + $myfreshness = filemtime( $this->cacheDir . '/wikis/' . $host . ( $path ? $path : '' ) . '.php' ); foreach( $result['$CORECONFIG'] as $coreconfig ) { if( !is_file( $this->configDir . '/' . $coreconfig ) || filemtime( $this->configDir . '/' . $coreconfig ) > $myfreshness ) { @@ -759,12 +764,12 @@ $this->variables = $result; return; } else { - unlink( $this->cacheDir . '/wikis/' . $host . '.php' ); - if( is_file( $this->cacheDir . '/LocalSettings/' . $host . '.php' ) ) { - unlink( $this->cacheDir . '/LocalSettings/' . $host . '.php' ); + unlink( $this->cacheDir . '/wikis/' . $host . ( $path ? $path : '' ) . '.php' ); + if( is_file( $this->cacheDir . '/LocalSettings/' . $host . ( $path ? $path : '' ) . '.php' ) ) { + unlink( $this->cacheDir . '/LocalSettings/' . $host . ( $path ? $path : '' ) . '.php' ); } - if( is_file( $this->cacheDir . '/composer/' . $host . '.php' ) ) { - unlink( $this->cacheDir . '/composer/' . $host . '.php' ); + if( is_file( $this->cacheDir . '/composer/' . $host . ( $path ? $path : '' ) . '.php' ) ) { + unlink( $this->cacheDir . '/composer/' . $host . ( $path ? $path : '' ) . '.php' ); } } } diff --git a/src/MediaWikiFarmScript.php b/src/MediaWikiFarmScript.php index 3ec6e88..1262fe8 100644 --- a/src/MediaWikiFarmScript.php +++ b/src/MediaWikiFarmScript.php @@ -80,10 +80,17 @@ # Get wiki $this->host = $this->getParam( 'wiki' ); + $this->path = ''; + $host = $this->host; if( is_null( $this->host ) ) { $this->usage(); $this->status = 4; return false; + } + $posSlash = strpos( $this->host, '/' ); + if( $posSlash !== false ) { + $this->path = substr( $this->host, $posSlash ); + $this->host = substr( $this->host, 0, $posSlash ); } # Get script @@ -104,7 +111,7 @@ # Initialise the requested version - $code = MediaWikiFarm::load( $this->script, $this->host ); + $code = MediaWikiFarm::load( $this->script, $this->host, $this->path ); if( $code == 404 ) { $this->status = 1; return false; @@ -128,7 +135,7 @@ $version = $wgMediaWikiFarm->getVariable( '$VERSION' ) ? $wgMediaWikiFarm->getVariable( '$VERSION' ) : 'current'; $code = $wgMediaWikiFarm->getVariable( '$CODE' ); echo " -Wiki: {$this->host} (wikiID: $wikiID; suffix: $suffix) +Wiki: $host (wikiID: $wikiID; suffix: $suffix) Version: $version: $code Script: {$this->script} diff --git a/tests/phpunit/MediaWikiFarmScriptTest.php b/tests/phpunit/MediaWikiFarmScriptTest.php index 72ab42c..50ea26e 100644 --- a/tests/phpunit/MediaWikiFarmScriptTest.php +++ b/tests/phpunit/MediaWikiFarmScriptTest.php @@ -503,7 +503,7 @@ $this->expectOutputString( <<<OUTPUT -Wiki: a.testfarm-monoversion.example.org (wikiID: atestfarm; suffix: testfarm) +Wiki: testfarm-multiversion-subdirectories.example.org/a (wikiID: atestfarm; suffix: testfarm) Version: current: $IP Script: maintenance/showJobs.php @@ -511,12 +511,13 @@ OUTPUT ); - $wgMediaWikiFarmScript = new MediaWikiFarmScript( 3, array( self::$mwscriptPath, '--wiki=a.testfarm-monoversion.example.org', 'showJobs' ) ); + $wgMediaWikiFarmScript = new MediaWikiFarmScript( 3, array( self::$mwscriptPath, '--wiki=testfarm-multiversion-subdirectories.example.org/a', 'showJobs' ) ); $wgMediaWikiFarmScript->main(); $this->assertEquals( 0, $wgMediaWikiFarmScript->status ); - $this->assertEquals( 'a.testfarm-monoversion.example.org', $wgMediaWikiFarmScript->host ); + $this->assertEquals( 'testfarm-multiversion-subdirectories.example.org', $wgMediaWikiFarmScript->host ); + $this->assertEquals( '/a', $wgMediaWikiFarmScript->path ); $this->assertEquals( 'maintenance/showJobs.php', $wgMediaWikiFarmScript->script ); $this->assertEquals( 1, $wgMediaWikiFarmScript->argc ); $this->assertEquals( array( 'maintenance/showJobs.php' ), $wgMediaWikiFarmScript->argv ); -- To view, visit https://gerrit.wikimedia.org/r/361302 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie54c52d0a57bf0b75fa8566dbcf6913eb83ad15e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <se...@seb35.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits