r22190 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22189‎ | r22190 | r22191 >
Date:18:45, 15 May 2007
Author:yurik
Status:old
Tags:
Comment:
* API: JSON format now allows callback parameter
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatJson.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFormatJson.php
@@ -49,14 +49,35 @@
5050 }
5151
5252 public function execute() {
 53+ $prefix = $suffix = "";
 54+
 55+ $params = $this->extractRequestParams();
 56+ $callback = $params['callback'];
 57+ if(!is_null($callback)) {
 58+ $prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "(";
 59+ $suffix = ")";
 60+ }
 61+
5362 if (!function_exists('json_encode') || $this->getIsHtml()) {
5463 $json = new Services_JSON();
55 - $this->printText($json->encode($this->getResultData(), $this->getIsHtml()));
 64+ $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix);
5665 } else {
57 - $this->printText(json_encode($this->getResultData()));
 66+ $this->printText($prefix . json_encode($this->getResultData()) . $suffix);
5867 }
5968 }
6069
 70+ protected function getAllowedParams() {
 71+ return array (
 72+ 'callback' => null
 73+ );
 74+ }
 75+
 76+ protected function getParamDescription() {
 77+ return array (
 78+ 'callback' => 'If specified, wraps the output into a given function call',
 79+ );
 80+ }
 81+
6182 protected function getDescription() {
6283 if ($this->mIsRaw)
6384 return 'Output data with the debuging elements in JSON format' . parent :: getDescription();