// So extensions (and other code) can check whether they're running in API mode
define( 'MW_API', true );
+define( 'MW_ENTRY_POINT', 'api' );
require __DIR__ . '/includes/WebStart.php';
return;
}
-// Pathinfo can be used for stupid things. We don't support it for api.php at
+// PATH_INFO can be used for stupid things. We don't support it for api.php at
// all, so error out if it's present.
if ( isset( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != '' ) {
- $correctUrl = wfAppendQuery( wfScript( 'api' ), $wgRequest->getQueryValues() );
+ $correctUrl = wfAppendQuery( wfScript( 'api' ), $wgRequest->getQueryValuesOnly() );
$correctUrl = wfExpandUrl( $correctUrl, PROTO_CANONICAL );
header( "Location: $correctUrl", true, 301 );
echo 'This endpoint does not support "path info", i.e. extra text between "api.php"'
RequestContext::getMain()->setTitle( $wgTitle );
try {
- /* Construct an ApiMain with the arguments passed via the URL. What we get back
- * is some form of an ApiMain, possibly even one that produces an error message,
- * but we don't care here, as that is handled by the constructor.
- */
+ // Construct an ApiMain with the arguments passed via the URL. What we get back
+ // is some form of an ApiMain, possibly even one that produces an error message,
+ // but we don't care here, as that is handled by the constructor.
$processor = new ApiMain( RequestContext::getMain(), true );
// Last chance hook before executing the API
if ( !$processor instanceof ApiMain ) {
throw new MWException( 'ApiBeforeMain hook set $processor to a non-ApiMain class' );
}
-} catch ( Exception $e ) {
+} catch ( Exception $e ) { // @todo Remove this block when HHVM is no longer supported
+ // Crap. Try to report the exception in API format to be friendly to clients.
+ ApiMain::handleApiBeforeMainException( $e );
+ $processor = false;
+} catch ( Throwable $e ) {
// Crap. Try to report the exception in API format to be friendly to clients.
ApiMain::handleApiBeforeMainException( $e );
$processor = false;
try {
$manager = $processor->getModuleManager();
$module = $manager->getModule( $wgRequest->getVal( 'action' ), 'action' );
- } catch ( Exception $ex ) {
+ } catch ( Exception $ex ) { // @todo Remove this block when HHVM is no longer supported
+ $module = null;
+ } catch ( Throwable $ex ) {
$module = null;
}
if ( !$module || $module->mustBePosted() ) {