00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( 'ApiFormatBase.php' );
00029 }
00030
00034 class ApiFormatJson extends ApiFormatBase {
00035
00036 private $mIsRaw;
00037
00038 public function __construct( $main, $format ) {
00039 parent :: __construct( $main, $format );
00040 $this->mIsRaw = ( $format === 'rawfm' );
00041 }
00042
00043 public function getMimeType() {
00044 $params = $this->extractRequestParams();
00045
00046 if ( $params['callback'] ) {
00047 return 'text/javascript';
00048 }
00049 return 'application/json';
00050 }
00051
00052 public function getNeedsRawData() {
00053 return $this->mIsRaw;
00054 }
00055
00056 public function getWantsHelp() {
00057
00058 return false;
00059 }
00060
00061 public function execute() {
00062 $prefix = $suffix = "";
00063
00064 $params = $this->extractRequestParams();
00065 $callback = $params['callback'];
00066 if ( !is_null( $callback ) ) {
00067 $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "(";
00068 $suffix = ")";
00069 }
00070 $this->printText(
00071 $prefix .
00072 FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) .
00073 $suffix );
00074 }
00075
00076 public function getAllowedParams() {
00077 return array (
00078 'callback' => null,
00079 );
00080 }
00081
00082 public function getParamDescription() {
00083 return array (
00084 'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
00085 );
00086 }
00087
00088 public function getDescription() {
00089 if ( $this->mIsRaw )
00090 return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
00091 else
00092 return 'Output data in JSON format' . parent :: getDescription();
00093 }
00094
00095 public function getVersion() {
00096 return __CLASS__ . ': $Id: ApiFormatJson.php 62354 2010-02-12 06:44:16Z mah $';
00097 }
00098 }