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 0000000..bffeca4 --- /dev/null +++ b/src/Yaml.php @@ -0,0 +1,29 @@ +<?php + +/** + * Helper program returning the parsed content of a YAML file. + * + * It was splitted from the main class MediaWikiFarm to ensure compatibility with + * PHP 5.2 (which doesn’t understand namespaces). + * + * @author Sébastien Beyou ~ Seb35 <se...@seb35.fr> + * @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( 'Symfony\Component\Yaml\Yaml' ) || !class_exists( 'Symfony\Component\Yaml\Exception\ParseException' ) ) + return false; + +# Return the array read from YAML or an error +try { + return Symfony\Component\Yaml\Yaml::parse( @file_get_contents( $prefixedFile ) ); +} +catch( Symfony\Component\Yaml\Exception\ParseException $e ) { + + return false; +} diff --git a/src/main.php b/src/main.php index 3524294..8f9f6a1 100644 --- a/src/main.php +++ b/src/main.php @@ -17,6 +17,9 @@ # Old MediaWiki installations doesn’t load DefaultSettings.php before LocalSettings.php if( !isset( $wgVersion ) ) { + if( !$IP ) { + $IP = realpath( '.' ) ? realpath( '.' ) : dirname( __DIR__ ); + } require_once "$IP/includes/DefaultSettings.php"; } -- To view, visit https://gerrit.wikimedia.org/r/299493 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6987ca8985787bb7618782b98e34872d6ff60534 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com> Gerrit-Reviewer: Seb35 <seb35wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits