Use PHP 5.6 constant expressions for some bitfield constants
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 6 Oct 2017 19:10:53 +0000 (21:10 +0200)
committerJames D. Forrester <jforrester@wikimedia.org>
Thu, 31 May 2018 01:05:18 +0000 (18:05 -0700)
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
includes/api/ApiResult.php
includes/dao/IDBAccessObject.php
includes/logging/LogPage.php
includes/parser/Preprocessor.php
tests/phpunit/suites/ParserTestTopLevelSuite.php

index 6d83e1c..ff0a70d 100644 (file)
@@ -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;
index 468d878..1afacaf 100644 (file)
@@ -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.
index e18a090..a555c55 100644 (file)
@@ -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;
index 9f34264..265a41c 100644 (file)
@@ -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;
index 49e961a..b6084d8 100644 (file)
@@ -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;
index 07b18f5..fe38a98 100644 (file)
@@ -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;
 
        /** @} */