Merge "Allow <figure-inline> attributes through Sanitizer"
[lhc/web/wiklou.git] / includes / libs / rdbms / ChronologyProtector.php
index 45179cc..fa454c8 100644 (file)
@@ -72,15 +72,20 @@ class ChronologyProtector implements LoggerAwareInterface {
 
        /**
         * @param BagOStuff $store
-        * @param array[] $client Map of (ip: <IP>, agent: <user-agent> [, clientId: <hash>] )
-        * @param int|null $posIndex Write counter index [optional]
+        * @param array $client Map of (ip: <IP>, agent: <user-agent> [, clientId: <hash>] )
+        * @param int|null $posIndex Write counter index
+        * @param string $secret Secret string for HMAC hashing [optional]
         * @since 1.27
         */
-       public function __construct( BagOStuff $store, array $client, $posIndex = null ) {
+       public function __construct( BagOStuff $store, array $client, $posIndex, $secret = '' ) {
                $this->store = $store;
-               $this->clientId = isset( $client['clientId'] )
-                       ? $client['clientId']
-                       : md5( $client['ip'] . "\n" . $client['agent'] );
+               if ( isset( $client['clientId'] ) ) {
+                       $this->clientId = $client['clientId'];
+               } else {
+                       $this->clientId = strlen( $secret )
+                               ? hash_hmac( 'md5', $client['ip'] . "\n" . $client['agent'], $secret )
+                               : md5( $client['ip'] . "\n" . $client['agent'] );
+               }
                $this->key = $store->makeGlobalKey( __CLASS__, $this->clientId, 'v2' );
                $this->waitForPosIndex = $posIndex;
 
@@ -203,7 +208,7 @@ class ChronologyProtector implements LoggerAwareInterface {
                        );
                }
 
-               if ( !count( $this->shutdownPositions ) ) {
+               if ( $this->shutdownPositions === [] ) {
                        return []; // nothing to save
                }