[MediaWiki-commits] [Gerrit] mediawiki...MediaWikiFarm[master]: Execute scripts when wikis are path-based

2017-06-25 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
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(-)

Approvals:
  Seb35: Looks good to me, approved
  jenkins-bot: Verified



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 

[MediaWiki-commits] [Gerrit] mediawiki...MediaWikiFarm[master]: Execute scripts when wikis are path-based

2017-06-25 Thread Seb35 (Code Review)
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