MediaWiki  1.23.0
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  $this->printText( "$callback($json)" );
70  } else {
71  $this->printText( $json );
72  }
73  }
74 
75  public function getAllowedParams() {
76  return array(
77  'callback' => null,
78  'utf8' => false,
79  );
80  }
81 
82  public function getParamDescription() {
83  return array(
84  'callback' => 'If specified, wraps the output into a given function ' .
85  'call. For safety, all user-specific data will be restricted.',
86  'utf8' => 'If specified, encodes most (but not all) non-ASCII ' .
87  'characters as UTF-8 instead of replacing them with hexadecimal escape sequences.',
88  );
89  }
90 
91  public function getDescription() {
92  if ( $this->mIsRaw ) {
93  return 'Output data with the debugging elements in JSON format' . parent::getDescription();
94  }
95 
96  return 'Output data in JSON format' . parent::getDescription();
97  }
98 }
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:75
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:82
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:91