* API: Refactored per brion's suggestions
[lhc/web/wiklou.git] / api.php
1 <?php
2
3
4 /**
5 * API for MediaWiki 1.8+
6 *
7 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
8 *
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.
13 *
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.
18 *
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
23 */
24
25 $wgApiStartTime = microtime(true);
26
27 /**
28 * When no format parameter is given, this format will be used
29 */
30 define('API_DEFAULT_FORMAT', 'xmlfm');
31
32 /**
33 * List of classes and containing files.
34 */
35 $wgApiAutoloadClasses = array (
36
37 'ApiMain' => 'ApiMain.php',
38
39 // Utility classes
40 'ApiBase' => 'ApiBase.php',
41 'ApiQueryBase' => 'ApiQueryBase.php',
42 'ApiResult' => 'ApiResult.php',
43 'ApiPageSet' => 'ApiPageSet.php',
44
45 // Formats
46 'ApiFormatBase' => 'ApiFormatBase.php',
47 'ApiFormatYaml' => 'ApiFormatYaml.php',
48 'ApiFormatXml' => 'ApiFormatXml.php',
49 'ApiFormatJson' => 'ApiFormatJson.php',
50
51 // Modules (action=...) - should match the $apiModules list
52 'ApiHelp' => 'ApiHelp.php',
53 'ApiLogin' => 'ApiLogin.php',
54 'ApiQuery' => 'ApiQuery.php',
55
56 // Query items (meta/prop/list=...)
57 'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php',
58 'ApiQueryInfo' => 'ApiQueryInfo.php',
59 'ApiQueryRevisions' => 'ApiQueryRevisions.php',
60 'ApiQueryAllpages' => 'ApiQueryAllpages.php'
61 );
62
63 /**
64 * List of available modules: action name => module class
65 * The class must also be listed in the $wgApiAutoloadClasses array.
66 */
67 $wgApiModules = array (
68 'help' => 'ApiHelp',
69 'login' => 'ApiLogin',
70 'query' => 'ApiQuery'
71 );
72
73 /**
74 * List of available formats: format name => format class
75 * The class must also be listed in the $wgApiAutoloadClasses array.
76 */
77 $wgApiFormats = array (
78 'json' => 'ApiFormatJson',
79 'jsonfm' => 'ApiFormatJson',
80 'xml' => 'ApiFormatXml',
81 'xmlfm' => 'ApiFormatXml',
82 'yaml' => 'ApiFormatYaml',
83 'yamlfm' => 'ApiFormatYaml'
84 );
85
86 // Initialise common code
87 require (dirname(__FILE__) . "/includes/WebStart.php");
88 wfProfileIn('api.php');
89
90 // Verify that the API has not been disabled
91 // The next line should be
92 // if (isset ($wgEnableAPI) && !$wgEnableAPI) {
93 // but will be in a safe mode until api is stabler
94 if (!isset ($wgEnableAPI) || !$wgEnableAPI) {
95 echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
96 echo '<pre><b>$wgEnableAPI=true;</b></pre>';
97 die(-1);
98 }
99
100 apiInitAutoloadClasses($wgApiAutoloadClasses, "$IP/includes/api/");
101 $processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
102 $processor->execute();
103
104 wfProfileOut('api.php');
105 wfLogProfilingData();
106 exit; // Done!
107
108 function apiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {
109
110 // Prefix each api class with the proper prefix,
111 // and append them to $wgAutoloadClasses
112 global $wgAutoloadClasses;
113
114 foreach ($apiAutoloadClasses as $className => $classFile)
115 $wgAutoloadClasses[$className] = $apiDirectory . $classFile;
116 }
117 ?>