jenkins-bot has submitted this change and it was merged.

Change subject: Deprecate MWFunction::call and ::callArray
......................................................................


Deprecate MWFunction::call and ::callArray

These functions existed to work around a bug (fixed in PHP 5.3) and
a missing feature (added in PHP 5.2) in older versions of PHP;
therefore, they are no longer necessary.

Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7
---
M includes/GlobalFunctions.php
M includes/MWFunction.php
M includes/WebStart.php
M maintenance/doMaintenance.php
M tests/phpunit/includes/GlobalFunctions/GlobalTest.php
M tests/phpunit/includes/MWFunctionTest.php
6 files changed, 13 insertions(+), 81 deletions(-)

Approvals:
  Parent5446: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index e71e80c..17835e4 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -1351,7 +1351,7 @@
  */
 function wfMessageFallback( /*...*/ ) {
        $args = func_get_args();
-       return MWFunction::callArray( 'Message::newFallbackSequence', $args );
+       return call_user_func_array( 'Message::newFallbackSequence', $args );
 }
 
 /**
diff --git a/includes/MWFunction.php b/includes/MWFunction.php
index 3eaa8fe..6d11d17 100644
--- a/includes/MWFunction.php
+++ b/includes/MWFunction.php
@@ -23,48 +23,24 @@
 class MWFunction {
 
        /**
-        * @param $callback
-        * @return array
-        * @throws MWException
-        */
-       protected static function cleanCallback( $callback ) {
-               if ( is_string( $callback ) ) {
-                       if ( strpos( $callback, '::' ) !== false ) {
-                               // PHP 5.1 cannot use call_user_func( 
'Class::Method' )
-                               // It can only handle only call_user_func( 
array( 'Class', 'Method' ) )
-                               $callback = explode( '::', $callback, 2 );
-                       }
-               }
-
-               if ( count( $callback ) == 2 && $callback[0] == 'self' || 
$callback[0] == 'parent' ) {
-                       throw new MWException( 'MWFunction cannot call 
self::method() or parent::method()' );
-               }
-
-               // Run autoloader (workaround for call_user_func_array bug: 
http://bugs.php.net/bug.php?id=51329)
-               is_callable( $callback );
-
-               return $callback;
-       }
-
-       /**
+        * @deprecated since 1.22; use call_user_func()
         * @param $callback
         * @return mixed
         */
        public static function call( $callback ) {
-               $callback = self::cleanCallback( $callback );
-
+               wfDeprecated( __METHOD__, '1.22' );
                $args = func_get_args();
-
                return call_user_func_array( 'call_user_func', $args );
        }
 
        /**
+        * @deprecated since 1.22; use call_user_func_array()
         * @param $callback
         * @param $argsarams
         * @return mixed
         */
        public static function callArray( $callback, $argsarams ) {
-               $callback = self::cleanCallback( $callback );
+               wfDeprecated( __METHOD__, '1.22' );
                return call_user_func_array( $callback, $argsarams );
        }
 
diff --git a/includes/WebStart.php b/includes/WebStart.php
index 604a3c0..f840a5e 100644
--- a/includes/WebStart.php
+++ b/includes/WebStart.php
@@ -121,7 +121,7 @@
 
 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
        # Use a callback function to configure MediaWiki
-       MWFunction::call( MW_CONFIG_CALLBACK );
+       call_user_func( MW_CONFIG_CALLBACK );
 } else {
        if ( !defined( 'MW_CONFIG_FILE' ) ) {
                define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php
index 4658d36..69b4b9c 100644
--- a/maintenance/doMaintenance.php
+++ b/maintenance/doMaintenance.php
@@ -77,7 +77,7 @@
 
 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
        # Use a callback function to configure MediaWiki
-       MWFunction::call( MW_CONFIG_CALLBACK );
+       call_user_func( MW_CONFIG_CALLBACK );
 } else {
        if ( file_exists( "$IP/../wmf-config/wikimedia-mode" ) ) {
                // Load settings, using wikimedia-mode if needed
diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php 
b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
index 475a774..408d440 100644
--- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -266,8 +266,8 @@
                        array_unshift( $param_set, $sampleUTF );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_substr', $param_set 
),
-                               MWFunction::callArray( 'Fallback::mb_substr', 
$param_set ),
+                               call_user_func_array( 'mb_substr', $param_set ),
+                               call_user_func_array( 'Fallback::mb_substr', 
$param_set ),
                                'Fallback mb_substr with params ' . implode( ', 
', $old_param_set )
                        );
                }
@@ -294,14 +294,14 @@
                        array_unshift( $param_set, $sampleUTF );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_strpos', $param_set 
),
-                               MWFunction::callArray( 'Fallback::mb_strpos', 
$param_set ),
+                               call_user_func_array( 'mb_strpos', $param_set ),
+                               call_user_func_array( 'Fallback::mb_strpos', 
$param_set ),
                                'Fallback mb_strpos with params ' . implode( ', 
', $old_param_set )
                        );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_strrpos', $param_set 
),
-                               MWFunction::callArray( 'Fallback::mb_strrpos', 
$param_set ),
+                               call_user_func_array( 'mb_strrpos', $param_set 
),
+                               call_user_func_array( 'Fallback::mb_strrpos', 
$param_set ),
                                'Fallback mb_strrpos with params ' . implode( 
', ', $old_param_set )
                        );
                }
diff --git a/tests/phpunit/includes/MWFunctionTest.php 
b/tests/phpunit/includes/MWFunctionTest.php
index becf507..a44f69e 100644
--- a/tests/phpunit/includes/MWFunctionTest.php
+++ b/tests/phpunit/includes/MWFunctionTest.php
@@ -1,26 +1,6 @@
 <?php
 
 class MWFunctionTest extends MediaWikiTestCase {
-       function testCallUserFuncWorkarounds() {
-               $this->assertEquals(
-                       call_user_func( array( 'MWFunctionTest', 'someMethod' ) 
),
-                       MWFunction::call( 'MWFunctionTest::someMethod' )
-               );
-               $this->assertEquals(
-                       call_user_func( array( 'MWFunctionTest', 'someMethod' 
), 'foo', 'bar', 'baz' ),
-                       MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 
'bar', 'baz' )
-               );
-
-               $this->assertEquals(
-                       call_user_func_array( array( 'MWFunctionTest', 
'someMethod' ), array() ),
-                       MWFunction::callArray( 'MWFunctionTest::someMethod', 
array() )
-               );
-               $this->assertEquals(
-                       call_user_func_array( array( 'MWFunctionTest', 
'someMethod' ), array( 'foo', 'bar', 'baz' ) ),
-                       MWFunction::callArray( 'MWFunctionTest::someMethod', 
array( 'foo', 'bar', 'baz' ) )
-               );
-       }
-
        function testNewObjFunction() {
                $arg1 = 'Foo';
                $arg2 = 'Bar';
@@ -34,30 +14,6 @@
                        MWFunction::newObj( 'MWBlankClass', $args )->args,
                        $newObject->args
                );
-
-               $this->assertEquals(
-                       MWFunction::newObj( 'MWBlankClass', $args, true )->args,
-                       $newObject->args,
-                       'Works even with PHP version < 5.1.3'
-               );
-       }
-
-       /**
-        * @expectedException MWException
-        */
-       function testCallingParentFails() {
-               MWFunction::call( 'parent::foo' );
-       }
-
-       /**
-        * @expectedException MWException
-        */
-       function testCallingSelfFails() {
-               MWFunction::call( 'self::foo' );
-       }
-
-       public static function someMethod() {
-               return func_get_args();
        }
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/74805
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to