* added content-type plain/text output param for json format
authorMichael Dale <dale@users.mediawiki.org>
Sat, 15 Aug 2009 20:24:30 +0000 (20:24 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Sat, 15 Aug 2009 20:24:30 +0000 (20:24 +0000)
* added content-type "application/json" or 'text/javascript' per callback param

includes/api/ApiFormatJson.php

index 1d7e3dc..888be28 100644 (file)
@@ -41,7 +41,16 @@ class ApiFormatJson extends ApiFormatBase {
        }
 
        public function getMimeType() {
-               return 'text/javascript';
+               $params = $this->extractRequestParams();
+               //callback:             
+               if( $params['callback']){
+                       return 'text/javascript';
+               }
+               //check for text content request                
+               if( isset( $params['ctypetext']) &&  $params['ctypetext']) {                    
+                       return 'text/plain';
+               }
+               return 'application/json';
        }
 
        public function getNeedsRawData() {
@@ -84,13 +93,15 @@ class ApiFormatJson extends ApiFormatBase {
 
        public function getAllowedParams() {
                return array (
-                       'callback' => null
+                       'callback'  => null,
+                       'ctypetext' => null             
                );
        }
 
        public function getParamDescription() {
                return array (
                        'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
+                       'ctypetext'=> 'Used to set the content type of the json result to plain-text (useful for evaling iframe uploads)',
                );
        }