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
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
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)) {
|
2008-04-05 18:52:33 +00:00
|
|
|
$prefix = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "(";
|
2007-05-15 18:45:20 +00:00
|
|
|
$suffix = ")";
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 14:11:20 +00:00
|
|
|
// Some versions of PHP have a broken json_encode, see PHP bug
|
|
|
|
|
// 46944. Test encoding an affected character (U+20000) to
|
|
|
|
|
// avoid this.
|
2009-03-23 19:58:07 +00:00
|
|
|
if (!function_exists('json_encode') || $this->getIsHtml() || strtolower(json_encode("\xf0\xa0\x80\x80")) != '"\ud840\udc00"') {
|
2006-10-16 00:08:03 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2007-05-15 18:45:20 +00:00
|
|
|
return array (
|
|
|
|
|
'callback' => null
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2007-05-15 18:45:20 +00:00
|
|
|
return array (
|
2008-03-03 05:45:37 +00:00
|
|
|
'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
|
2007-05-15 18:45:20 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public 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
|
|
|
}
|