]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiFormatJson.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiFormatJson.php
index ed9bd938f14120dcf30e8529944fb3fa755536e1..1d89eb186ebaed174f460f55588c87215b5d00e7 100644 (file)
@@ -29,7 +29,7 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * @addtogroup API
+ * @ingroup API
  */
 class ApiFormatJson extends ApiFormatBase {
 
@@ -54,11 +54,14 @@ class ApiFormatJson extends ApiFormatBase {
                $params = $this->extractRequestParams();
                $callback = $params['callback'];
                if(!is_null($callback)) {
-                       $prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "(";
+                       $prefix = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "(";
                        $suffix = ")";
                }
 
-               if (!function_exists('json_encode') || $this->getIsHtml()) {
+               // Some versions of PHP have a broken json_encode, see PHP bug 
+               // 46944. Test encoding an affected character (U+20000) to 
+               // avoid this.
+               if (!function_exists('json_encode') || $this->getIsHtml() || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') {
                        $json = new Services_JSON();
                        $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix);
                } else {
@@ -66,19 +69,19 @@ class ApiFormatJson extends ApiFormatBase {
                }
        }
 
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array (
                        'callback' => null
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array (
-                       'callback' => 'If specified, wraps the output into a given function call',
+                       'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
                );
        }
 
-       protected function getDescription() {
+       public function getDescription() {
                if ($this->mIsRaw)
                        return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
                else
@@ -86,7 +89,6 @@ class ApiFormatJson extends ApiFormatBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiFormatJson.php 23531 2007-06-29 01:19:14Z simetrical $';
+               return __CLASS__ . ': $Id: ApiFormatJson.php 45682 2009-01-12 19:06:33Z raymond $';
        }
 }
-