5 * API for MediaWiki 1.8+
7 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 $apiStartTime = microtime(true);
28 * When no format parameter is given, this format will be used
30 define('API_DEFAULT_FORMAT', 'xmlfm');
32 $apidir = 'includes/api';
34 * List of classes and containing files.
36 $apiAutoloadClasses = array (
38 'ApiMain' => "$apidir/ApiMain.php",
41 'ApiBase' => "$apidir/ApiBase.php",
42 'ApiQueryBase' => "$apidir/ApiQueryBase.php",
43 'ApiResult' => "$apidir/ApiResult.php",
46 'ApiFormatBase' => "$apidir/ApiFormatBase.php",
47 'ApiFormatYaml' => "$apidir/ApiFormatYaml.php",
48 'ApiFormatXml' => "$apidir/ApiFormatXml.php",
49 'ApiFormatJson' => "$apidir/ApiFormatJson.php",
51 // Modules (action=...) - should match the $apiModules list
52 'ApiHelp' => "$apidir/ApiHelp.php",
53 'ApiLogin' => "$apidir/ApiLogin.php",
54 'ApiQuery' => "$apidir/ApiQuery.php",
56 // Query items (what/list=...)
57 'ApiQueryContent' => "$apidir/ApiQueryContent.php",
59 'ApiPageSet' => "$apidir/ApiPageSet.php"
63 * List of available modules: action name => module class
64 * The class must also be listed in the $apiAutoloadClasses array.
68 'login' => 'ApiLogin',
73 * List of available formats: format name => format class
74 * The class must also be listed in the $apiAutoloadClasses array.
77 'json' => 'ApiFormatJson',
78 'jsonfm' => 'ApiFormatJson',
79 'xml' => 'ApiFormatXml',
80 'xmlfm' => 'ApiFormatXml',
81 'yaml' => 'ApiFormatYaml',
82 'yamlfm' => 'ApiFormatYaml'
85 // Initialise common code
86 require_once ('./includes/WebStart.php');
87 wfProfileIn('api.php');
89 // Verify that the API has not been disabled
90 // The next line should be
91 // if (isset ($wgEnableAPI) && !$wgEnableAPI) {
92 // but will be in a safe mode until api is stabler
93 if (!isset ($wgEnableAPI) ||
!$wgEnableAPI) {
94 echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
95 echo '<pre><b>$wgEnableAPI=true;</b></pre>';
99 ApiInitAutoloadClasses($apiAutoloadClasses);
100 $processor = new ApiMain($apiStartTime, $apiModules, $apiFormats);
101 $processor->Execute();
103 wfProfileOut('api.php');
104 wfLogProfilingData();
107 function ApiInitAutoloadClasses($apiAutoloadClasses) {
109 // Append $apiAutoloadClasses to $wgAutoloadClasses
110 global $wgAutoloadClasses;
111 if (isset ($wgAutoloadClasses)) {
112 $wgAutoloadClasses = array_merge($wgAutoloadClasses, $apiAutoloadClasses);
114 $wgAutoloadClasses = $apiAutoloadClasses;