4 * API for MediaWiki 1.8+
6 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * http://www.gnu.org/copyleft/gpl.html
25 * This file is the entry point for all API queries. It begins by checking
26 * whether the API is enabled on this wiki; if not, it informs the user that
27 * s/he should set $wgEnableAPI to true and exits. Otherwise, it constructs
28 * a new ApiMain using the parameter passed to it as an argument in the URL
29 * ('?action=') and with write-enabled set to the value of $wgEnableWriteAPI
30 * as specified in LocalSettings.php. It then invokes "execute()" on the
31 * ApiMain object instance, which produces output in the format sepecified
35 // Initialise common code
36 require (dirname(__FILE__
) . '/includes/WebStart.php');
38 wfProfileIn('api.php');
42 // See RawPage.php for details; summary is that MSIE can override the
43 // Content-Type if it sees a recognized extension on the URL, such as
44 // might be appended via PATH_INFO after 'api.php'.
46 // Some data formats can end up containing unfiltered user-provided data
47 // which will end up triggering HTML detection and execution, hence
48 // XSS injection and all that entails.
50 // Ensure that all access is through the canonical entry point...
52 if( isset( $_SERVER['SCRIPT_URL'] ) ) {
53 $url = $_SERVER['SCRIPT_URL'];
55 $url = $_SERVER['PHP_SELF'];
57 if( strcmp( "$wgScriptPath/api$wgScriptExtension", $url ) ) {
58 wfHttpError( 403, 'Forbidden',
59 'API must be accessed through the primary script entry point.' );
63 // Verify that the API has not been disabled
65 echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
66 echo '<pre><b>$wgEnableAPI=true;</b></pre>';
70 /* Construct an ApiMain with the arguments passed via the URL. What we get back
71 * is some form of an ApiMain, possibly even one that produces an error message,
72 * but we don't care here, as that is handled by the ctor.
74 $processor = new ApiMain($wgRequest, $wgEnableWriteAPI);
76 // Process data & print results
77 $processor->execute();
79 // Execute any deferred updates
82 // Log what the user did, for book-keeping purposes.
83 wfProfileOut('api.php');
86 // Shut down the database
87 wfGetLBFactory()->shutdown();