MediaWiki  1.23.2
ApiFormatJson.php
Go to the documentation of this file.
1 <?php
32 
33  private $mIsRaw;
34 
35  public function __construct( $main, $format ) {
36  parent::__construct( $main, $format );
37  $this->mIsRaw = ( $format === 'rawfm' );
38  }
39 
40  public function getMimeType() {
41  $params = $this->extractRequestParams();
42  // callback:
43  if ( $params['callback'] ) {
44  return 'text/javascript';
45  }
46 
47  return 'application/json';
48  }
49 
50  public function getNeedsRawData() {
51  return $this->mIsRaw;
52  }
53 
54  public function getWantsHelp() {
55  // Help is always ugly in JSON
56  return false;
57  }
58 
59  public function execute() {
60  $params = $this->extractRequestParams();
61  $json = FormatJson::encode(
62  $this->getResultData(),
63  $this->getIsHtml(),
65  );
66  $callback = $params['callback'];
67  if ( $callback !== null ) {
68  $callback = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback );
69  # Prepend a comment to try to avoid attacks against content
70  # sniffers, such as bug 68187.
71  $this->printText( "/**/$callback($json)" );
72  } else {
73  $this->printText( $json );
74  }
75  }
76 
77  public function getAllowedParams() {
78  return array(
79  'callback' => null,
80  'utf8' => false,
81  );
82  }
83 
84  public function getParamDescription() {
85  return array(
86  'callback' => 'If specified, wraps the output into a given function ' .
87  'call. For safety, all user-specific data will be restricted.',
88  'utf8' => 'If specified, encodes most (but not all) non-ASCII ' .
89  'characters as UTF-8 instead of replacing them with hexadecimal escape sequences.',
90  );
91  }
92 
93  public function getDescription() {
94  if ( $this->mIsRaw ) {
95  return 'Output data with the debugging elements in JSON format' . parent::getDescription();
96  }
97 
98  return 'Output data in JSON format' . parent::getDescription();
99  }
100 }
ApiFormatJson\$mIsRaw
$mIsRaw
Definition: ApiFormatJson.php:33
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiFormatJson\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiFormatJson.php:77
FormatJson\XMLMETA_OK
const XMLMETA_OK
Skip escaping the characters '<', '>', and '&', which have special meanings in HTML and XML.
Definition: FormatJson.php:46
ApiFormatBase
This is the abstract base class for API formatters.
Definition: ApiFormatBase.php:32
$params
$params
Definition: styleTest.css.php:40
ApiFormatJson\getWantsHelp
getWantsHelp()
Whether this formatter can format the help message in a nice way.
Definition: ApiFormatJson.php:54
FormatJson\ALL_OK
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
ApiFormatJson
API JSON output formatter.
Definition: ApiFormatJson.php:31
ApiFormatJson\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiFormatJson.php:84
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:104
ApiFormatJson\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiFormatJson.php:59
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiFormatJson\getNeedsRawData
getNeedsRawData()
Whether this formatter needs raw data such as _element tags.
Definition: ApiFormatJson.php:50
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
ApiBase\getResultData
getResultData()
Get the result data array (read-only)
Definition: ApiBase.php:219
ApiFormatJson\getMimeType
getMimeType()
Overriding class returns the mime type that should be sent to the client.
Definition: ApiFormatJson.php:40
ApiFormatBase\printText
printText( $text)
The main format printing function.
Definition: ApiFormatBase.php:229
ApiFormatBase\getIsHtml
getIsHtml()
Returns true when the HTML pretty-printer should be used.
Definition: ApiFormatBase.php:97
ApiFormatJson\__construct
__construct( $main, $format)
Constructor If $format ends with 'fm', pretty-print the output in HTML.
Definition: ApiFormatJson.php:35
ApiFormatJson\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiFormatJson.php:93