Index: trunk/phase3/maintenance/doMaintenance.php |
— | — | @@ -65,12 +65,7 @@ |
66 | 66 | |
67 | 67 | if ( defined( 'MW_CONFIG_CALLBACK' ) ) { |
68 | 68 | # Use a callback function to configure MediaWiki |
69 | | - $callback = MW_CONFIG_CALLBACK; |
70 | | - # PHP 5.1 doesn't support "class::method" for call_user_func, so split it |
71 | | - if ( strpos( $callback, '::' ) !== false ) { |
72 | | - $callback = explode( '::', $callback, 2 ); |
73 | | - } |
74 | | - call_user_func( $callback ); |
| 69 | + MWFunction::call( MW_CONFIG_CALLBACK ); |
75 | 70 | } elseif ( file_exists( "$IP/wmf-config/wikimedia-mode" ) ) { |
76 | 71 | // Load settings, using wikimedia-mode if needed |
77 | 72 | // Fixme: replace this hack with general farm-friendly code |
Index: trunk/phase3/tests/phpunit/includes/MWFunctionTest.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class MWFunctionTest extends MediaWikiTestCase { |
| 5 | + |
| 6 | + function testCallUserFuncWorkarounds() { |
| 7 | + |
| 8 | + $this->assertEquals( |
| 9 | + MWFunction::call( 'MWFunctionTest::someMethod' ), |
| 10 | + call_user_func( array( 'MWFunctionTest', 'someMethod' ) ) |
| 11 | + ); |
| 12 | + $this->assertEquals( |
| 13 | + MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' ), |
| 14 | + call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ) |
| 15 | + ); |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + $this->assertEquals( |
| 20 | + MWFunction::callArray( 'MWFunctionTest::someMethod', array() ), |
| 21 | + call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ) |
| 22 | + ); |
| 23 | + $this->assertEquals( |
| 24 | + MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) ), |
| 25 | + call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ) |
| 26 | + ); |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + public static function someMethod() { |
| 31 | + return func_get_args(); |
| 32 | + } |
| 33 | + |
| 34 | +} |
| 35 | + |
Property changes on: trunk/phase3/tests/phpunit/includes/MWFunctionTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 36 | + native |
Index: trunk/phase3/includes/MWFunction.php |
— | — | @@ -0,0 +1,52 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * This program is free software; you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation; either version 2 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License along |
| 16 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + * http://www.gnu.org/copyleft/gpl.html |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +class MWFunction { |
| 23 | + |
| 24 | + protected static function cleanCallback( $callback ) { |
| 25 | + |
| 26 | + if( is_string( $callback ) ) { |
| 27 | + if ( in_string( '::', $callback ) ) { |
| 28 | + //PHP 5.1 cannot use call_user_func( 'Class::Method' ) |
| 29 | + //It can only handle only call_user_func( array( 'Class', 'Method' ) ) |
| 30 | + $callback = explode( '::', $callback, 2); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + return $callback; |
| 35 | + } |
| 36 | + |
| 37 | + public static function call( $callback ) { |
| 38 | + $callback = self::cleanCallback( $callback ); |
| 39 | + |
| 40 | + $args = func_get_args(); |
| 41 | + |
| 42 | + return call_user_func_array( 'call_user_func', $args ); |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + public static function callArray( $callback, $params ) { |
| 47 | + |
| 48 | + $callback = self::cleanCallback( $callback ); |
| 49 | + return call_user_func_array( $callback, $params ); |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | +} |
Property changes on: trunk/phase3/includes/MWFunction.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 54 | + native |
Index: trunk/phase3/includes/WebStart.php |
— | — | @@ -96,12 +96,8 @@ |
97 | 97 | |
98 | 98 | if ( defined( 'MW_CONFIG_CALLBACK' ) ) { |
99 | 99 | # Use a callback function to configure MediaWiki |
100 | | - $callback = MW_CONFIG_CALLBACK; |
101 | | - # PHP 5.1 doesn't support "class::method" for call_user_func, so split it |
102 | | - if ( strpos( $callback, '::' ) !== false ) { |
103 | | - $callback = explode( '::', $callback, 2); |
104 | | - } |
105 | | - call_user_func( $callback ); |
| 100 | + MWFunction::call( MW_CONFIG_CALLBACK ); |
| 101 | + |
106 | 102 | } else { |
107 | 103 | if ( !defined('MW_CONFIG_FILE') ) |
108 | 104 | define('MW_CONFIG_FILE', "$IP/LocalSettings.php"); |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -166,6 +166,7 @@ |
167 | 167 | 'MessageCache' => 'includes/MessageCache.php', |
168 | 168 | 'MimeMagic' => 'includes/MimeMagic.php', |
169 | 169 | 'MWException' => 'includes/Exception.php', |
| 170 | + 'MWFunction' => 'includes/MWFunction.php', |
170 | 171 | 'MWHttpRequest' => 'includes/HttpFunctions.php', |
171 | 172 | 'MWMemcached' => 'includes/memcached-client.php', |
172 | 173 | 'MWNamespace' => 'includes/Namespace.php', |