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 0000000..18913ec
--- /dev/null
+++ b/src/Yaml.php
@@ -0,0 +1,16 @@
+<?php
+
+
+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 {
+       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..7b55395 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( !isset( $IP ) ) {
+               $IP = realpath( '.' );
+       }
        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: newchange
Gerrit-Change-Id: I6987ca8985787bb7618782b98e34872d6ff60534
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

Reply via email to