2006-09-23 15:57:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Sep 19, 2006
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2007-05-20 23:31:44 +00:00
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
|
2006-09-23 15:57:16 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
|
|
|
|
// Eclipse helper - will be ignored in production
|
2006-10-01 02:02:13 +00:00
|
|
|
require_once ('ApiFormatBase.php');
|
2006-09-23 15:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
|
|
|
|
* @addtogroup API
|
|
|
|
|
*/
|
2006-09-23 15:57:16 +00:00
|
|
|
class ApiFormatJson extends ApiFormatBase {
|
|
|
|
|
|
2006-10-17 02:01:20 +00:00
|
|
|
private $mIsRaw;
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2006-09-23 15:57:16 +00:00
|
|
|
public function __construct($main, $format) {
|
|
|
|
|
parent :: __construct($main, $format);
|
2006-11-03 06:53:47 +00:00
|
|
|
$this->mIsRaw = ($format === 'rawfm');
|
2006-09-23 15:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
public function getMimeType() {
|
2006-09-23 15:57:16 +00:00
|
|
|
return 'application/json';
|
|
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2006-10-17 02:01:20 +00:00
|
|
|
public function getNeedsRawData() {
|
|
|
|
|
return $this->mIsRaw;
|
|
|
|
|
}
|
2006-11-03 06:53:47 +00:00
|
|
|
|
2006-10-15 07:43:52 +00:00
|
|
|
public function execute() {
|
2007-05-15 18:45:20 +00:00
|
|
|
$prefix = $suffix = "";
|
|
|
|
|
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
$callback = $params['callback'];
|
|
|
|
|
if(!is_null($callback)) {
|
|
|
|
|
$prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "(";
|
|
|
|
|
$suffix = ")";
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-16 00:08:03 +00:00
|
|
|
if (!function_exists('json_encode') || $this->getIsHtml()) {
|
|
|
|
|
$json = new Services_JSON();
|
2007-05-15 18:45:20 +00:00
|
|
|
$this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix);
|
2006-10-16 00:08:03 +00:00
|
|
|
} else {
|
2007-05-15 18:45:20 +00:00
|
|
|
$this->printText($prefix . json_encode($this->getResultData()) . $suffix);
|
2006-10-16 00:08:03 +00:00
|
|
|
}
|
2006-09-23 15:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-15 18:45:20 +00:00
|
|
|
protected function getAllowedParams() {
|
|
|
|
|
return array (
|
|
|
|
|
'callback' => null
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getParamDescription() {
|
|
|
|
|
return array (
|
|
|
|
|
'callback' => 'If specified, wraps the output into a given function call',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
protected function getDescription() {
|
2006-11-03 06:53:47 +00:00
|
|
|
if ($this->mIsRaw)
|
|
|
|
|
return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
|
|
|
|
|
else
|
|
|
|
|
return 'Output data in JSON format' . parent :: getDescription();
|
2006-09-23 15:57:16 +00:00
|
|
|
}
|
2006-10-01 21:20:55 +00:00
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
|
}
|
2006-09-23 15:57:16 +00:00
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|