From b7ce7aacb0fb6803d9135f465e9cf6b48912883e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 3 Sep 2019 09:55:00 +1000 Subject: [PATCH] Add MW_REST_API and MW_ENTRY_POINT Define the global constant MW_REST_API in rest.php, by analogy with MW_API. Also generalize this by adding MW_ENTRY_POINT, which contains the entry script name, "cli" or "unknown". This allows tests such as if ( MW_ENTRY_POINT !== 'index' ) which is probably what is really intended by defined('MW_API') in many cases. Change-Id: I24099f4cdd170de17afd6e1bbad67c9b204071fc --- api.php | 1 + img_auth.php | 1 + includes/Setup.php | 11 +++++++++++ index.php | 2 ++ load.php | 2 ++ maintenance/Maintenance.php | 2 ++ opensearch_desc.php | 2 ++ profileinfo.php | 2 ++ rest.php | 3 +++ thumb.php | 1 + thumb_handler.php | 1 + 11 files changed, 28 insertions(+) diff --git a/api.php b/api.php index 0fb674b9eb..f9f6175cb7 100644 --- a/api.php +++ b/api.php @@ -31,6 +31,7 @@ use MediaWiki\Logger\LegacyLogger; // 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'; diff --git a/img_auth.php b/img_auth.php index 6e45e4eba5..f23de4f470 100644 --- a/img_auth.php +++ b/img_auth.php @@ -39,6 +39,7 @@ */ define( 'MW_NO_OUTPUT_COMPRESSION', 1 ); +define( 'MW_ENTRY_POINT', 'img_auth' ); require __DIR__ . '/includes/WebStart.php'; # Set action base paths so that WebRequest::getPathInfo() diff --git a/includes/Setup.php b/includes/Setup.php index 1e65f52a95..7cf223b942 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -52,6 +52,17 @@ if ( ini_get( 'mbstring.func_overload' ) ) { die( 'MediaWiki does not support installations where mbstring.func_overload is non-zero.' ); } +// Define MW_ENTRY_POINT if it's not already, so that config code can check the +// value without using defined() +if ( !defined( 'MW_ENTRY_POINT' ) ) { + /** + * The entry point, which may be either the script filename without the + * file extension, or "cli" for maintenance scripts, or "unknown" for any + * entry point that does not set the constant. + */ + define( 'MW_ENTRY_POINT', 'unknown' ); +} + // Start the autoloader, so that extensions can derive classes from core files require_once "$IP/includes/AutoLoader.php"; diff --git a/index.php b/index.php index 0df4cd01ad..5c2d290af8 100644 --- a/index.php +++ b/index.php @@ -30,6 +30,8 @@ * @file */ +define( 'MW_ENTRY_POINT', 'index' ); + // Bail on old versions of PHP, or if composer has not been run yet to install // dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. // phpcs:ignore MediaWiki.Usage.DirUsage.FunctionFound diff --git a/load.php b/load.php index 6edb7ec954..3f0c3df293 100644 --- a/load.php +++ b/load.php @@ -28,6 +28,8 @@ use MediaWiki\MediaWikiServices; // details of the session. Enforce this constraint with respect to session use. define( 'MW_NO_SESSION', 1 ); +define( 'MW_ENTRY_POINT', 'load' ); + require __DIR__ . '/includes/WebStart.php'; // URL safety checks diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 130d1fbf71..281aeb9365 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -20,6 +20,8 @@ * @defgroup Maintenance Maintenance */ +define( MW_ENTRY_POINT, 'cli' ); + // Bail on old versions of PHP, or if composer has not been run yet to install // dependencies. require_once __DIR__ . '/../includes/PHPVersionCheck.php'; diff --git a/opensearch_desc.php b/opensearch_desc.php index b546cbf6e8..642523855f 100644 --- a/opensearch_desc.php +++ b/opensearch_desc.php @@ -24,6 +24,8 @@ // details of the session. Enforce this constraint with respect to session use. define( 'MW_NO_SESSION', 1 ); +define( 'MW_ENTRY_POINT', 'opensearch_desc' ); + require_once __DIR__ . '/includes/WebStart.php'; if ( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) { diff --git a/profileinfo.php b/profileinfo.php index dccdd38ff6..7b652b74d5 100644 --- a/profileinfo.php +++ b/profileinfo.php @@ -40,6 +40,8 @@ // details of the session. Enforce this constraint with respect to session use. define( 'MW_NO_SESSION', 1 ); +define( 'MW_ENTRY_POINT', 'profileinfo' ); + ini_set( 'zlib.output_compression', 'off' ); require __DIR__ . '/includes/WebStart.php'; diff --git a/rest.php b/rest.php index 3ac532e43d..f647f91fe0 100644 --- a/rest.php +++ b/rest.php @@ -23,6 +23,9 @@ use MediaWiki\Rest\EntryPoint; +define( 'MW_REST_API', true ); +define( 'MW_ENTRY_POINT', 'rest' ); + require __DIR__ . '/includes/WebStart.php'; EntryPoint::main(); diff --git a/thumb.php b/thumb.php index 13dbc0e767..0925967867 100644 --- a/thumb.php +++ b/thumb.php @@ -25,6 +25,7 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; define( 'MW_NO_OUTPUT_COMPRESSION', 1 ); +define( 'MW_ENTRY_POINT', 'thumb' ); require __DIR__ . '/includes/WebStart.php'; // Don't use fancy MIME detection, just check the file extension for jpg/gif/png diff --git a/thumb_handler.php b/thumb_handler.php index e2b165b8a9..4e6bbd9cf8 100644 --- a/thumb_handler.php +++ b/thumb_handler.php @@ -23,6 +23,7 @@ */ define( 'THUMB_HANDLER', true ); +define( 'MW_ENTRY_POINT', 'thumb_handler' ); // Execute thumb.php, having set THUMB_HANDLER so that // it knows to extract params from a thumbnail file URL. -- 2.20.1