From 46028c4c32caf8dfc675f5544a037bd5e5d8f9c2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 4 Jun 2020 08:22:16 +0200 Subject: [PATCH] Move defines to their own file As described in https://github.com/dwp-forge/columns/issues/5#issuecomment-638467603 sometime the Lexer constants have not been (auto)loaded when a syntax plugin is invoked (I'm not sure why). In general PSR2 discourages a mix of main code and function/class setup with the call to define() being considered main code. This patch moves these the define calls to a separate new file, solving both of the above problems. These are not all our defines. Instead I focused on the ones that are ENUM-like. In the future we should think about what defines can be replaced by class constants and what other define() calls should be moved. --- inc/Parsing/Lexer/Lexer.php | 8 ------ inc/auth.php | 9 ------- inc/changelog.php | 8 ------ inc/common.php | 10 ------- inc/defines.php | 65 +++++++++++++++++++++++++++++++++++++++++++++ inc/infoutils.php | 22 ++------------- inc/load.php | 1 + inc/media.php | 5 ---- 8 files changed, 68 insertions(+), 60 deletions(-) create mode 100644 inc/defines.php diff --git a/inc/Parsing/Lexer/Lexer.php b/inc/Parsing/Lexer/Lexer.php index c37e3fe4c..edcd25169 100644 --- a/inc/Parsing/Lexer/Lexer.php +++ b/inc/Parsing/Lexer/Lexer.php @@ -9,14 +9,6 @@ namespace dokuwiki\Parsing\Lexer; -// FIXME move elsewhere - -define("DOKU_LEXER_ENTER", 1); -define("DOKU_LEXER_MATCHED", 2); -define("DOKU_LEXER_UNMATCHED", 3); -define("DOKU_LEXER_EXIT", 4); -define("DOKU_LEXER_SPECIAL", 5); - /** * Accepts text and breaks it into tokens. * diff --git a/inc/auth.php b/inc/auth.php index ffd0c2249..96ae7c236 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -9,21 +9,12 @@ * @author Andreas Gohr */ -// some ACL level defines use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\Event; use dokuwiki\Extension\PluginController; use dokuwiki\PassHash; use dokuwiki\Subscriptions\RegistrationSubscriptionSender; -define('AUTH_NONE', 0); -define('AUTH_READ', 1); -define('AUTH_EDIT', 2); -define('AUTH_CREATE', 4); -define('AUTH_UPLOAD', 8); -define('AUTH_DELETE', 16); -define('AUTH_ADMIN', 255); - /** * Initialize the auth system. * diff --git a/inc/changelog.php b/inc/changelog.php index 57eb48c76..f02572e7f 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -6,14 +6,6 @@ * @author Andreas Gohr */ -// Constants for known core changelog line types. -// Use these in place of string literals for more readable code. -define('DOKU_CHANGE_TYPE_CREATE', 'C'); -define('DOKU_CHANGE_TYPE_EDIT', 'E'); -define('DOKU_CHANGE_TYPE_MINOR_EDIT', 'e'); -define('DOKU_CHANGE_TYPE_DELETE', 'D'); -define('DOKU_CHANGE_TYPE_REVERT', 'R'); - /** * parses a changelog line into it's components * diff --git a/inc/common.php b/inc/common.php index 3fc1b85f5..2910358c7 100644 --- a/inc/common.php +++ b/inc/common.php @@ -15,16 +15,6 @@ use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\Event; /** - * These constants are used with the recents function - */ -define('RECENTS_SKIP_DELETED', 2); -define('RECENTS_SKIP_MINORS', 4); -define('RECENTS_SKIP_SUBSPACES', 8); -define('RECENTS_MEDIA_CHANGES', 16); -define('RECENTS_MEDIA_PAGES_MIXED', 32); -define('RECENTS_ONLY_CREATION', 64); - -/** * Wrapper around htmlspecialchars() * * @author Andreas Gohr diff --git a/inc/defines.php b/inc/defines.php new file mode 100644 index 000000000..d864f711a --- /dev/null +++ b/inc/defines.php @@ -0,0 +1,65 @@ + - * @see html_msgarea - */ - -define('MSG_PUBLIC', 0); -define('MSG_USERS_ONLY', 1); -define('MSG_MANAGERS_ONLY',2); -define('MSG_ADMINS_ONLY',4); - -/** - * Display a message to the user - * * Triggers INFOUTIL_MSG_SHOW * + * @see html_msgarea() * @param string $message * @param int $lvl -1 = error, 0 = info, 1 = success, 2 = notify * @param string $line line number diff --git a/inc/load.php b/inc/load.php index f4b15af27..46cd91f4c 100644 --- a/inc/load.php +++ b/inc/load.php @@ -12,6 +12,7 @@ spl_autoload_register('load_autoload'); // require all the common libraries // for a few of these order does matter +require_once(DOKU_INC.'inc/defines.php'); require_once(DOKU_INC.'inc/actions.php'); require_once(DOKU_INC.'inc/changelog.php'); require_once(DOKU_INC.'inc/common.php'); diff --git a/inc/media.php b/inc/media.php index cc29bd16c..01e9b9250 100644 --- a/inc/media.php +++ b/inc/media.php @@ -230,11 +230,6 @@ function media_inuse($id) { } } -define('DOKU_MEDIA_DELETED', 1); -define('DOKU_MEDIA_NOT_AUTH', 2); -define('DOKU_MEDIA_INUSE', 4); -define('DOKU_MEDIA_EMPTY_NS', 8); - /** * Handles media file deletions * -- 2.11.4.GIT