[MediaWiki-commits] [Gerrit] Compatibility with PHP 5.2 (degraded mode; cannot read YAML)... - change (mediawiki...MediaWikiFarm)
Seb35 has submitted this change and it was merged. Change subject: Compatibility with PHP 5.2 (degraded mode; cannot read YAML) and MediaWiki < 1.9 .. Compatibility with PHP 5.2 (degraded mode; cannot read YAML) and MediaWiki < 1.9 Note that in current state it cannot work with MediaWiki < 1.6 because SiteConfiguration::getAll was introduced in MediaWiki 1.6. Change-Id: I6987ca8985787bb7618782b98e34872d6ff60534 --- M src/MediaWikiFarm.php A src/Yaml.php M src/main.php 3 files changed, 52 insertions(+), 16 deletions(-) Approvals: Seb35: Verified; Looks good to me, approved diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 113bd48..4a90544 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -842,8 +842,8 @@ return array( 'suffix' => $this->params['suffix'], 'lang' => '', - 'tags' => [], - 'params' => [], + 'tags' => array(), + 'params' => array(), ); } @@ -889,19 +889,19 @@ # Extract skin and extension configuration from the general configuration $regexSkins = count( $globals['skins'] ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), array_keys( $globals['skins'] ) ) ) . ')/' : false; $regexExtensions = count( $globals['extensions'] ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), array_keys( $globals['extensions'] ) ) ) . ')/' : false; $regexUnsetPrefixes = count( $unsetPrefixes ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), $unsetPrefixes ) ) . ')/' : false; @@ -918,6 +918,17 @@ elseif( $regexUnsetPrefixes && preg_match( $regexUnsetPrefixes, $setting, $matches ) ) unset( $matches[1] ); } + } + + /** +* Helper function used in extractSkinsAndExtensions. +* +* @param string $a String to be regex-escaped. +* @return string Escaped string. +*/ + static private function protectRegex( $a ) { + + return preg_quote( $a, '/' ); } /** @@ -1005,18 +1016,11 @@ # Load Composer libraries # There is no warning if not present because to properly handle the error by returning false # This is only included here to avoid delays (~3ms without OPcache) during the loading using cached files or other formats - if( is_file( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) - include_once dirname( __FILE__ ) . '/../vendor/autoload.php'; - - if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) || !class_exists( 'Symfony\Component\Yaml\Exception\ParseException' ) ) - return false; - - try { - $array = Symfony\Component\Yaml\Yaml::parse( @file_get_contents( $prefixedFile ) ); - } - catch( Symfony\Component\Yaml\Exception\ParseException $e ) { + if( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) { - return false; + $array = require 'Yaml.php'; + if( $array === false ) + return false; } } diff --git a/src/Yaml.php b/src/Yaml.php new file mode 100644 index 000..bffeca4 --- /dev/null +++ b/src/Yaml.php @@ -0,0 +1,29 @@ + + * @license GPL-3.0+ GNU General Public License v3.0 ou version ultérieure + * @license AGPL-3.0+ GNU Affero General Public License v3.0 ou version ultérieure + */ + +# Load Composer +if( is_file( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) + include_once dirname( __FILE__ ) . '/../vendor/autoload.php'; + +# If the class doesn’t exist, return an error +if( !class_exists(
[MediaWiki-commits] [Gerrit] Compatibility with PHP 5.2 (degraded mode; cannot read YAML)... - change (mediawiki...MediaWikiFarm)
Seb35 has uploaded a new change for review. https://gerrit.wikimedia.org/r/299493 Change subject: Compatibility with PHP 5.2 (degraded mode; cannot read YAML) and MediaWiki < 1.9 .. Compatibility with PHP 5.2 (degraded mode; cannot read YAML) and MediaWiki < 1.9 Note that in current state it cannot work with MediaWiki < 1.6 because SiteConfiguration::getAll was introduced in MediaWiki 1.6. Change-Id: I6987ca8985787bb7618782b98e34872d6ff60534 --- M src/MediaWikiFarm.php A src/Yaml.php M src/main.php 3 files changed, 39 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm refs/changes/93/299493/1 diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 113bd48..4a90544 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -842,8 +842,8 @@ return array( 'suffix' => $this->params['suffix'], 'lang' => '', - 'tags' => [], - 'params' => [], + 'tags' => array(), + 'params' => array(), ); } @@ -889,19 +889,19 @@ # Extract skin and extension configuration from the general configuration $regexSkins = count( $globals['skins'] ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), array_keys( $globals['skins'] ) ) ) . ')/' : false; $regexExtensions = count( $globals['extensions'] ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), array_keys( $globals['extensions'] ) ) ) . ')/' : false; $regexUnsetPrefixes = count( $unsetPrefixes ) ? '/^wg(' . implode( '|', array_map( - function( $a ) { return preg_quote( $a, '/' ); }, + array( 'MediaWikiFarm', 'protectRegex' ), $unsetPrefixes ) ) . ')/' : false; @@ -918,6 +918,17 @@ elseif( $regexUnsetPrefixes && preg_match( $regexUnsetPrefixes, $setting, $matches ) ) unset( $matches[1] ); } + } + + /** +* Helper function used in extractSkinsAndExtensions. +* +* @param string $a String to be regex-escaped. +* @return string Escaped string. +*/ + static private function protectRegex( $a ) { + + return preg_quote( $a, '/' ); } /** @@ -1005,18 +1016,11 @@ # Load Composer libraries # There is no warning if not present because to properly handle the error by returning false # This is only included here to avoid delays (~3ms without OPcache) during the loading using cached files or other formats - if( is_file( dirname( __FILE__ ) . '/../vendor/autoload.php' ) ) - include_once dirname( __FILE__ ) . '/../vendor/autoload.php'; - - if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) || !class_exists( 'Symfony\Component\Yaml\Exception\ParseException' ) ) - return false; - - try { - $array = Symfony\Component\Yaml\Yaml::parse( @file_get_contents( $prefixedFile ) ); - } - catch( Symfony\Component\Yaml\Exception\ParseException $e ) { + if( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) { - return false; + $array = require 'Yaml.php'; + if( $array === false ) + return false; } } diff --git a/src/Yaml.php b/src/Yaml.php new file mode 100644 index 000..18913ec --- /dev/null +++ b/src/Yaml.php @@ -0,0 +1,16 @@ +https://gerrit.wikimedia.org/r/299493 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6987ca8985787bb7618782b98e34872d6ff60534 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35