Index: trunk/extensions/WikiSync/WikiSyncClient.php |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | */ |
65 | 65 | function setContext( $rc ) { |
66 | 66 | if ( is_string( $rc ) ) { |
67 | | - $rc = json_decode( $rc, true ); |
| 67 | + $rc = FormatJson::decode( $rc, true ); |
68 | 68 | } |
69 | 69 | if ( !isset( $rc['wikiroot'] ) ) { |
70 | 70 | throw new MWException( 'wikiroot is undefined in ' . __METHOD__ ); |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | function getResult( $code = null, $msg = null ) { |
175 | 175 | $this->setCode( $code, $msg ); |
176 | 176 | if ( $this->encodeResult ) { |
177 | | - return json_encode( $this->jr ); |
| 177 | + return FormatJson::encode( $this->jr ); |
178 | 178 | } else { |
179 | 179 | return $this->jr; |
180 | 180 | } |
— | — | @@ -297,7 +297,7 @@ |
298 | 298 | if ( $snoopy->error != '' ) { |
299 | 299 | return $json_result->getResult( 'http', $snoopy->error ); |
300 | 300 | } |
301 | | - $response = json_decode( $snoopy->results ); |
| 301 | + $response = FormatJson::decode( $snoopy->results ); |
302 | 302 | # proxy returned html instead of json ? |
303 | 303 | if ( $response === null ) { |
304 | 304 | return $json_result->getResult( 'http' ); |
— | — | @@ -325,7 +325,7 @@ |
326 | 326 | if ( $snoopy->error != '' ) { |
327 | 327 | return $json_result->getResult( 'http', $snoopy->error ); |
328 | 328 | } |
329 | | - $response = json_decode( $snoopy->results ); |
| 329 | + $response = FormatJson::decode( $snoopy->results ); |
330 | 330 | # proxy returned html instead of json ? |
331 | 331 | if ( $response === null ) { |
332 | 332 | return $json_result->getResult( 'http' ); |
— | — | @@ -354,7 +354,7 @@ |
355 | 355 | */ |
356 | 356 | static function localAPIwrap( $api_params ) { |
357 | 357 | if ( is_string( $api_params ) ) { |
358 | | - $api_params = json_decode( $api_params, true ); |
| 358 | + $api_params = FormatJson::decode( $api_params, true ); |
359 | 359 | } |
360 | 360 | $req = new FauxRequest( $api_params ); |
361 | 361 | $api = new ApiMain( $req ); |
— | — | @@ -385,7 +385,7 @@ |
386 | 386 | # not enough priviledges to run this method |
387 | 387 | return $json_result->getResult( 'noaccess', $iu ); |
388 | 388 | } |
389 | | - $api_params = is_array( $args[0] ) ? $args[0] : json_decode( $args[0], true ); |
| 389 | + $api_params = is_array( $args[0] ) ? $args[0] : FormatJson::decode( $args[0], true ); |
390 | 390 | try { |
391 | 391 | $response = self::localAPIwrap( $api_params ); |
392 | 392 | } catch ( Exception $e ) { |
— | — | @@ -434,7 +434,7 @@ |
435 | 435 | return $json_result->getResult( 'noaccess', $iu ); |
436 | 436 | } |
437 | 437 | # snoopy api_params are associative array |
438 | | - $api_params = is_array( $args[1] ) ? $args[1] : json_decode( $args[1], true ); |
| 438 | + $api_params = is_array( $args[1] ) ? $args[1] : FormatJson::decode( $args[1], true ); |
439 | 439 | $snoopy = new WikiSnoopy(); |
440 | 440 | $snoopy->setContext( $args[0] ); |
441 | 441 | # we always use POST method because it's less often cached by proxies |
— | — | @@ -453,7 +453,7 @@ |
454 | 454 | if ( $resultEncoding == self::RESULT_SNOOPY ) { |
455 | 455 | return $snoopy; |
456 | 456 | } |
457 | | - $response = json_decode( $snoopy->results, true ); |
| 457 | + $response = FormatJson::decode( $snoopy->results, true ); |
458 | 458 | # proxy returned html instead of json ? |
459 | 459 | if ( $response === null ) { |
460 | 460 | return $json_result->getResult( 'http' ); |
— | — | @@ -514,7 +514,7 @@ |
515 | 515 | } |
516 | 516 | # remote context; used for remote API calls |
517 | 517 | self::$remoteContextJSON = $args[0]; |
518 | | - self::$client_params = json_decode( $args[1], true ); |
| 518 | + self::$client_params = FormatJson::decode( $args[1], true ); |
519 | 519 | if ( ($check_result = self::checkClientParameters( $client_name )) !== true ) { |
520 | 520 | self::$json_result->setCode( 'init_client', $check_result ); |
521 | 521 | return false; |
— | — | @@ -631,7 +631,7 @@ |
632 | 632 | $result = self::sourceAPIget( $APIparams ); |
633 | 633 | if ( $result['ws_status'] === '0' ) { |
634 | 634 | $result['ws_msg'] = 'source: ' . $result['ws_msg'] . ' (' . __METHOD__ . ')'; |
635 | | - return json_encode( $result ); |
| 635 | + return FormatJson::encode( $result ); |
636 | 636 | } |
637 | 637 | # collect the file titles existed in current chunk's revisions |
638 | 638 | $files = array(); |
— | — | @@ -649,7 +649,7 @@ |
650 | 650 | $result = self::importXML( $client_params['dst_import_token'], $result['query']['exportxml'] ); |
651 | 651 | if ( $result['ws_status'] === '0' ) { |
652 | 652 | $result['ws_msg'] = 'destination: ' . $result['ws_msg'] . ' (' . __METHOD__ . ')'; |
653 | | - return json_encode( $result ); |
| 653 | + return FormatJson::encode( $result ); |
654 | 654 | } |
655 | 655 | $json_result->setStatus( '1' ); // API success |
656 | 656 | return $json_result->getResult(); |
— | — | @@ -700,7 +700,7 @@ |
701 | 701 | !isset( $src_result['query'] ) || |
702 | 702 | !isset( $src_result['query']['pages'] ) ) { |
703 | 703 | $src_result['ws_msg'] = 'source: ' . $src_result['ws_msg'] . ' (' . __METHOD__ . ')'; |
704 | | - return json_encode( $src_result ); |
| 704 | + return FormatJson::encode( $src_result ); |
705 | 705 | } |
706 | 706 | $src_result = self::transformImageInfoResult( $src_result ); |
707 | 707 | $dst_result = self::destinationAPIget( $APIparams ); |
— | — | @@ -708,7 +708,7 @@ |
709 | 709 | !isset( $dst_result['query'] ) || |
710 | 710 | !isset( $dst_result['query']['pages'] ) ) { |
711 | 711 | $dst_result['ws_msg'] = 'destination: ' . $dst_result['ws_msg'] . ' (' . __METHOD__ . ')'; |
712 | | - return json_encode( $dst_result ); |
| 712 | + return FormatJson::encode( $dst_result ); |
713 | 713 | } |
714 | 714 | $dst_result = self::transformImageInfoResult( $dst_result ); |
715 | 715 | $new_files = array(); |
Index: trunk/extensions/WikiSync/WikiSync.php |
— | — | @@ -54,24 +54,6 @@ |
55 | 55 | |
56 | 56 | WikiSyncSetup::init(); |
57 | 57 | |
58 | | -if ( !function_exists( 'json_decode' ) ) { |
59 | | - function json_decode( $content, $assoc = false ) { |
60 | | - if ( $assoc ) { |
61 | | - $json = new Services_JSON( SERVICES_JSON_LOOSE_TYPE ); |
62 | | - } else { |
63 | | - $json = new Services_JSON; |
64 | | - } |
65 | | - return $json->decode( $content ); |
66 | | - } |
67 | | -} |
68 | | - |
69 | | -if ( !function_exists( 'json_encode' ) ) { |
70 | | - function json_encode( $content ) { |
71 | | - $json = new Services_JSON; |
72 | | - return $json->encode($content); |
73 | | - } |
74 | | -} |
75 | | - |
76 | 58 | class WikiSyncSetup { |
77 | 59 | |
78 | 60 | const COOKIE_EXPIRE_TIME = 2592000; // 60 * 60 * 24 * 30; see also WikiSync.js, WikiSync.cookieExpireTime |
— | — | @@ -135,7 +117,6 @@ |
136 | 118 | $wgAutoloadClasses['_QXML'] = self::$ExtDir . '/WikiSyncBasic.php'; |
137 | 119 | } |
138 | 120 | $wgAutoloadClasses['Snoopy'] = self::$ExtDir . '/Snoopy/Snoopy.class.php'; |
139 | | - $wgAutoloadClasses['Services_JSON'] = self::$ExtDir . '/pear/JSON.php'; |
140 | 121 | $wgAutoloadClasses['WikiSyncSetup'] = self::$ExtDir . '/WikiSync.php'; |
141 | 122 | $wgAutoloadClasses['WikiSnoopy'] = |
142 | 123 | $wgAutoloadClasses['WikiSyncJSONresult'] = |
— | — | @@ -234,7 +215,7 @@ |
235 | 216 | $arg = self::JS_MSG_PREFIX . $arg; |
236 | 217 | $result[$arg] = wfMsg( $arg ); |
237 | 218 | } |
238 | | - return json_encode( $result ); |
| 219 | + return FormatJson::encode( $result ); |
239 | 220 | } |
240 | 221 | |
241 | 222 | static function checkUserMembership( $groups ) { |