43 define(
'MW_API',
true );
44 define(
'MW_ENTRY_POINT',
'api' );
46 require __DIR__ .
'/includes/WebStart.php';
53 $starttime = microtime(
true );
55 $services = MediaWikiServices::getInstance();
59 if ( isset( $_SERVER[
'PATH_INFO'] ) && $_SERVER[
'PATH_INFO'] !=
'' ) {
61 $correctUrl = (string)$services->getUrlUtils()->expand( $correctUrl,
PROTO_CANONICAL );
62 header(
"Location: $correctUrl",
true, 301 );
63 echo
'This endpoint does not support "path info", i.e. extra text between "api.php"'
64 .
'and the "?". Remove any such text and try again.';
70 $wgTitle = Title::makeTitle(
NS_SPECIAL,
'Badtitle/dummy title for API calls set in api.php' );
83 (
new HookRunner( $services->getHookContainer() ) )->onApiBeforeMain( $processor );
84 if ( !$processor instanceof
ApiMain ) {
85 throw new LogicException(
'ApiBeforeMain hook set $processor to a non-ApiMain class' );
87 }
catch ( Throwable $e ) {
95 $processor->execute();
99 $endtime = microtime(
true );
105 $endtime - $starttime,
109 $items[] =
$wgRequest->wasPosted() ?
'POST' :
'GET';
112 $manager = $processor->getModuleManager();
113 $module = $manager->getModule(
$wgRequest->getRawVal(
'action' ),
'action' );
114 }
catch ( Throwable $ex ) {
117 if ( !$module || $module->mustBePosted() ) {
118 $items[] =
"action=" .
$wgRequest->getRawVal(
'action' );
123 $items[] =
"failed in ApiBeforeMain";
126 wfDebug(
"Logged API request to $wgAPIRequestLog" );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgTitle
This is the main API class, used for both external and internal processing.
static handleApiBeforeMainException(Throwable $e)
Handle a throwable from the ApiBeforeMain hook.
static getMain()
Get the RequestContext object associated with the main request.
$wgAPIRequestLog
Config variable stub for the APIRequestLog setting, for use by phpdoc and IDEs.