2006-09-08 14:27:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2006-09-26 01:44:13 +00:00
|
|
|
$wgApiStartTime = microtime(true);
|
2006-09-08 14:27:58 +00:00
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* When no format parameter is given, this format will be used
|
|
|
|
|
*/
|
|
|
|
|
define('API_DEFAULT_FORMAT', 'xmlfm');
|
|
|
|
|
|
2006-09-08 14:27:58 +00:00
|
|
|
/**
|
|
|
|
|
* List of classes and containing files.
|
|
|
|
|
*/
|
2006-09-26 01:44:13 +00:00
|
|
|
$wgApiAutoloadClasses = array (
|
2006-09-25 04:12:07 +00:00
|
|
|
|
2006-09-26 01:44:13 +00:00
|
|
|
'ApiMain' => 'ApiMain.php',
|
2006-09-25 04:12:07 +00:00
|
|
|
|
|
|
|
|
// Utility classes
|
2006-09-26 01:44:13 +00:00
|
|
|
'ApiBase' => 'ApiBase.php',
|
|
|
|
|
'ApiQueryBase' => 'ApiQueryBase.php',
|
|
|
|
|
'ApiResult' => 'ApiResult.php',
|
|
|
|
|
'ApiPageSet' => 'ApiPageSet.php',
|
2006-09-25 04:12:07 +00:00
|
|
|
|
|
|
|
|
// Formats
|
2006-09-26 01:44:13 +00:00
|
|
|
'ApiFormatBase' => 'ApiFormatBase.php',
|
|
|
|
|
'ApiFormatYaml' => 'ApiFormatYaml.php',
|
|
|
|
|
'ApiFormatXml' => 'ApiFormatXml.php',
|
|
|
|
|
'ApiFormatJson' => 'ApiFormatJson.php',
|
2006-09-25 04:12:07 +00:00
|
|
|
|
|
|
|
|
// Modules (action=...) - should match the $apiModules list
|
2006-09-26 01:44:13 +00:00
|
|
|
'ApiHelp' => 'ApiHelp.php',
|
|
|
|
|
'ApiLogin' => 'ApiLogin.php',
|
|
|
|
|
'ApiQuery' => 'ApiQuery.php',
|
|
|
|
|
|
|
|
|
|
// Query items (meta/prop/list=...)
|
|
|
|
|
'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php',
|
|
|
|
|
'ApiQueryInfo' => 'ApiQueryInfo.php',
|
2006-09-26 05:43:02 +00:00
|
|
|
'ApiQueryRevisions' => 'ApiQueryRevisions.php',
|
2006-09-26 06:37:26 +00:00
|
|
|
'ApiQueryAllpages' => 'ApiQueryAllpages.php'
|
2006-09-08 14:27:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of available modules: action name => module class
|
2006-09-26 01:44:13 +00:00
|
|
|
* The class must also be listed in the $wgApiAutoloadClasses array.
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2006-09-26 01:44:13 +00:00
|
|
|
$wgApiModules = array (
|
2006-09-08 14:27:58 +00:00
|
|
|
'help' => 'ApiHelp',
|
|
|
|
|
'login' => 'ApiLogin',
|
|
|
|
|
'query' => 'ApiQuery'
|
|
|
|
|
);
|
|
|
|
|
|
2006-09-25 04:12:07 +00:00
|
|
|
/**
|
|
|
|
|
* List of available formats: format name => format class
|
2006-09-26 01:44:13 +00:00
|
|
|
* The class must also be listed in the $wgApiAutoloadClasses array.
|
2006-09-25 04:12:07 +00:00
|
|
|
*/
|
2006-09-26 01:44:13 +00:00
|
|
|
$wgApiFormats = array (
|
2006-09-25 04:12:07 +00:00
|
|
|
'json' => 'ApiFormatJson',
|
|
|
|
|
'jsonfm' => 'ApiFormatJson',
|
|
|
|
|
'xml' => 'ApiFormatXml',
|
|
|
|
|
'xmlfm' => 'ApiFormatXml',
|
|
|
|
|
'yaml' => 'ApiFormatYaml',
|
|
|
|
|
'yamlfm' => 'ApiFormatYaml'
|
|
|
|
|
);
|
2006-09-08 14:27:58 +00:00
|
|
|
|
|
|
|
|
// Initialise common code
|
2006-10-01 02:02:13 +00:00
|
|
|
require (dirname(__FILE__) . '/includes/WebStart.php');
|
2006-09-08 14:27:58 +00:00
|
|
|
wfProfileIn('api.php');
|
|
|
|
|
|
|
|
|
|
// Verify that the API has not been disabled
|
|
|
|
|
// The next line should be
|
|
|
|
|
// if (isset ($wgEnableAPI) && !$wgEnableAPI) {
|
|
|
|
|
// but will be in a safe mode until api is stabler
|
|
|
|
|
if (!isset ($wgEnableAPI) || !$wgEnableAPI) {
|
|
|
|
|
echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
|
|
|
|
|
echo '<pre><b>$wgEnableAPI=true;</b></pre>';
|
|
|
|
|
die(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
apiInitAutoloadClasses($wgApiAutoloadClasses, "$IP/includes/api/");
|
2006-09-26 01:44:13 +00:00
|
|
|
$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
|
2006-09-27 05:13:48 +00:00
|
|
|
$processor->execute();
|
2006-09-08 14:27:58 +00:00
|
|
|
|
|
|
|
|
wfProfileOut('api.php');
|
|
|
|
|
wfLogProfilingData();
|
|
|
|
|
exit; // Done!
|
|
|
|
|
|
2006-09-27 05:13:48 +00:00
|
|
|
function apiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {
|
2006-09-08 14:27:58 +00:00
|
|
|
|
2006-09-26 01:44:13 +00:00
|
|
|
// Prefix each api class with the proper prefix,
|
|
|
|
|
// and append them to $wgAutoloadClasses
|
2006-09-08 14:27:58 +00:00
|
|
|
global $wgAutoloadClasses;
|
2006-09-26 06:37:26 +00:00
|
|
|
|
2006-09-26 01:44:13 +00:00
|
|
|
foreach ($apiAutoloadClasses as $className => $classFile)
|
|
|
|
|
$wgAutoloadClasses[$className] = $apiDirectory . $classFile;
|
2006-09-08 14:27:58 +00:00
|
|
|
}
|
2006-10-01 02:02:13 +00:00
|
|
|
?>
|