Seb35 has uploaded a new change for review. https://gerrit.wikimedia.org/r/299370
Change subject: Added JSON format, soften requirement on YAML (possibly it is not installed and it works fine). ...................................................................... Added JSON format, soften requirement on YAML (possibly it is not installed and it works fine). --- M src/MediaWikiFarm.php 1 file changed, 20 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm refs/changes/70/299370/1 diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 0c1cbbf..d95e7f9 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -10,7 +10,7 @@ # Protect against web entry if( !defined( 'MEDIAWIKI' ) ) exit; -require_once __DIR__ . '/../vendor/autoload.php'; +@include_once __DIR__ . '/../vendor/autoload.php'; /** * This class computes the configuration of a specific wiki from a set of configuration files. @@ -272,6 +272,7 @@ # Read the farm(s) configuration if( $configs = $this->readFile( $this->configDir . '/farms.yml' ) ); + else if( $configs = $this->readFile( $this->configDir . '/farms.json' ) ); else if( $configs = $this->readFile( $this->configDir . '/farms.php' ) ); else $this->unusable = true; @@ -380,9 +381,9 @@ * ----------------------- */ /** - * Read a file either in PHP, YAML, or dblist, and returns the interpreted array. + * Read a file either in PHP, YAML (if library available), JSON, or dblist, and returns the interpreted array. * - * The choice between the format depends on the extension: php, yml, dblist. + * The choice between the format depends on the extension: php, yml, yaml, json, dblist. * * @param string $filename Name of the requested file. * @return array|false The interpreted array in case of success, else false. @@ -399,7 +400,7 @@ if( $format == 'php' ) { - $array = require $filename; + $array = @include $filename; if( !is_array( $array ) ) return false; @@ -407,22 +408,34 @@ return $array; } - if( $format == 'yml' ) { + if( $format == 'yml' || $format == 'yaml' ) { + + if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) ) + return false; try { - $array = \Symfony\Component\Yaml\Yaml::parse( file_get_contents( $filename ) ); + $array = Symfony\Component\Yaml\Yaml::parse( file_get_contents( $filename ) ); if( !is_array( $array ) ) return false; return $array; } - catch( \Symfony\Component\Yaml\Exception\ParseException $e ) { + catch( Symfony\Component\Yaml\Exception\ParseException $e ) { return false; } } + if( $format == 'json' ) { + + $array = json_decode( file_get_contents( $filename ), true ); + if( !is_array( $array ) ) + return false; + + return $array; + } + if( $format == 'dblist' ) { $content = file_get_contents( $filename ); -- To view, visit https://gerrit.wikimedia.org/r/299370 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I607c0754224c655ee3a65268b346b7814d03d18f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits