Seb35 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344881 )

Change subject: [WIP] Support for farms given by subdirectories in addition of 
subdomains
......................................................................

[WIP] Support for farms given by subdirectories in addition of subdomains

In the config file farms.yml one can now use subdirectories; subdirectories 
should
be caught in a variable to retrieve the wiki name exactly as in subdomains;
possibly the server regex can mix subdomains and subdirectories.

Bug: T161413
Change-Id: Ic906b84315150abc8fff90e6db23d47b27707902
---
M docs/configuration.rst
M docs/farms-schema.json
M docs/versions-schema.json
M src/MediaWikiFarm.php
M tests/phpunit/ConfigurationTest.php
M tests/phpunit/ConstructionTest.php
M tests/phpunit/InstallationIndependantTest.php
M tests/phpunit/LoadingTest.php
M tests/phpunit/LoggingTest.php
M tests/phpunit/MonoversionInstallationTest.php
M tests/phpunit/MultiversionInstallationTest.php
M tests/phpunit/data/config/farms.php
12 files changed, 312 insertions(+), 48 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm 
refs/changes/81/344881/1

diff --git a/docs/configuration.rst b/docs/configuration.rst
index 2b34109..3974618 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -59,7 +59,7 @@
 Server
 ------
 
-The most important subkey is 'server': it is a regular expression of the 
server name/domain name. There should be only one regex, which matchs a given 
server name. It is recommanded to use named patterns in the regex to capture 
parts of the server name to construct the wikiID and suffix.
+The most important subkey is 'server': it is a regular expression of the 
server name/domain name and possibly of the subdirectory (or even multiple 
subdirectories). There should be only one regex, which matchs a given server 
name. It is recommanded to use named patterns in the regex to capture parts of 
the server name to construct the wikiID and suffix.
 
 Redirect
 --------
diff --git a/docs/farms-schema.json b/docs/farms-schema.json
index ab0882f..1967196 100644
--- a/docs/farms-schema.json
+++ b/docs/farms-schema.json
@@ -19,8 +19,8 @@
                                        "properties": {
                                                "server": {
                                                        "type": "string",
-                                                       "description": "Regular 
expression of the server names.",
-                                                       "pattern": 
"^[a-zA-Z0-9\\[\\]\\(\\)\\\\<>.*?+_|-]+$"
+                                                       "description": "Regular 
expression of the server name and subdirectory.",
+                                                       "pattern": 
"^[a-zA-Z0-9\\[\\]\\(\\)\\\\/<>.*?+_|-]+$"
                                                },
                                                "variables": {
                                                        "type": "array",
@@ -119,8 +119,8 @@
                                        "properties": {
                                                "server": {
                                                        "type": "string",
-                                                       "description": "Regular 
expression of the server name.",
-                                                       "pattern": 
"^[a-zA-Z0-9\\[\\]\\(\\)\\\\<>.*?+_|-]+$"
+                                                       "description": "Regular 
expression of the server name and subdirectory.",
+                                                       "pattern": 
"^[a-zA-Z0-9\\[\\]\\(\\)\\\\/<>.*?+_|-]+$"
                                                },
                                                "redirect": {
                                                        "type": "string",
diff --git a/docs/versions-schema.json b/docs/versions-schema.json
index 0c382d5..d0d7d52 100644
--- a/docs/versions-schema.json
+++ b/docs/versions-schema.json
@@ -21,7 +21,7 @@
                                                "$SERVER": {
                                                        "type": "string",
                                                        "description": "Server 
host (must be the same as the first key in the hierarchy).",
-                                                       "pattern": 
"^[a-zA-Z0-9\\._-]+$"
+                                                       "pattern": 
"^[a-zA-Z0-9\\./_-]+$"
                                                },
                                                "$SUFFIX": {
                                                        "type": "string",
diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php
index 58a1723..731f70e 100644
--- a/src/MediaWikiFarm.php
+++ b/src/MediaWikiFarm.php
@@ -234,18 +234,19 @@
         *
         * @param string $entryPoint Name of the entry point, e.g. 'index.php', 
'load.php'…
         * @param string|null $host Host name (string) or null to use the 
global variables HTTP_HOST or SERVER_NAME.
+        * @param string|null $path Path (string) or null to use the global 
variables REQUEST_URI.
         * @param array $state Parameters, see object property $state.
         * @param array $environment Environment which determines a given 
configuration.
         * @return string $entryPoint Identical entry point as passed in input.
         */
-       static function load( $entryPoint = '', $host = null, $state = array(), 
$environment = array() ) {
+       static function load( $entryPoint = '', $host = null, $path = null, 
$state = array(), $environment = array() ) {
 
                global $wgMediaWikiFarm;
                global $wgMediaWikiFarmConfigDir, $wgMediaWikiFarmCodeDir, 
$wgMediaWikiFarmCacheDir, $wgMediaWikiFarmSyslog;
 
                try {
                        # Initialise object
-                       $wgMediaWikiFarm = new MediaWikiFarm( $host,
+                       $wgMediaWikiFarm = new MediaWikiFarm( $host, $path,
                                $wgMediaWikiFarmConfigDir, 
$wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir,
                                array_merge( $state, array( 'EntryPoint' => 
$entryPoint ) ),
                                $environment
@@ -622,6 +623,7 @@
         * @internal
         *
         * @param string|null $host Requested host.
+        * @param string|null $host Requested path.
         * @param string $configDir Configuration directory.
         * @param string|null $codeDir Code directory; if null, the current 
MediaWiki installation is used.
         * @param string|false $cacheDir Cache directory; if false, the cache 
is disabled.
@@ -631,7 +633,7 @@
         * @throws MWFConfigurationException When no farms.yml/php/json is 
found.
         * @throws InvalidArgumentException When wrong input arguments are 
passed.
         */
-       function __construct( $host, $configDir, $codeDir = null, $cacheDir = 
false, $state = array(), $environment = array() ) {
+       function __construct( $host, $path, $configDir, $codeDir = null, 
$cacheDir = false, $state = array(), $environment = array() ) {
 
                # Default value for host
                # Warning: do not use $GLOBALS['_SERVER']['HTTP_HOST']: bug 
with PHP7: it is not initialised in early times of a script
@@ -639,11 +641,20 @@
                #            and it will be checked against available hosts in 
constructor
                if( is_null( $host ) ) {
                        if( array_key_exists( 'HTTP_HOST', $_SERVER ) && 
$_SERVER['HTTP_HOST'] ) {
-                               $host = $_SERVER['HTTP_HOST'];
+                               $host = (string) $_SERVER['HTTP_HOST'];
                        } elseif( array_key_exists( 'SERVER_NAME', $_SERVER ) 
&& $_SERVER['SERVER_NAME'] ) {
-                               $host = $_SERVER['SERVER_NAME'];
+                               $host = (string) $_SERVER['SERVER_NAME'];
                        } else {
                                throw new InvalidArgumentException( 'Undefined 
host' );
+                       }
+               }
+
+               # Default value for path
+               if( !is_string( $path ) ) {
+                       if( array_key_exists( 'REQUEST_URI', $_SERVER ) ) {
+                               $path = (string) $_SERVER['REQUEST_URI'];
+                       } else {
+                               $path = '';
                        }
                }
 
@@ -678,8 +689,9 @@
                        }
                }
 
-               # Sanitise host
+               # Sanitise host and path
                $host = preg_replace( '/[^a-zA-Z0-9\\._-]/', '', $host );
+               $path = '/' . substr( $path, 1 );
 
                # Set parameters
                $this->farmDir = dirname( dirname( __FILE__ ) );
@@ -717,7 +729,7 @@
                }
 
                # Now select the right farm amoung all farms
-               $result = $this->selectFarm( $host, false, 5 );
+               $result = $this->selectFarm( $host . $path, false, 5 );
 
                # Success
                if( $result['farm'] ) {
@@ -733,9 +745,9 @@
                        throw new MWFConfigurationException( 'No configuration 
file found' );
                }
                elseif( $result['redirects'] <= 0 ) {
-                       throw new MWFConfigurationException( 'Infinite or too 
long redirect detected (host=\'' . $host . '\')' );
+                       throw new MWFConfigurationException( 'Infinite or too 
long redirect detected (host=\'' . $host . '\', path=\'' . $path . '\')' );
                }
-               throw new MWFConfigurationException( 'No farm corresponding to 
this host (host=\'' . $host . '\')' );
+               throw new MWFConfigurationException( 'No farm corresponding to 
this host (host=\'' . $host . '\', path=\'' . $path . '\')' );
        }
 
        /**
@@ -776,9 +788,22 @@
                # For each proposed farm, check if the host matches
                foreach( $farms as $farm => $config ) {
 
-                       if( !preg_match( '/^' . $config['server'] . '$/i', 
$host, $matches ) ) {
+                       # Cut the host from the beginning to the first slash
+                       # A slash is added at the end to be sure there is a 
slash
+                       $confighost = substr( $config['server'], 0, strpos( 
$config['server'] . '/', '/' ) );
+                       # Added a trailing slash either unuseful if there is 
already a subdirectory either it will act as a separator between host and path
+                       $configpath = substr( $config['server'] . '/', strlen( 
$confighost ) );
+                       # Protect the slashes but let other characters to keep 
the regex
+                       $configpath = str_replace( '/', '\/', $configpath );
+                       # The host is case-insensitive, the path is 
case-sensitive
+                       # The tested host must have a trailing slash because 
the regex has at least one slash
+                       if( ! preg_match( '/^' . $confighost . '(?-i)' . 
$configpath . '/i', $host . '/', $matches ) ) {
                                continue;
                        }
+                       # Get the resulting host; this must not be the tested 
host because it has the article name, etc and is less safe than
+                       # the config host; this is the interpretation of the 
configured regex tested against the client host. Remove the
+                       # last character, which is always the slash added in 
$configpath.
+                       $host = substr( $matches[0], 0, -1 );
 
                        # Initialise variables from the host
                        $variables = array();
diff --git a/tests/phpunit/ConfigurationTest.php 
b/tests/phpunit/ConfigurationTest.php
index 740ff3b..598bbf4 100644
--- a/tests/phpunit/ConfigurationTest.php
+++ b/tests/phpunit/ConfigurationTest.php
@@ -102,7 +102,7 @@
                        ),
                );
 
-               $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
null, self::$wgMediaWikiFarmCacheDir,
                                           array( 'EntryPoint' => 'index.php' 
), array( 'ExtensionRegistry' => true )
                        );
@@ -153,7 +153,7 @@
        function testLoadingMechanisms() {
 
                # First, without ExtensionRegistry
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
                        array( 'EntryPoint' => 'index.php' ), array( 
'ExtensionRegistry' => false )
                );
@@ -166,7 +166,7 @@
                $this->assertContains( array( 'MediaWikiFarm', 'extension', 
'require_once', 5 ), $extensions );
 
                # Now with ExtensionRegistry
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
                        array( 'EntryPoint' => 'index.php' ), array( 
'ExtensionRegistry' => true )
                );
@@ -179,7 +179,7 @@
                $this->assertContains( array( 'MediaWikiFarm', 'extension', 
'wfLoadExtension', 7 ), $extensions );
 
                # Now with imposed loading mechanism (1)
-               $farm = new MediaWikiFarm( 
'c.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'c.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
                        array( 'EntryPoint' => 'index.php' ), array( 
'ExtensionRegistry' => true )
                );
@@ -193,7 +193,7 @@
                $this->assertContains( array( 'TestExtensionBiLoading', 
'extension', 'require_once', 0 ), $extensions );
 
                # Now with imposed loading mechanism (2)
-               $farm = new MediaWikiFarm( 
'd.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'd.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', false,
                        array( 'EntryPoint' => 'index.php' ), array( 
'ExtensionRegistry' => true )
                );
@@ -241,7 +241,7 @@
         */
        function testLoadMediaWikiConfigMultiversion() {
 
-               $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', self::$wgMediaWikiFarmCacheDir,
                        array( 'EntryPoint' => 'index.php', 'InnerMediaWiki' => 
true )
                );
@@ -259,7 +259,7 @@
 
                # Re-load to use config cache
                AbstractMediaWikiFarmScript::rmdirr( 
self::$wgMediaWikiFarmCacheDir . '/versions.php' );
-               $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', self::$wgMediaWikiFarmCacheDir,
                        array( 'EntryPoint' => 'index.php', 'InnerMediaWiki' => 
true )
                );
@@ -303,7 +303,7 @@
         */
        function testLoadMediaWikiConfigMonoversion() {
 
-               $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir,
                        array( 'EntryPoint' => 'index.php', 'InnerMediaWiki' => 
true )
                );
@@ -318,7 +318,7 @@
 
                # Re-load to use config cache
                AbstractMediaWikiFarmScript::rmdirr( 
self::$wgMediaWikiFarmCacheDir . 
'/wikis/a.testfarm-monoversion.example.org.php' );
-               $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir,
                        array( 'EntryPoint' => 'index.php', 'InnerMediaWiki' => 
true )
                );
@@ -347,7 +347,7 @@
         */
        function testSort() {
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-test-extensions.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, dirname( __FILE__ ) . 
'/data/mediawiki', self::$wgMediaWikiFarmCacheDir,
                        array( 'EntryPoint' => 'index.php', 'InnerMediaWiki' => 
false )
                );
diff --git a/tests/phpunit/ConstructionTest.php 
b/tests/phpunit/ConstructionTest.php
index 08e3a9b..703e52c 100644
--- a/tests/phpunit/ConstructionTest.php
+++ b/tests/phpunit/ConstructionTest.php
@@ -32,6 +32,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -87,6 +88,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-monoversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                null,
                                false,
@@ -140,6 +142,62 @@
        }
 
        /**
+        * Test a successful initialisation of multiversion MediaWikiFarm 
selected by subdirectories with a correct configuration file farms.php.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @covers MediaWikiFarm::getState
+        * @covers MediaWikiFarm::getFarmConfiguration
+        * @covers MediaWikiFarm::getVariable
+        * @uses MediaWikiFarm::readFile
+        */
+       function testSuccessfulConstructionMultiversionSubdirectories() {
+
+               $farm = new MediaWikiFarm(
+                               
'testfarm-multiversion-subdirectories.example.org',
+                               '/a',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+
+               $this->assertEquals( 
'testfarm-multiversion-subdirectories.example.org/a', $farm->getVariable( 
'$SERVER' ) );
+
+               $this->assertEquals( 'index.php', $farm->getState( 'EntryPoint' 
) );
+               $this->assertNull( $farm->getState( 'nonexistant' ) );
+
+               $farmConfig = array(
+                       'server' => 
'testfarm-multiversion-subdirectories\.example\.org/(?P<wiki>[a-z])',
+                       'variables' => array(
+                               array( 'variable' => 'wiki', ),
+                       ),
+                       'suffix' => 'testfarm',
+                       'wikiID' => '$wikitestfarm',
+                       'versions' => 'versions.php',
+                       'coreconfig' => array(
+                               'farms.php',
+                       ),
+                       'config' => array(
+                               array( 'file' => 'settings.php',
+                                      'key' => 'default',
+                               ),
+                               array( 'file' => 'localsettings.php',
+                                      'key' => '*testfarm',
+                                      'default' => 'testfarm',
+                               ),
+                               array( 'file' => 'globalsettings.php',
+                                      'key' => '*',
+                               ),
+                               array( 'file' => 'LocalSettings.php',
+                                      'executable' => true,
+                               ),
+                       ),
+               );
+
+               $this->assertEquals( $farmConfig, $farm->getFarmConfiguration() 
);
+       }
+
+       /**
         * Test when there is no configuration file farms.yml/json/php.
         *
         * @covers MediaWikiFarm::__construct
@@ -155,6 +213,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                $wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -174,6 +233,7 @@
 
                $farm = new MediaWikiFarm(
                                0,
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -193,6 +253,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                0,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -214,6 +275,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                $wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -233,6 +295,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                0,
                                false,
@@ -252,6 +315,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir . '/farms.php',
                                false,
@@ -271,6 +335,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                0,
@@ -290,6 +355,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -332,6 +398,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -351,6 +418,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -370,6 +438,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -390,6 +459,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -398,7 +468,7 @@
        }
 
        /**
-        * Test successful construction with global variable.
+        * Test successful construction with global variable for the host.
         *
         * @backupGlobals enabled
         * @covers MediaWikiFarm::__construct
@@ -413,6 +483,7 @@
 
                $farm = new MediaWikiFarm(
                                null,
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -422,7 +493,7 @@
        }
 
        /**
-        * Test successful construction with global variable.
+        * Test successful construction with global variable for the host.
         *
         * @backupGlobals enabled
         * @covers MediaWikiFarm::__construct
@@ -437,12 +508,144 @@
 
                $farm = new MediaWikiFarm(
                                null,
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
                                array( 'EntryPoint' => 'index.php' ) );
 
                $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
+       }
+
+       /**
+        * Test successful construction with global variable for the path.
+        *
+        * @backupGlobals enabled
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @covers MediaWikiFarm::getVariable
+        * @uses MediaWikiFarm::readFile
+        */
+       function testSuccessfulConstructionWithGlobalVariable3() {
+
+               $this->backupAndSetGlobalSubvariable( '_SERVER', 'HTTP_HOST', 
'a.testfarm-multiversion.example.org' );
+               $this->backupAndUnsetGlobalSubvariable( '_SERVER', 
'SERVER_NAME' );
+               $this->backupAndSetGlobalSubvariable( '_SERVER', 'REQUEST_URI', 
'' );
+
+               $farm = new MediaWikiFarm(
+                               null,
+                               null,
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+
+               $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
+       }
+
+       /**
+        * Test a normal path is correctly recognised.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::getVariable
+        * @uses MediaWikiFarm::readFile
+        */
+       function testNormalPath() {
+
+               $farm = new MediaWikiFarm(
+                               'a.testfarm-multiversion.example.org',
+                               '/',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+
+               $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
+       }
+
+       /**
+        * Test a normal path is correctly recognised.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::getVariable
+        * @uses MediaWikiFarm::readFile
+        */
+       function testNormalPath2() {
+
+               $farm = new MediaWikiFarm(
+                               'a.testfarm-multiversion.example.org',
+                               '/wiki/Main_Page',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+
+               $this->assertEquals( 'a.testfarm-multiversion.example.org', 
$farm->getVariable( '$SERVER' ) );
+       }
+
+       /**
+        * Test when the path is written in the server name.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::readFile
+        *
+        * @expectedException MWFConfigurationException
+        * @expectedExceptionMessage No farm corresponding to this host
+        */
+       function testFailedPath() {
+
+               $farm = new MediaWikiFarm(
+                               
'testfarm-multiversion-subdirectories.example.org/a',
+                               '',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+       }
+
+       /**
+        * Test when the path is written in the server name.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::readFile
+        *
+        * @expectedException MWFConfigurationException
+        * @expectedExceptionMessage No farm corresponding to this host
+        */
+       function testFailedPath2() {
+
+               $farm = new MediaWikiFarm(
+                               
'testfarm-multiversion-subdirectories.example.or',
+                               'g/a',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
+       }
+
+       /**
+        * Test when the path is written in the server name.
+        *
+        * @covers MediaWikiFarm::__construct
+        * @covers MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::readFile
+        *
+        * @expectedException MWFConfigurationException
+        * @expectedExceptionMessage No farm corresponding to this host
+        */
+       function testFailedPath3() {
+
+               $farm = new MediaWikiFarm(
+                               
'testfarm-multiversion-subdirectories.example.org',
+                               '/A',
+                               self::$wgMediaWikiFarmConfigDir,
+                               self::$wgMediaWikiFarmCodeDir,
+                               false,
+                               array( 'EntryPoint' => 'index.php' ) );
        }
 
        /**
@@ -459,6 +662,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                self::$wgMediaWikiFarmCacheDir,
@@ -482,6 +686,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -512,6 +717,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-monoversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                null,
                                false,
@@ -539,6 +745,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion-redirect.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -561,6 +768,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-infinite-redirect.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -581,6 +789,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-missing.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -728,6 +937,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-infinite-redirect.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir . '/yaml',
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -748,6 +958,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-infinite-redirect.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir . '/json',
                                self::$wgMediaWikiFarmCodeDir,
                                false,
diff --git a/tests/phpunit/InstallationIndependantTest.php 
b/tests/phpunit/InstallationIndependantTest.php
index 17f600d..f9f0661 100644
--- a/tests/phpunit/InstallationIndependantTest.php
+++ b/tests/phpunit/InstallationIndependantTest.php
@@ -40,7 +40,7 @@
         */
        static function constructMediaWikiFarm( $host ) {
 
-               return new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, null, false );
+               return new MediaWikiFarm( $host, null, 
self::$wgMediaWikiFarmConfigDir, null, false );
        }
 
        /**
@@ -304,7 +304,7 @@
         */
        function testNoCache() {
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', self::$wgMediaWikiFarmConfigDir, null, 
false );
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', null, self::$wgMediaWikiFarmConfigDir, 
null, false );
 
                $farm->readFile( 'testreading.json', 
self::$wgMediaWikiFarmConfigDir );
 
@@ -325,7 +325,7 @@
         */
        function testCacheFile() {
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', self::$wgMediaWikiFarmConfigDir, null, 
self::$wgMediaWikiFarmCacheDir );
+               $farm = new MediaWikiFarm( 
'a.testfarm-monoversion.example.org', null, self::$wgMediaWikiFarmConfigDir, 
null, self::$wgMediaWikiFarmCacheDir );
 
                copy( self::$wgMediaWikiFarmConfigDir . '/testreading.json', 
self::$wgMediaWikiFarmConfigDir . '/testreading2.json' );
 
@@ -498,7 +498,7 @@
 
                $this->assertEquals( $localSettings, 
$this->farm->createLocalSettings( $configuration, "# Pre-config\n", "# 
Post-config\n" ) );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, false );
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null, self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, false );
                $extensionJson = var_export( dirname( dirname( dirname( 
__FILE__ ) ) ) . '/extension.json', true );
                $localSettings2 = str_replace( 'wfLoadExtension( 
\'MediaWikiFarm\' );', "wfLoadExtension( 'MediaWikiFarm', $extensionJson );", 
$localSettings );
                $this->assertEquals( $localSettings2, 
$farm->createLocalSettings( $configuration, "# Pre-config\n", "# Post-config\n" 
) );
diff --git a/tests/phpunit/LoadingTest.php b/tests/phpunit/LoadingTest.php
index e2ccd86..8f6e690 100644
--- a/tests/phpunit/LoadingTest.php
+++ b/tests/phpunit/LoadingTest.php
@@ -154,7 +154,7 @@
                $this->backupGlobalVariables( array_keys( $result['settings'] ) 
);
                $this->backupAndUnsetGlobalVariable( 'wgFileExtensions' );
 
-               $exists = MediaWikiFarm::load( 'index.php', 
'a.testfarm-multiversion-test-extensions.example.org', array(), array( 
'ExtensionRegistry' => true ) );
+               $exists = MediaWikiFarm::load( 'index.php', 
'a.testfarm-multiversion-test-extensions.example.org', null, array(), array( 
'ExtensionRegistry' => true ) );
                $this->assertEquals( 200, $exists );
                $this->assertEquals( 'vstub', $wgMediaWikiFarm->getVariable( 
'$VERSION' ) );
 
@@ -218,7 +218,7 @@
 
                $this->backupGlobalVariable( 'wgAutoloadClasses' );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null,
                        self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, false,
                        array(), array( 'ExtensionRegistry' => false )
                );
diff --git a/tests/phpunit/LoggingTest.php b/tests/phpunit/LoggingTest.php
index d9f7870..001230d 100644
--- a/tests/phpunit/LoggingTest.php
+++ b/tests/phpunit/LoggingTest.php
@@ -66,6 +66,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
@@ -89,6 +90,7 @@
 
                $farm = new MediaWikiFarm(
                                'a.testfarm-multiversion.example.org',
+                               null,
                                self::$wgMediaWikiFarmConfigDir,
                                self::$wgMediaWikiFarmCodeDir,
                                false,
diff --git a/tests/phpunit/MonoversionInstallationTest.php 
b/tests/phpunit/MonoversionInstallationTest.php
index 53a99db..35155ac 100644
--- a/tests/phpunit/MonoversionInstallationTest.php
+++ b/tests/phpunit/MonoversionInstallationTest.php
@@ -33,7 +33,7 @@
         */
        static function constructMediaWikiFarm( $host ) {
 
-               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, null, false, array( 'EntryPoint' => 
'index.php' ) );
+               $farm = new MediaWikiFarm( $host, null, 
self::$wgMediaWikiFarmConfigDir, null, false, array( 'EntryPoint' => 
'index.php' ) );
 
                return $farm;
        }
diff --git a/tests/phpunit/MultiversionInstallationTest.php 
b/tests/phpunit/MultiversionInstallationTest.php
index 3ec8a86..51d703b 100644
--- a/tests/phpunit/MultiversionInstallationTest.php
+++ b/tests/phpunit/MultiversionInstallationTest.php
@@ -52,7 +52,7 @@
         */
        static function constructMediaWikiFarm( $host, $entryPoint = 
'index.php' ) {
 
-               $farm = new MediaWikiFarm( $host, 
self::$wgMediaWikiFarmConfigDir, self::$wgMediaWikiFarmCodeDir, false, array( 
'EntryPoint' => $entryPoint ) );
+               $farm = new MediaWikiFarm( $host, null, 
self::$wgMediaWikiFarmConfigDir, self::$wgMediaWikiFarmCodeDir, false, array( 
'EntryPoint' => $entryPoint ) );
 
                return $farm;
        }
@@ -236,7 +236,7 @@
         */
        function testFamilyFarm() {
 
-               $farm = new MediaWikiFarm( 
'a.a.testfarm-multiversion-with-file-versions-other-keys.example.org',
+               $farm = new MediaWikiFarm( 
'a.a.testfarm-multiversion-with-file-versions-other-keys.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
@@ -244,7 +244,7 @@
                $this->assertEquals( 'aafamilytestfarm', $farm->getVariable( 
'$WIKIID' ) );
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
 
-               $farm = new MediaWikiFarm( 
'b.a.testfarm-multiversion-with-file-versions-other-keys.example.org',
+               $farm = new MediaWikiFarm( 
'b.a.testfarm-multiversion-with-file-versions-other-keys.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
@@ -252,7 +252,7 @@
                $this->assertEquals( 'bafamilytestfarm', $farm->getVariable( 
'$WIKIID' ) );
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
 
-               $farm = new MediaWikiFarm( 
'a.b.testfarm-multiversion-with-file-versions-other-keys.example.org',
+               $farm = new MediaWikiFarm( 
'a.b.testfarm-multiversion-with-file-versions-other-keys.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
@@ -289,7 +289,7 @@
         */
        function testDeploymedVersions() {
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
@@ -297,7 +297,7 @@
                $this->assertEquals( 'vstub', $farm->getVariable( '$VERSION' ) 
);
                $this->assertTrue( is_file( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php' ) );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
                $this->assertTrue( $farm->checkExistence() );
@@ -333,7 +333,7 @@
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
@@ -372,7 +372,7 @@
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'maintenance/update.php' )
                        );
                $farm->updateVersionAfterMaintenance();
@@ -423,7 +423,7 @@
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/testdeploymentsfarmversions.php', $versionsFile );
                file_put_contents( self::$wgMediaWikiFarmConfigDir . 
'/deployments.php', $deploymentsFile );
 
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion-with-file-versions-with-deployments.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
dirname( __FILE__ ) . '/data/mediawiki', false, array( 'EntryPoint' => 
'index.php' )
                        );
 
@@ -468,7 +468,7 @@
        function testCacheExistence() {
 
                # Populate the existence cache
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, self::$wgMediaWikiFarmCacheDir,
                                           array( 'EntryPoint' => 'index.php' )
                        );
@@ -478,7 +478,7 @@
                $this->assertFalse( is_file( self::$wgMediaWikiFarmCacheDir . 
'/LocalSettings/a.testfarm-multiversion.example.org.php' ) );
 
                # Read the existence cache
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, self::$wgMediaWikiFarmCacheDir,
                                           array( 'EntryPoint' => 'index.php' )
                        );
@@ -486,7 +486,7 @@
                $this->assertTrue( $farm->checkExistence() );
 
                # Populate the configuration cache
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, self::$wgMediaWikiFarmCacheDir,
                                           array( 'EntryPoint' => 'index.php', 
'InnerMediaWiki' => true ),
                                           array( 'ExtensionRegistry' => true )
@@ -502,7 +502,7 @@
                $this->assertTrue( touch( self::$wgMediaWikiFarmConfigDir . 
'/farms.php' ) );
 
                # Check the existence cache is understood as invalidated
-               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org',
+               $farm = new MediaWikiFarm( 
'a.testfarm-multiversion.example.org', null,
                                           self::$wgMediaWikiFarmConfigDir, 
self::$wgMediaWikiFarmCodeDir, self::$wgMediaWikiFarmCacheDir,
                                           array( 'EntryPoint' => 'index.php' )
                        );
diff --git a/tests/phpunit/data/config/farms.php 
b/tests/phpunit/data/config/farms.php
index 5a7f3de..7fe1bc2 100644
--- a/tests/phpunit/data/config/farms.php
+++ b/tests/phpunit/data/config/farms.php
@@ -67,6 +67,32 @@
                ),
        ),
 
+       'testfarm-multiversion-subdirectories' => array(
+
+               'server' => 
'testfarm-multiversion-subdirectories\.example\.org/(?P<wiki>[a-z])',
+               'variables' => array(
+                       array( 'variable' => 'wiki', ),
+               ),
+               'suffix' => 'testfarm',
+               'wikiID' => '$wikitestfarm',
+               'versions' => 'versions.php',
+               'config' => array(
+                       array( 'file' => 'settings.php',
+                              'key' => 'default',
+                       ),
+                       array( 'file' => 'localsettings.php',
+                              'key' => '*testfarm',
+                              'default' => 'testfarm',
+                       ),
+                       array( 'file' => 'globalsettings.php',
+                              'key' => '*',
+                       ),
+                       array( 'file' => 'LocalSettings.php',
+                              'executable' => true,
+                       ),
+               ),
+       ),
+
        'testfarm-multiversion-with-file-variable-without-version' => array(
 
                'server' => 
'(?P<wiki>[a-z])\.testfarm-multiversion-with-file-variable-without-version\.example\.org',

-- 
To view, visit https://gerrit.wikimedia.org/r/344881
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic906b84315150abc8fff90e6db23d47b27707902
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

Reply via email to