Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / includes / Storage / SqlBlobStore.php
index 0ff7c13..fb3ef94 100644 (file)
@@ -244,7 +244,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
 
                        $textId = $dbw->insertId();
 
-                       return 'tt:' . $textId;
+                       return self::makeAddressFromTextId( $textId );
                } catch ( MWException $e ) {
                        throw new BlobAccessException( $e->getMessage(), 0, $e );
                }
@@ -292,7 +292,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
         * @param string $blobAddress
         * @param int $queryFlags
         *
-        * @throw BlobAccessException
+        * @throws BlobAccessException
         * @return string|false
         */
        private function fetchBlob( $blobAddress, $queryFlags ) {
@@ -349,7 +349,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                $blob = $this->expandBlob( $row->old_text, $row->old_flags, $blobAddress );
 
                if ( $blob === false ) {
-                       wfWarn( __METHOD__ . ": Bad data in text row $textId." );
+                       wfLogWarning( __METHOD__ . ": Bad data in text row $textId." );
                        return false;
                }
 
@@ -399,13 +399,13 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                                                // No negative caching per BlobStore::getBlob()
                                                $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->wikiId ] );
 
-                                               return $this->decompressData( $blob, $flags );
+                                               return $blob === false ? false : $this->decompressData( $blob, $flags );
                                        },
                                        [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
                                );
                        } else {
                                $blob = ExternalStore::fetchFromURL( $url, [ 'wiki' => $this->wikiId ] );
-                               return $this->decompressData( $blob, $flags );
+                               return $blob === false ? false : $this->decompressData( $blob, $flags );
                        }
                } else {
                        return $this->decompressData( $raw, $flags );
@@ -461,7 +461,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
         * @note direct use is deprecated, use getBlob() or SlotRecord::getContent() instead.
         * @todo make this private, there should be no need to use this method outside this class.
         *
-        * @param mixed $blob Reference to a text
+        * @param string $blob Blob in compressed/encoded form.
         * @param array $blobFlags Compression flags, such as 'gzip'.
         *   Note that not including 'utf-8' in $blobFlags will cause the data to be decoded
         *   according to the legacy encoding specified via setLegacyEncoding.
@@ -469,10 +469,8 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
         * @return string|bool Decompressed text, or false on failure
         */
        public function decompressData( $blob, array $blobFlags ) {
-               if ( $blob === false ) {
-                       // Text failed to be fetched; nothing to do
-                       return false;
-               }
+               // Revision::decompressRevisionText accepted false here, so defend against that
+               Assert::parameterType( 'string', $blob, '$blob' );
 
                if ( in_array( 'error', $blobFlags ) ) {
                        // Error row, return false
@@ -486,7 +484,7 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                        $blob = gzinflate( $blob );
 
                        if ( $blob === false ) {
-                               wfLogWarning( __METHOD__ . ': gzinflate() failed' );
+                               wfWarn( __METHOD__ . ': gzinflate() failed' );
                                return false;
                        }
                }
@@ -542,11 +540,12 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
         * Currently, $address must start with 'tt:' followed by a decimal integer representing
         * the old_id; if $address does not start with 'tt:', null is returned. However,
         * the implementation may change to insert rows into the text table on the fly.
+        * This implies that this method cannot be static.
         *
         * @note This method exists for use with the text table based storage schema.
         * It should not be assumed that is will function with all future kinds of content addresses.
         *
-        * @deprecated since 1.31, so not assume that all blob addresses refer to a row in the text
+        * @deprecated since 1.31, so don't assume that all blob addresses refer to a row in the text
         * table. This method should become private once the relevant refactoring in WikiPage is
         * complete.
         *
@@ -570,6 +569,22 @@ class SqlBlobStore implements IDBAccessObject, BlobStore {
                return $textId;
        }
 
+       /**
+        * Returns an address referring to content stored in the text table row with the given ID.
+        * The address schema for blobs stored in the text table is "tt:" followed by an integer
+        * that corresponds to a value of the old_id field.
+        *
+        * @deprecated since 1.31. This method should become private once the relevant refactoring
+        * in WikiPage is complete.
+        *
+        * @param int $id
+        *
+        * @return string
+        */
+       public static function makeAddressFromTextId( $id ) {
+               return 'tt:' . $id;
+       }
+
        /**
         * Splits a blob address into three parts: the schema, the ID, and parameters/flags.
         *