r61440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61439‎ | r61440 | r61441 >
Date:22:31, 23 January 2010
Author:reedy
Status:ok
Tags:
Comment:
Refactor array_intersect_key from ApiResult.php to GlobalFunctions.php
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiResult.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -190,6 +190,37 @@
191191 }
192192 }
193193
 194+if ( !function_exists( 'array_intersect_key' ) ) {
 195+ /**
 196+ * Exists in 5.1.0+
 197+ * Define our own array_intersect_key function
 198+ */
 199+ function array_intersect_key( $isec, $keys ) {
 200+ $argc = func_num_args();
 201+
 202+ if ( $argc > 2 ) {
 203+ for ( $i = 1; $isec && $i < $argc; $i++ ) {
 204+ $arr = func_get_arg( $i );
 205+
 206+ foreach ( array_keys( $isec ) as $key ) {
 207+ if ( !isset( $arr[$key] ) )
 208+ unset( $isec[$key] );
 209+ }
 210+ }
 211+
 212+ return $isec;
 213+ } else {
 214+ $res = array();
 215+ foreach ( array_keys( $isec ) as $key ) {
 216+ if ( isset( $keys[$key] ) )
 217+ $res[$key] = $isec[$key];
 218+ }
 219+
 220+ return $res;
 221+ }
 222+ }
 223+}
 224+
194225 // Support for Wietse Venema's taint feature
195226 if ( !function_exists( 'istainted' ) ) {
196227 function istainted( $var ) {
Index: trunk/phase3/includes/api/ApiResult.php
@@ -315,31 +315,3 @@
316316 return __CLASS__ . ': $Id$';
317317 }
318318 }
319 -
320 -/* For compatibility with PHP versions < 5.1.0, define our own array_intersect_key function. */
321 -if ( !function_exists( 'array_intersect_key' ) ) {
322 - function array_intersect_key( $isec, $keys ) {
323 - $argc = func_num_args();
324 -
325 - if ( $argc > 2 ) {
326 - for ( $i = 1; $isec && $i < $argc; $i++ ) {
327 - $arr = func_get_arg( $i );
328 -
329 - foreach ( array_keys( $isec ) as $key ) {
330 - if ( !isset( $arr[$key] ) )
331 - unset( $isec[$key] );
332 - }
333 - }
334 -
335 - return $isec;
336 - } else {
337 - $res = array();
338 - foreach ( array_keys( $isec ) as $key ) {
339 - if ( isset( $keys[$key] ) )
340 - $res[$key] = $isec[$key];
341 - }
342 -
343 - return $res;
344 - }
345 - }
346 -}

Status & tagging log