* API: Query Meta SiteInfo module
[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 * All API classes reside in this directory
34 */
35 $wgApiDirectory = 'includes/api/';
36
37 /**
38 * List of classes and containing files.
39 */
40 $wgApiAutoloadClasses = array (
41
42 'ApiMain' => 'ApiMain.php',
43
44 // Utility classes
45 'ApiBase' => 'ApiBase.php',
46 'ApiQueryBase' => 'ApiQueryBase.php',
47 'ApiResult' => 'ApiResult.php',
48 'ApiPageSet' => 'ApiPageSet.php',
49
50 // Formats
51 'ApiFormatBase' => 'ApiFormatBase.php',
52 'ApiFormatYaml' => 'ApiFormatYaml.php',
53 'ApiFormatXml' => 'ApiFormatXml.php',
54 'ApiFormatJson' => 'ApiFormatJson.php',
55
56 // Modules (action=...) - should match the $apiModules list
57 'ApiHelp' => 'ApiHelp.php',
58 'ApiLogin' => 'ApiLogin.php',
59 'ApiQuery' => 'ApiQuery.php',
60
61 // Query items (meta/prop/list=...)
62 'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php',
63 'ApiQueryInfo' => 'ApiQueryInfo.php',
64 'ApiQueryContent' => 'ApiQueryContent.php'
65 );
66
67 /**
68 * List of available modules: action name => module class
69 * The class must also be listed in the $wgApiAutoloadClasses array.
70 */
71 $wgApiModules = array (
72 'help' => 'ApiHelp',
73 'login' => 'ApiLogin',
74 'query' => 'ApiQuery'
75 );
76
77 /**
78 * List of available formats: format name => format class
79 * The class must also be listed in the $wgApiAutoloadClasses array.
80 */
81 $wgApiFormats = array (
82 'json' => 'ApiFormatJson',
83 'jsonfm' => 'ApiFormatJson',
84 'xml' => 'ApiFormatXml',
85 'xmlfm' => 'ApiFormatXml',
86 'yaml' => 'ApiFormatYaml',
87 'yamlfm' => 'ApiFormatYaml'
88 );
89
90 // Initialise common code
91 require_once ('./includes/WebStart.php');
92 wfProfileIn('api.php');
93
94 // Verify that the API has not been disabled
95 // The next line should be
96 // if (isset ($wgEnableAPI) && !$wgEnableAPI) {
97 // but will be in a safe mode until api is stabler
98 if (!isset ($wgEnableAPI) || !$wgEnableAPI) {
99 echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
100 echo '<pre><b>$wgEnableAPI=true;</b></pre>';
101 die(-1);
102 }
103
104 ApiInitAutoloadClasses($wgApiAutoloadClasses, $wgApiDirectory);
105 $processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
106 $processor->Execute();
107
108 wfProfileOut('api.php');
109 wfLogProfilingData();
110 exit; // Done!
111
112 function ApiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {
113
114 // Prefix each api class with the proper prefix,
115 // and append them to $wgAutoloadClasses
116 global $wgAutoloadClasses;
117
118 if (!isset ($wgAutoloadClasses))
119 $wgAutoloadClasses = array();
120
121 foreach ($apiAutoloadClasses as $className => $classFile)
122 $wgAutoloadClasses[$className] = $apiDirectory . $classFile;
123 }
124 ?>