From fb0a61bed71060bf5691664a666553caa9ca3ec1 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Fri, 12 Oct 2007 04:04:12 +0000 Subject: [PATCH] API: Compatibility fix for 5.0.x. Define array_intersect_key if not already defined. Implementation by Rod Byrnes, published by php.net. --- RELEASE-NOTES | 1 + includes/api/ApiResult.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a7b483da13..e0e635c5d4 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -123,6 +123,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * (bug 11569) Login should return the cookie prefix * (bug 11632) Breaking change: Specify the type of a change in the recentchanges list as 'edit', 'new', 'log' instead of 0, 1, 2, respectively. +* Compatibility fix for PHP 5.0.x. === Languages updated in 1.12 === diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 6699707358..63aaa2498a 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -179,3 +179,30 @@ class ApiResult extends ApiBase { } } +/* For compatibility with PHP versions < 5.1.0, define our own array_intersect_key function. */ +if (!function_exists('array_intersect_key')) { + function array_intersect_key($isec, $keys) { + $argc = func_num_args(); + + if ($argc > 2) { + for ($i = 1; !empty($isec) && $i < $argc; $i++) { + $arr = func_get_arg($i); + + foreach (array_keys($isec) as $key) { + if (!isset($arr[$key])) + unset($isec[$key]); + } + } + + return $isec; + } else { + $res = array(); + foreach (array_keys($isec) as $key) { + if (isset($keys[$key])) + $res[$key] = $isec[$key]; + } + + return $res; + } + } +} -- 2.20.1