* API: Query Meta SiteInfo module
[mediawiki.git] / api.php
blob48ae7e4485ec3dba11373c1fa98d005d671558a1
1 <?php
4 /**
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 $wgApiStartTime = microtime(true);
27 /**
28 * When no format parameter is given, this format will be used
30 define('API_DEFAULT_FORMAT', 'xmlfm');
32 /**
33 * All API classes reside in this directory
35 $wgApiDirectory = 'includes/api/';
37 /**
38 * List of classes and containing files.
40 $wgApiAutoloadClasses = array (
42 'ApiMain' => 'ApiMain.php',
44 // Utility classes
45 'ApiBase' => 'ApiBase.php',
46 'ApiQueryBase' => 'ApiQueryBase.php',
47 'ApiResult' => 'ApiResult.php',
48 'ApiPageSet' => 'ApiPageSet.php',
50 // Formats
51 'ApiFormatBase' => 'ApiFormatBase.php',
52 'ApiFormatYaml' => 'ApiFormatYaml.php',
53 'ApiFormatXml' => 'ApiFormatXml.php',
54 'ApiFormatJson' => 'ApiFormatJson.php',
56 // Modules (action=...) - should match the $apiModules list
57 'ApiHelp' => 'ApiHelp.php',
58 'ApiLogin' => 'ApiLogin.php',
59 'ApiQuery' => 'ApiQuery.php',
61 // Query items (meta/prop/list=...)
62 'ApiQuerySiteinfo' => 'ApiQuerySiteinfo.php',
63 'ApiQueryInfo' => 'ApiQueryInfo.php',
64 'ApiQueryContent' => 'ApiQueryContent.php'
67 /**
68 * List of available modules: action name => module class
69 * The class must also be listed in the $wgApiAutoloadClasses array.
71 $wgApiModules = array (
72 'help' => 'ApiHelp',
73 'login' => 'ApiLogin',
74 'query' => 'ApiQuery'
77 /**
78 * List of available formats: format name => format class
79 * The class must also be listed in the $wgApiAutoloadClasses array.
81 $wgApiFormats = array (
82 'json' => 'ApiFormatJson',
83 'jsonfm' => 'ApiFormatJson',
84 'xml' => 'ApiFormatXml',
85 'xmlfm' => 'ApiFormatXml',
86 'yaml' => 'ApiFormatYaml',
87 'yamlfm' => 'ApiFormatYaml'
90 // Initialise common code
91 require_once ('./includes/WebStart.php');
92 wfProfileIn('api.php');
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);
104 ApiInitAutoloadClasses($wgApiAutoloadClasses, $wgApiDirectory);
105 $processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
106 $processor->Execute();
108 wfProfileOut('api.php');
109 wfLogProfilingData();
110 exit; // Done!
112 function ApiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {
114 // Prefix each api class with the proper prefix,
115 // and append them to $wgAutoloadClasses
116 global $wgAutoloadClasses;
118 if (!isset ($wgAutoloadClasses))
119 $wgAutoloadClasses = array();
121 foreach ($apiAutoloadClasses as $className => $classFile)
122 $wgAutoloadClasses[$className] = $apiDirectory . $classFile;