diff options
author | Tim Starling <tstarling@wikimedia.org> | 2019-09-03 09:55:00 +1000 |
---|---|---|
committer | Tim Starling <tstarling@wikimedia.org> | 2019-09-03 11:43:18 +1000 |
commit | b7ce7aacb0fb6803d9135f465e9cf6b48912883e (patch) | |
tree | 8341cf98271d5ad0db2df5998d82c6e08bc0913f | |
parent | 7c9f1a122712362b5840aee0325e36b249cb79db (diff) | |
download | mediawikicore-b7ce7aacb0fb6803d9135f465e9cf6b48912883e.tar.gz mediawikicore-b7ce7aacb0fb6803d9135f465e9cf6b48912883e.zip |
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
-rw-r--r-- | api.php | 1 | ||||
-rw-r--r-- | img_auth.php | 1 | ||||
-rw-r--r-- | includes/Setup.php | 11 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | load.php | 2 | ||||
-rw-r--r-- | maintenance/Maintenance.php | 2 | ||||
-rw-r--r-- | opensearch_desc.php | 2 | ||||
-rw-r--r-- | profileinfo.php | 2 | ||||
-rw-r--r-- | rest.php | 3 | ||||
-rw-r--r-- | thumb.php | 1 | ||||
-rw-r--r-- | thumb_handler.php | 1 |
11 files changed, 28 insertions, 0 deletions
@@ -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 6e45e4eba5a6..f23de4f4703f 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 1e65f52a952f..7cf223b94233 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 0df4cd01adf8..5c2d290af881 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 @@ -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 130d1fbf7150..281aeb936536 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 b546cbf6e8f5..642523855fce 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 dccdd38ff6a1..7b652b74d5d0 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'; @@ -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 13dbc0e767ca..0925967867a0 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 e2b165b8a95b..4e6bbd9cf84b 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. |