jenkins-bot has submitted this change and it was merged.

Change subject: Move LIST_ constaints to IDatabase class constants
......................................................................


Move LIST_ constaints to IDatabase class constants

Leave aliases in Defines.php for backwards compatibility.

Change-Id: I88b45e0943cbfe97d863c2e0a4911fc0f81e5bb5
---
M includes/Defines.php
M includes/libs/rdbms/database/DBConnRef.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabaseMysqlBase.php
M includes/libs/rdbms/database/IDatabase.php
M includes/libs/rdbms/defines.php
6 files changed, 74 insertions(+), 47 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Defines.php b/includes/Defines.php
index 077f39a..529dfb3 100644
--- a/includes/Defines.php
+++ b/includes/Defines.php
@@ -28,6 +28,17 @@
 define( 'DB_SLAVE', -1 );
 
 /**@{
+ * Obsolete IDatabase::makeList() constants
+ * These are also available as Database class constants
+ */
+define( 'LIST_COMMA', IDatabase::LIST_COMMA );
+define( 'LIST_AND', IDatabase::LIST_AND );
+define( 'LIST_SET', IDatabase::LIST_SET );
+define( 'LIST_NAMES', IDatabase::LIST_NAMES );
+define( 'LIST_OR', IDatabase::LIST_OR );
+/**@}*/
+
+/**@{
  * Virtual namespaces; don't appear in the page database
  */
 define( 'NS_MEDIA', -2 );
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index 0d9b692..2375678 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -308,7 +308,7 @@
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
-       public function makeList( $a, $mode = LIST_COMMA ) {
+       public function makeList( $a, $mode = self::LIST_COMMA ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 1c2c0bd..f9e9296 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -1163,7 +1163,7 @@
                }
                if ( isset( $options['HAVING'] ) ) {
                        $having = is_array( $options['HAVING'] )
-                               ? $this->makeList( $options['HAVING'], LIST_AND 
)
+                               ? $this->makeList( $options['HAVING'], 
self::LIST_AND )
                                : $options['HAVING'];
                        $sql .= ' HAVING ' . $having;
                }
@@ -1233,7 +1233,7 @@
 
                if ( !empty( $conds ) ) {
                        if ( is_array( $conds ) ) {
-                               $conds = $this->makeList( $conds, LIST_AND );
+                               $conds = $this->makeList( $conds, 
self::LIST_AND );
                        }
                        $sql = "SELECT $startOpts $vars $from $useIndex 
$ignoreIndex WHERE $conds $preLimitTail";
                } else {
@@ -1467,16 +1467,16 @@
        function update( $table, $values, $conds, $fname = __METHOD__, $options 
= [] ) {
                $table = $this->tableName( $table );
                $opts = $this->makeUpdateOptions( $options );
-               $sql = "UPDATE $opts $table SET " . $this->makeList( $values, 
LIST_SET );
+               $sql = "UPDATE $opts $table SET " . $this->makeList( $values, 
self::LIST_SET );
 
                if ( $conds !== [] && $conds !== '*' ) {
-                       $sql .= " WHERE " . $this->makeList( $conds, LIST_AND );
+                       $sql .= " WHERE " . $this->makeList( $conds, 
self::LIST_AND );
                }
 
                return $this->query( $sql, $fname );
        }
 
-       public function makeList( $a, $mode = LIST_COMMA ) {
+       public function makeList( $a, $mode = self::LIST_COMMA ) {
                if ( !is_array( $a ) ) {
                        throw new DBUnexpectedError( $this, __METHOD__ . ' 
called with incorrect parameters' );
                }
@@ -1486,9 +1486,9 @@
 
                foreach ( $a as $field => $value ) {
                        if ( !$first ) {
-                               if ( $mode == LIST_AND ) {
+                               if ( $mode == self::LIST_AND ) {
                                        $list .= ' AND ';
-                               } elseif ( $mode == LIST_OR ) {
+                               } elseif ( $mode == self::LIST_OR ) {
                                        $list .= ' OR ';
                                } else {
                                        $list .= ',';
@@ -1497,11 +1497,13 @@
                                $first = false;
                        }
 
-                       if ( ( $mode == LIST_AND || $mode == LIST_OR ) && 
is_numeric( $field ) ) {
+                       if ( ( $mode == self::LIST_AND || $mode == 
self::LIST_OR ) && is_numeric( $field ) ) {
                                $list .= "($value)";
-                       } elseif ( ( $mode == LIST_SET ) && is_numeric( $field 
) ) {
+                       } elseif ( $mode == self::LIST_SET && is_numeric( 
$field ) ) {
                                $list .= "$value";
-                       } elseif ( ( $mode == LIST_AND || $mode == LIST_OR ) && 
is_array( $value ) ) {
+                       } elseif (
+                               ( $mode == self::LIST_AND || $mode == 
self::LIST_OR ) && is_array( $value )
+                       ) {
                                // Remove null from array to be handled 
separately if found
                                $includeNull = false;
                                foreach ( array_keys( $value, null, true ) as 
$nullKey ) {
@@ -1509,7 +1511,8 @@
                                        unset( $value[$nullKey] );
                                }
                                if ( count( $value ) == 0 && !$includeNull ) {
-                                       throw new InvalidArgumentException( 
__METHOD__ . ": empty input for field $field" );
+                                       throw new InvalidArgumentException(
+                                               __METHOD__ . ": empty input for 
field $field" );
                                } elseif ( count( $value ) == 0 ) {
                                        // only check if $field is null
                                        $list .= "$field IS NULL";
@@ -1534,17 +1537,19 @@
                                        }
                                }
                        } elseif ( $value === null ) {
-                               if ( $mode == LIST_AND || $mode == LIST_OR ) {
+                               if ( $mode == self::LIST_AND || $mode == 
self::LIST_OR ) {
                                        $list .= "$field IS ";
-                               } elseif ( $mode == LIST_SET ) {
+                               } elseif ( $mode == self::LIST_SET ) {
                                        $list .= "$field = ";
                                }
                                $list .= 'NULL';
                        } else {
-                               if ( $mode == LIST_AND || $mode == LIST_OR || 
$mode == LIST_SET ) {
+                               if (
+                                       $mode == self::LIST_AND || $mode == 
self::LIST_OR || $mode == self::LIST_SET
+                               ) {
                                        $list .= "$field = ";
                                }
-                               $list .= $mode == LIST_NAMES ? $value : 
$this->addQuotes( $value );
+                               $list .= $mode == self::LIST_NAMES ? $value : 
$this->addQuotes( $value );
                        }
                }
 
@@ -1558,12 +1563,12 @@
                        if ( count( $sub ) ) {
                                $conds[] = $this->makeList(
                                        [ $baseKey => $base, $subKey => 
array_keys( $sub ) ],
-                                       LIST_AND );
+                                       self::LIST_AND );
                        }
                }
 
                if ( $conds ) {
-                       return $this->makeList( $conds, LIST_OR );
+                       return $this->makeList( $conds, self::LIST_OR );
                } else {
                        // Nothing to search for...
                        return false;
@@ -1884,7 +1889,7 @@
                                                $tableClause .= ' ' . $ignore;
                                        }
                                }
-                               $on = $this->makeList( (array)$conds, LIST_AND 
);
+                               $on = $this->makeList( (array)$conds, 
self::LIST_AND );
                                if ( $on != '' ) {
                                        $tableClause .= ' ON (' . $on . ')';
                                }
@@ -2153,10 +2158,10 @@
                                        foreach ( $index as $column ) {
                                                $rowKey[$column] = 
$row[$column];
                                        }
-                                       $clauses[] = $this->makeList( $rowKey, 
LIST_AND );
+                                       $clauses[] = $this->makeList( $rowKey, 
self::LIST_AND );
                                }
                        }
-                       $where = [ $this->makeList( $clauses, LIST_OR ) ];
+                       $where = [ $this->makeList( $clauses, self::LIST_OR ) ];
                } else {
                        $where = false;
                }
@@ -2198,7 +2203,7 @@
                $joinTable = $this->tableName( $joinTable );
                $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar 
FROM $joinTable ";
                if ( $conds != '*' ) {
-                       $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
+                       $sql .= 'WHERE ' . $this->makeList( $conds, 
self::LIST_AND );
                }
                $sql .= ')';
 
@@ -2239,7 +2244,7 @@
 
                if ( $conds != '*' ) {
                        if ( is_array( $conds ) ) {
-                               $conds = $this->makeList( $conds, LIST_AND );
+                               $conds = $this->makeList( $conds, 
self::LIST_AND );
                        }
                        $sql .= ' WHERE ' . $conds;
                }
@@ -2317,7 +2322,7 @@
 
                if ( $conds != '*' ) {
                        if ( is_array( $conds ) ) {
-                               $conds = $this->makeList( $conds, LIST_AND );
+                               $conds = $this->makeList( $conds, 
self::LIST_AND );
                        }
                        $sql .= " WHERE $conds";
                }
@@ -2368,7 +2373,7 @@
 
        public function conditional( $cond, $trueVal, $falseVal ) {
                if ( is_array( $cond ) ) {
-                       $cond = $this->makeList( $cond, LIST_AND );
+                       $cond = $this->makeList( $cond, self::LIST_AND );
                }
 
                return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) ";
diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php 
b/includes/libs/rdbms/database/DatabaseMysqlBase.php
index 46c6678..b3f1add 100644
--- a/includes/libs/rdbms/database/DatabaseMysqlBase.php
+++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php
@@ -735,7 +735,7 @@
         * @see 
https://www.percona.com/doc/percona-toolkit/2.1/pt-heartbeat.html
         */
        protected function getHeartbeatData( array $conds ) {
-               $whereSQL = $this->makeList( $conds, LIST_AND );
+               $whereSQL = $this->makeList( $conds, self::LIST_AND );
                // Use ORDER BY for channel based queries since that field 
might not be UNIQUE.
                // Note: this would use 
"TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6))" but the
                // percision field is not supported in MySQL <= 5.5.
@@ -1107,7 +1107,7 @@
                $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE 
$delVar=$joinVar ";
 
                if ( $conds != '*' ) {
-                       $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
+                       $sql .= ' AND ' . $this->makeList( $conds, 
self::LIST_AND );
                }
 
                return $this->query( $sql, $fname );
@@ -1141,7 +1141,7 @@
                        $rowTuples[] = '(' . $this->makeList( $row ) . ')';
                }
                $sql .= implode( ',', $rowTuples );
-               $sql .= " ON DUPLICATE KEY UPDATE " . $this->makeList( $set, 
LIST_SET );
+               $sql .= " ON DUPLICATE KEY UPDATE " . $this->makeList( $set, 
self::LIST_SET );
 
                return (bool)$this->query( $sql, $fname );
        }
diff --git a/includes/libs/rdbms/database/IDatabase.php 
b/includes/libs/rdbms/database/IDatabase.php
index 495816f..25e5912 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -63,6 +63,17 @@
        /** @var string Estimate time to apply (scanning, applying) */
        const ESTIMATE_DB_APPLY = 'apply';
 
+       /** @var int Combine list with comma delimeters */
+       const LIST_COMMA = 0;
+       /** @var int Combine list with AND clauses */
+       const LIST_AND = 1;
+       /** @var int Convert map into a SET clause */
+       const LIST_SET = 2;
+       /** @var int Treat as field name and do not apply value escaping */
+       const LIST_NAMES = 3;
+       /** @var int Combine list with OR clauses */
+       const LIST_OR = 4;
+
        /**
         * A string describing the current software version, and possibly
         * other details in a user-friendly way. Will be listed on 
Special:Version, etc.
@@ -897,18 +908,29 @@
        /**
         * Makes an encoded list of strings from an array
         *
+        * These can be used to make conjunctions or disjunctions on SQL 
condition strings
+        * derived from an array (see IDatabase::select() $conds documentation).
+        *
+        * Example usage:
+        * @code
+        *     $sql = $db->makeList( [
+        *         'rev_user' => $id,
+        *         $db->makeList( [ 'rev_minor' => 1, 'rev_len' < 500 ], 
$db::LIST_OR ] )
+        *     ], $db::LIST_AND );
+        * @endcode
+        * This would set $sql to "rev_user = '$id' AND (rev_minor = '1' OR 
rev_len < '500')"
+        *
         * @param array $a Containing the data
-        * @param int $mode Constant
-        *    - LIST_COMMA: Comma separated, no field names
-        *    - LIST_AND:   ANDed WHERE clause (without the WHERE). See the
-        *      documentation for $conds in IDatabase::select().
-        *    - LIST_OR:    ORed WHERE clause (without the WHERE)
-        *    - LIST_SET:   Comma separated with field names, like a SET clause
-        *    - LIST_NAMES: Comma separated field names
+        * @param int $mode IDatabase class constant:
+        *    - IDatabase::LIST_COMMA: Comma separated, no field names
+        *    - IDatabase::LIST_AND:   ANDed WHERE clause (without the WHERE).
+        *    - IDatabase::LIST_OR:    ORed WHERE clause (without the WHERE)
+        *    - IDatabase::LIST_SET:   Comma separated with field names, like a 
SET clause
+        *    - IDatabase::LIST_NAMES: Comma separated field names
         * @throws DBError
         * @return string
         */
-       public function makeList( $a, $mode = LIST_COMMA );
+       public function makeList( $a, $mode = self::LIST_COMMA );
 
        /**
         * Build a partial where clause from a 2-d array such as used for 
LinkBatch.
diff --git a/includes/libs/rdbms/defines.php b/includes/libs/rdbms/defines.php
index 48baa3c..b420ca1 100644
--- a/includes/libs/rdbms/defines.php
+++ b/includes/libs/rdbms/defines.php
@@ -22,14 +22,3 @@
 define( 'DB_REPLICA', -1 );     # Read from a replica (or only server)
 define( 'DB_MASTER', -2 );    # Write to master (or only server)
 /**@}*/
-
-/**@{
- * Flags for IDatabase::makeList()
- * These are also available as Database class constants
- */
-define( 'LIST_COMMA', 0 );
-define( 'LIST_AND', 1 );
-define( 'LIST_SET', 2 );
-define( 'LIST_NAMES', 3 );
-define( 'LIST_OR', 4 );
-/**@}*/

-- 
To view, visit https://gerrit.wikimedia.org/r/311376
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I88b45e0943cbfe97d863c2e0a4911fc0f81e5bb5
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to