replace overloaded DEBUG_MODE with specific constants

This commit is contained in:
Spine
2025-09-04 22:41:56 +00:00
parent d0243c69a4
commit 1f7eaae26f
14 changed files with 34 additions and 36 deletions

View File

@@ -240,14 +240,12 @@ class Debug {
}
}
if (DEBUG_WARNINGS) {
self::$Errors[] = [
str_replace(SERVER_ROOT . '/', '', $Error),
str_replace(SERVER_ROOT . '/', '', $File) . ":$Line",
$Call,
$Args
];
}
self::$Errors[] = [
str_replace(SERVER_ROOT . '/', '', $Error),
str_replace(SERVER_ROOT . '/', '', $File) . ":$Line",
$Call,
$Args
];
return true;
}

View File

@@ -69,7 +69,7 @@ class SessionCookie {
[
'expires' => $expiryEpoch,
'path' => '/',
'secure' => !DEBUG_MODE,
'secure' => SECURE_COOKIE,
'httponly' => true,
'samesite' => 'Lax',
]
@@ -83,7 +83,7 @@ class SessionCookie {
[
'expires' => time() - 86_400 * 90,
'path' => '/',
'secure' => !DEBUG_MODE,
'secure' => SECURE_COOKIE,
'httponly' => true,
'samesite' => 'Lax',
]

View File

@@ -109,7 +109,7 @@ class User extends BaseAttrObject {
setcookie('session', '', [
'expires' => time() - 60 * 60 * 24 * 90,
'path' => '/',
'secure' => !DEBUG_MODE,
'secure' => SECURE_COOKIE,
'httponly' => true,
'samesite' => 'Strict',
]);

View File

@@ -24,7 +24,7 @@ class Twig {
self::$userMan = $userMan;
$twig = new \Twig\Environment(
new \Twig\Loader\FilesystemLoader(__DIR__ . '/../../' . TEMPLATE_PATH), [
'debug' => DEBUG_MODE,
'debug' => DEBUG_TWIG,
'cache' => __DIR__ . '/../../cache/twig'
]);

View File

@@ -92,7 +92,7 @@ class Sphinxql extends mysqli {
86_400,
);
if ($halt === true) {
if (DEBUG_MODE || $Viewer->permitted('site_debug')) {
if ($Viewer->permitted('site_debug')) {
echo '<pre>' . display_str($error) . '</pre>';
die();
} else {

View File

@@ -121,7 +121,7 @@ if ($Viewer) {
}
$Debug->mark('load page');
if (DEBUG_MODE || $Viewer?->permitted('site_debug')) {
if (DEBUG_TWIG) {
$Twig->addExtension(new \Twig\Extension\DebugExtension());
}
@@ -169,7 +169,7 @@ try {
}
$errorLog = $Debug->saveError($e);
Error500::error(
DEBUG_MODE || $Viewer?->permitted('site_debug')
$Viewer?->permitted('site_debug')
? ($e->getMessage() . " ({$errorLog->link()})")
: "That is not supposed to happen. Check to see whether someone has created a thread in the the Bugs forum, or create a new thread to explain what you were doing and reference the Error ID {$errorLog->id}."
);

View File

@@ -479,11 +479,8 @@ defined('HTTP_PROXY') or define('HTTP_PROXY', false);
// Block Opera Mini proxy?
defined('BLOCK_OPERA_MINI') or define('BLOCK_OPERA_MINI', true);
// Should PHP errors be shown in the output?
defined('DEBUG_MODE') or define('DEBUG_MODE', false);
// Can developer+ see PHP warnings in the site footer?
defined('DEBUG_WARNINGS') or define('DEBUG_WARNINGS', true);
// Is the debug() function available in Twig?
defined('DEBUG_TWIG') or define('DEBUG_TWIG', false);
// Do upload notifications need to be traced? (Results written to TMPDIR)
defined('DEBUG_UPLOAD_NOTIFICATION') or define('DEBUG_UPLOAD_NOTIFICATION', false);
@@ -509,12 +506,6 @@ defined('LASTFM_API_KEY') or define('LASTFM_API_KEY', false);
// Fake useragent (to override default cURL useragent string).
defined('FAKE_USERAGENT') or define('FAKE_USERAGENT', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
// How much upload buffer to members start out with? (3 GiB)
defined('STARTING_UPLOAD') or define('STARTING_UPLOAD', 3 * 1024 * 1024 * 1024);
// Can freeleech (FL) tokens be stacked?
defined('STACKABLE_FREELEECH_TOKENS') or define('STACKABLE_FREELEECH_TOKENS', true);
// How long does an activated token last before it is purged?
defined('FREELEECH_TOKEN_EXPIRY_DAYS') or define('FREELEECH_TOKEN_EXPIRY_DAYS', 30);
@@ -542,6 +533,15 @@ defined('DELETE_USER_STATS_DAILY_DAY') or define('DELETE_USER_STATS_DAILY_DAY',
// Retain this many months of daily snapshots.
defined('DELETE_USER_STATS_MONTHLY_DAY') or define('DELETE_USER_STATS_MONTHLY_DAY', 120);
// Is the secure attribute set on cookies?
defined('SECURE_COOKIE') or define('SECURE_COOKIE', true);
// Can freeleech (FL) tokens be stacked?
defined('STACKABLE_FREELEECH_TOKENS') or define('STACKABLE_FREELEECH_TOKENS', true);
// How much upload buffer to members start out with? (3 GiB)
defined('STARTING_UPLOAD') or define('STARTING_UPLOAD', 3 * 1024 * 1024 * 1024);
// How many invites do new users receive?
defined('STARTING_INVITES') or define('STARTING_INVITES', 0);

View File

@@ -9,11 +9,11 @@ define('DISABLE_TRACKER', true);
define('DISABLE_IRC', true);
define('DEBUG_EMAIL', true);
define('DEBUG_MODE', true);
define('DEBUG_WARNINGS', true);
define('DEBUG_TWIG', true);
define('DEBUG_UPLOAD_NOTIFICATION', true);
define('OPEN_REGISTRATION', true);
define('SECURE_COOKIE', false);
define('MEMCACHE_HOST_LIST', [['host' => 'memcached', 'port' => 11211, 'buckets' => 1]]);

View File

@@ -76,10 +76,9 @@ parameters:
- DEBUG
- DEBUG_CONTEST_PAYOUT
- DEBUG_EMAIL
- DEBUG_MODE
- DEBUG_TRACKER_TOKEN_EXPIRE
- DEBUG_TWIG
- DEBUG_UPLOAD_NOTIFICATION
- DEBUG_WARNINGS
- FEATURE_EMAIL_REENABLE
- GEOIP_SERVER
- HTTP_PROXY
@@ -103,6 +102,7 @@ parameters:
- RECOVERY_DB
- REFERRAL_SEND_EMAIL
- REQUEST_TAX
- SECURE_COOKIE
- SHOW_PUBLIC_INDEX
- STACKABLE_FREELEECH_TOKENS
- USER_LIMIT

View File

@@ -10,8 +10,7 @@ use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
define('DEBUG_MODE', true);
define('DEBUG_WARNINGS', true);
define('DEBUG_TWIG', true);
define('DISABLE_IRC', false);
define('FEATURE_EMAIL_REENABLE', true);
define('GEOIP_SERVER', true);
@@ -24,6 +23,7 @@ define('REAPER_TASK_NOTIFY', true);
define('REAPER_TASK_REMOVE_UNSEEDED', true);
define('REAPER_TASK_REMOVE_NEVER_SEEDED', true);
define('RECOVERY_AUTOVALIDATE', true);
define('SECURE_COOKIE', false);
return RectorConfig::configure()
->withPaths([

View File

@@ -14,7 +14,7 @@ if (isset($_POST['username'])) {
setcookie('username', '', [
'expires' => time() + 60 * 60,
'path' => '/',
'secure' => !DEBUG_MODE,
'secure' => SECURE_COOKIE,
'httponly' => true,
'samesite' => 'Strict',
]);

View File

@@ -29,7 +29,7 @@ if (!empty($_POST['username']) && !empty($_POST['password'])) {
setcookie('username', urlencode($user->username()), [
'expires' => time() + 60 * 60,
'path' => '/',
'secure' => !DEBUG_MODE,
'secure' => SECURE_COOKIE,
'httponly' => true,
'samesite' => 'Strict',
]);

View File

@@ -1,6 +1,6 @@
</div>
<div id="footer">
{% if constant('DEBUG_MODE') or viewer.permitted('site_debug') %}
{% if viewer.permitted('site_debug') %}
<div id="site_debug">
{% include 'debug/performance.twig' with {'list': debug.perfInfo} only %}
{% include 'debug/flag.twig' with {'list': debug.markList} only %}

View File

@@ -57,7 +57,7 @@
<script type="text/javascript" src="{{ constant('STATIC_SERVER') }}/vendor/noty/noty.layout.bottomRight.js?v={{ mtime('vendor/noty/noty.layout.bottomRight.js') }}"></script>
<script type="text/javascript" src="{{ constant('STATIC_SERVER') }}/vendor/noty/noty.theme.default.js?v={{ mtime('vendor/noty/noty.theme.default.js') }}"></script>
{% endif %}
{% if constant('DEBUG_MODE') or viewer.permitted('site_debug') %}
{% if viewer.permitted('site_debug') %}
<script type="text/javascript" src="{{ constant('STATIC_SERVER') }}/vendor/jquery-migrate.js?v={{ mtime('vendor/jquery-migrate.js') }}"></script>
<script type="text/javascript" src="{{ constant('STATIC_SERVER') }}/functions/debug.js?v={{ mtime('functions/debug.js') }}"></script>
{% endif %}