* API: A new ApiPageSet class to retrieve page data and resolve redirects.
[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 $apiStartTime = 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 $apidir = 'includes/api';
33 /**
34 * List of classes and containing files.
35 */
36 $apiAutoloadClasses = array (
37
38 'ApiMain' => "$apidir/ApiMain.php",
39
40 // Utility classes
41 'ApiBase' => "$apidir/ApiBase.php",
42 'ApiQueryBase' => "$apidir/ApiQueryBase.php",
43 'ApiResult' => "$apidir/ApiResult.php",
44
45 // Formats
46 'ApiFormatBase' => "$apidir/ApiFormatBase.php",
47 'ApiFormatYaml' => "$apidir/ApiFormatYaml.php",
48 'ApiFormatXml' => "$apidir/ApiFormatXml.php",
49 'ApiFormatJson' => "$apidir/ApiFormatJson.php",
50
51 // Modules (action=...) - should match the $apiModules list
52 'ApiHelp' => "$apidir/ApiHelp.php",
53 'ApiLogin' => "$apidir/ApiLogin.php",
54 'ApiQuery' => "$apidir/ApiQuery.php",
55
56 // Query items (what/list=...)
57 'ApiQueryContent' => "$apidir/ApiQueryContent.php",
58
59 'ApiPageSet' => "$apidir/ApiPageSet.php"
60 );
61
62 /**
63 * List of available modules: action name => module class
64 * The class must also be listed in the $apiAutoloadClasses array.
65 */
66 $apiModules = array (
67 'help' => 'ApiHelp',
68 'login' => 'ApiLogin',
69 'query' => 'ApiQuery'
70 );
71
72 /**
73 * List of available formats: format name => format class
74 * The class must also be listed in the $apiAutoloadClasses array.
75 */
76 $apiFormats = array (
77 'json' => 'ApiFormatJson',
78 'jsonfm' => 'ApiFormatJson',
79 'xml' => 'ApiFormatXml',
80 'xmlfm' => 'ApiFormatXml',
81 'yaml' => 'ApiFormatYaml',
82 'yamlfm' => 'ApiFormatYaml'
83 );
84
85 // Initialise common code
86 require_once ('./includes/WebStart.php');
87 wfProfileIn('api.php');
88
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>';
96 die(-1);
97 }
98
99 ApiInitAutoloadClasses($apiAutoloadClasses);
100 $processor = new ApiMain($apiStartTime, $apiModules, $apiFormats);
101 $processor->Execute();
102
103 wfProfileOut('api.php');
104 wfLogProfilingData();
105 exit; // Done!
106
107 function ApiInitAutoloadClasses($apiAutoloadClasses) {
108
109 // Append $apiAutoloadClasses to $wgAutoloadClasses
110 global $wgAutoloadClasses;
111 if (isset ($wgAutoloadClasses)) {
112 $wgAutoloadClasses = array_merge($wgAutoloadClasses, $apiAutoloadClasses);
113 } else {
114 $wgAutoloadClasses = $apiAutoloadClasses;
115 }
116 }
117 ?>