Pass __METHOD__ to DatabaseBase::commit() and DatabaseBase::rollback()
[mediawiki.git] / includes / api / ApiFormatJson.php
blobe728d057a0e6cf3ea99778f30389a3ed99a8d29f
1 <?php
2 /**
5 * Created on Sep 19, 2006
7 * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * API JSON output formatter
29 * @ingroup API
31 class ApiFormatJson extends ApiFormatBase {
33 private $mIsRaw;
35 public function __construct( $main, $format ) {
36 parent::__construct( $main, $format );
37 $this->mIsRaw = ( $format === 'rawfm' );
40 public function getMimeType() {
41 $params = $this->extractRequestParams();
42 // callback:
43 if ( $params['callback'] ) {
44 return 'text/javascript';
46 return 'application/json';
49 public function getNeedsRawData() {
50 return $this->mIsRaw;
53 public function getWantsHelp() {
54 // Help is always ugly in JSON
55 return false;
58 public function execute() {
59 $prefix = $suffix = '';
61 $params = $this->extractRequestParams();
62 $callback = $params['callback'];
63 if ( !is_null( $callback ) ) {
64 $prefix = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback ) . '(';
65 $suffix = ')';
67 $this->printText(
68 $prefix .
69 FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) .
70 $suffix
74 public function getAllowedParams() {
75 return array(
76 'callback' => null,
80 public function getParamDescription() {
81 return array(
82 'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
86 public function getDescription() {
87 if ( $this->mIsRaw ) {
88 return 'Output data with the debuging elements in JSON format' . parent::getDescription();
89 } else {
90 return 'Output data in JSON format' . parent::getDescription();
94 public function getVersion() {
95 return __CLASS__ . ': $Id$';