From 52b0799e8deca45ba345eb6db4f173a20bbe44fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 6 Oct 2017 21:10:53 +0200 Subject: [PATCH] Use PHP 5.6 constant expressions for some bitfield constants I searched the entire codebase for 'const' and looked for things that looked suspiciously like manually calculated bitfield unions. As of PHP 5.6, we can have them calculated automatically when defining constants. Change-Id: I7d971d1a63f8916db2f8f6c053c7dd0a13add92d --- includes/Storage/RevisionRecord.php | 5 +++-- includes/api/ApiResult.php | 2 +- includes/dao/IDBAccessObject.php | 4 ++-- includes/logging/LogPage.php | 4 ++-- includes/parser/Preprocessor.php | 3 ++- tests/phpunit/suites/ParserTestTopLevelSuite.php | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/includes/Storage/RevisionRecord.php b/includes/Storage/RevisionRecord.php index 6d83e1c100..ff0a70dd24 100644 --- a/includes/Storage/RevisionRecord.php +++ b/includes/Storage/RevisionRecord.php @@ -48,8 +48,9 @@ abstract class RevisionRecord { const DELETED_COMMENT = 2; const DELETED_USER = 4; const DELETED_RESTRICTED = 8; - const SUPPRESSED_USER = 12; // convenience - const SUPPRESSED_ALL = 15; // convenience + const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED; // convenience + const SUPPRESSED_ALL = self::DELETED_TEXT | self::DELETED_COMMENT | self::DELETED_USER | + self::DELETED_RESTRICTED; // convenience // Audience options for accessors const FOR_PUBLIC = 1; diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 468d8783b4..1afacafc3b 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -61,7 +61,7 @@ class ApiResult implements ApiSerializable { * probably wrong. * @since 1.25 */ - const NO_VALIDATE = 12; + const NO_VALIDATE = self::NO_SIZE_CHECK | 8; /** * Key for the 'indexed tag name' metadata item. Value is string. diff --git a/includes/dao/IDBAccessObject.php b/includes/dao/IDBAccessObject.php index e18a090bcb..a555c5527c 100644 --- a/includes/dao/IDBAccessObject.php +++ b/includes/dao/IDBAccessObject.php @@ -59,9 +59,9 @@ interface IDBAccessObject { /** @var int Read from the master/quorum */ const READ_LATEST = 1; /* @var int Read from the master/quorum and lock out other writers */ - const READ_LOCKING = 3; // READ_LATEST (1) and "LOCK IN SHARE MODE" (2) + const READ_LOCKING = self::READ_LATEST | 2; // READ_LATEST (1) and "LOCK IN SHARE MODE" (2) /** @var int Read from the master/quorum and lock out other writers and locking readers */ - const READ_EXCLUSIVE = 7; // READ_LOCKING (3) and "FOR UPDATE" (4) + const READ_EXCLUSIVE = self::READ_LOCKING | 4; // READ_LOCKING (3) and "FOR UPDATE" (4) /** @var int Read from a replica DB or without a quorum, using the master/quorum on miss */ const READ_LATEST_IMMUTABLE = 8; diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 9f342646d1..265a41cdaf 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -37,8 +37,8 @@ class LogPage { const DELETED_RESTRICTED = 8; // Convenience fields - const SUPPRESSED_USER = 12; - const SUPPRESSED_ACTION = 9; + const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED; + const SUPPRESSED_ACTION = self::DELETED_ACTION | self::DELETED_RESTRICTED; /** @var bool */ public $updateRecentChanges; diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php index 49e961aec3..b6084d885b 100644 --- a/includes/parser/Preprocessor.php +++ b/includes/parser/Preprocessor.php @@ -171,7 +171,8 @@ interface PPFrame { const RECOVER_COMMENTS = 16; const NO_TAGS = 32; - const RECOVER_ORIG = 59; // = 1|2|8|16|32 no constant expression support in PHP yet + const RECOVER_ORIG = self::NO_ARGS | self::NO_TEMPLATES | self::NO_IGNORE | + self::RECOVER_COMMENTS | self::NO_TAGS; /** This constant exists when $indexOffset is supported in newChild() */ const SUPPORTS_INDEX_OFFSET = 1; diff --git a/tests/phpunit/suites/ParserTestTopLevelSuite.php b/tests/phpunit/suites/ParserTestTopLevelSuite.php index 07b18f594e..fe38a981cd 100644 --- a/tests/phpunit/suites/ParserTestTopLevelSuite.php +++ b/tests/phpunit/suites/ParserTestTopLevelSuite.php @@ -29,7 +29,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite { /** Include non core files as set in $wgParserTestFiles */ const NO_CORE = 2; /** Include anything set via $wgParserTestFiles */ - const WITH_ALL = 3; # CORE_ONLY | NO_CORE + const WITH_ALL = self::CORE_ONLY | self::NO_CORE; /** @} */ -- 2.20.1