Merge "build: Lower default Karma logLevel during local development"
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index 23e5911..1922f7d 100644 (file)
@@ -210,9 +210,17 @@ class ParserOutput extends CacheTime {
         */
        private $mFlags = [];
 
+       /** @var string[] */
+       private static $speculativeFields = [
+               'speculativePageIdUsed',
+               'mSpeculativeRevId',
+               'revisionTimestampUsed'
+       ];
+
        /** @var int|null Assumed rev ID for {{REVISIONID}} if no revision is set */
        private $mSpeculativeRevId;
-
+       /** @var int|null Assumed page ID for {{PAGEID}} if no revision is set */
+       private $speculativePageIdUsed;
        /** @var int|null Assumed rev timestamp for {{REVISIONTIMESTAMP}} if no revision is set */
        private $revisionTimestampUsed;
 
@@ -451,6 +459,22 @@ class ParserOutput extends CacheTime {
                return $this->mSpeculativeRevId;
        }
 
+       /**
+        * @param int $id
+        * @since 1.34
+        */
+       public function setSpeculativePageIdUsed( $id ) {
+               $this->speculativePageIdUsed = $id;
+       }
+
+       /**
+        * @return int|null
+        * @since 1.34
+        */
+       public function getSpeculativePageIdUsed() {
+               return $this->speculativePageIdUsed;
+       }
+
        /**
         * @param string $timestamp TS_MW timestamp
         * @since 1.34
@@ -1302,9 +1326,18 @@ class ParserOutput extends CacheTime {
        }
 
        public function __sleep() {
-               return array_diff(
-                       array_keys( get_object_vars( $this ) ),
-                       [ 'mParseStartTime' ]
+               return array_filter( array_keys( get_object_vars( $this ) ),
+                       function ( $field ) {
+                               if ( $field === 'mParseStartTime' ) {
+                                       return false;
+                               } elseif ( strpos( $field, "\0" ) !== false ) {
+                                       // Unserializing unknown private fields in HHVM causes
+                                       // member variables with nulls in their names (T229366)
+                                       return false;
+                               } else {
+                                       return true;
+                               }
+                       }
                );
        }
 
@@ -1320,18 +1353,13 @@ class ParserOutput extends CacheTime {
                $this->mWarnings = self::mergeMap( $this->mWarnings, $source->mWarnings ); // don't use getter
                $this->mTimestamp = $this->useMaxValue( $this->mTimestamp, $source->getTimestamp() );
 
-               if ( $this->mSpeculativeRevId && $source->mSpeculativeRevId
-                       && $this->mSpeculativeRevId !== $source->mSpeculativeRevId
-               ) {
-                       wfLogWarning(
-                               'Inconsistent speculative revision ID encountered while merging parser output!'
-                       );
+               foreach ( self::$speculativeFields as $field ) {
+                       if ( $this->$field && $source->$field && $this->$field !== $source->$field ) {
+                               wfLogWarning( __METHOD__ . ": inconsistent '$field' properties!" );
+                       }
+                       $this->$field = $this->useMaxValue( $this->$field, $source->$field );
                }
 
-               $this->mSpeculativeRevId = $this->useMaxValue(
-                       $this->mSpeculativeRevId,
-                       $source->getSpeculativeRevIdUsed()
-               );
                $this->mParseStartTime = $this->useEachMinValue(
                        $this->mParseStartTime,
                        $source->mParseStartTime