MediaWiki  master
MediaWiki\Storage\SqlBlobStore Class Reference

Service for storing and loading Content objects. More...

Inheritance diagram for MediaWiki\Storage\SqlBlobStore:
Collaboration diagram for MediaWiki\Storage\SqlBlobStore:

Public Member Functions

 __construct (ILoadBalancer $dbLoadBalancer, ExternalStoreAccess $extStoreAccess, WANObjectCache $cache, $dbDomain=false)
 
 compressData (&$blob)
 If $wgCompressRevisions is enabled, we will compress data. More...
 
 decompressData ( $blob, array $blobFlags)
 Re-converts revision text according to its flags. More...
 
 expandBlob ( $raw, $flags, $cacheKey=null)
 Expand a raw data blob according to the flags given. More...
 
 getBlob ( $blobAddress, $queryFlags=0)
 Retrieve a blob, given an address. More...
 
 getCacheExpiry ()
 
 getCompressBlobs ()
 
 getLegacyEncoding ()
 
 getLegacyEncodingConversionLang ()
 
 getTextIdFromAddress ( $address)
 Returns an ID corresponding to the old_id field in the text table, corresponding to the given $address. More...
 
 getUseExternalStore ()
 
 isReadOnly ()
 Check if the blob metadata or backing blob data store is read-only. More...
 
 setCacheExpiry ( $cacheExpiry)
 
 setCompressBlobs ( $compressBlobs)
 
 setLegacyEncoding ( $legacyEncoding, Language $language)
 
 setUseExternalStore ( $useExternalStore)
 
 storeBlob ( $data, $hints=[])
 Stores an arbitrary blob of data and returns an address that can be used with getBlob() to retrieve the same blob of data,. More...
 

Static Public Member Functions

static makeAddressFromTextId ( $id)
 Returns an address referring to content stored in the text table row with the given ID. More...
 
static splitBlobAddress ( $address)
 Splits a blob address into three parts: the schema, the ID, and parameters/flags. More...
 

Public Attributes

const TEXT_CACHE_GROUP = 'revisiontext:10'
 
- Public Attributes inherited from IDBAccessObject
const READ_LOCKING = self::READ_LATEST | 2
 Constants for object loading bitfield flags (higher => higher QoS) More...
 
const READ_NONE = -1
 
- Public Attributes inherited from MediaWiki\Storage\BlobStore
const DESIGNATION_HINT = 'designation'
 Hint key for use with storeBlob, indicating the general role the block takes in the application. More...
 
const FORMAT_HINT = 'cont_format'
 Hint key for use with storeBlob, indicating the serialization format used to create the blob, as a MIME type. More...
 
const MODEL_HINT = 'cont_model'
 Hint key for use with storeBlob, indicating the model of the content encoded in the given blob. More...
 
const PAGE_HINT = 'page_id'
 Hint key for use with storeBlob, indicating the page the blob is associated with. More...
 
const PARENT_HINT = 'rev_parent_id'
 Hint key for use with storeBlob, indicating the parent revision of the revision the blob is associated with. More...
 
const REVISION_HINT = 'rev_id'
 Hint key for use with storeBlob, indicating the revision the blob is associated with. More...
 
const ROLE_HINT = 'role_name'
 Hint key for use with storeBlob, indicating the slot the blob is associated with. More...
 
const SHA1_HINT = 'cont_sha1'
 Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the method. More...
 

Private Member Functions

 fetchBlob ( $blobAddress, $queryFlags)
 MCR migration note: this corresponds to Revision::fetchText. More...
 
 getCacheKey ( $blobAddress)
 Get a cache key for a given Blob address. More...
 
 getCacheTTL ()
 Get the text cache TTL. More...
 
 getDBConnection ( $index)
 
 getDBLoadBalancer ()
 

Private Attributes

WANObjectCache $cache
 
int $cacheExpiry = 604800
 
bool $compressBlobs = false
 
string bool $dbDomain
 DB domain ID of a wiki or false for the local one. More...
 
ILoadBalancer $dbLoadBalancer
 
ExternalStoreAccess $extStoreAccess
 
bool string $legacyEncoding = false
 
Language null $legacyEncodingConversionLang = null
 
boolean $useExternalStore = false
 

Detailed Description

Service for storing and loading Content objects.

Since
1.31
Note
This was written to act as a drop-in replacement for the corresponding static methods in Revision.

Definition at line 49 of file SqlBlobStore.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Storage\SqlBlobStore::__construct ( ILoadBalancer  $dbLoadBalancer,
ExternalStoreAccess  $extStoreAccess,
WANObjectCache  $cache,
  $dbDomain = false 
)
Parameters
ILoadBalancer$dbLoadBalancerA load balancer for acquiring database connections
ExternalStoreAccess$extStoreAccessAccess layer for external storage
WANObjectCache$cacheA cache manager for caching blobs. This can be the local wiki's default instance even if $dbDomain refers to a different wiki, since makeGlobalKey() is used to constructed a key that allows cached blobs from the same database to be re-used between wikis. For example, enwiki and frwiki will use the same cache keys for blobs from the wikidatawiki database, regardless of the cache's default key space.
bool | string$dbDomainThe ID of the target wiki database. Use false for the local wiki.

Definition at line 110 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$cache, MediaWiki\Storage\SqlBlobStore\$dbDomain, MediaWiki\Storage\SqlBlobStore\$dbLoadBalancer, MediaWiki\Storage\SqlBlobStore\$extStoreAccess, and cache.

Member Function Documentation

◆ compressData()

MediaWiki\Storage\SqlBlobStore::compressData ( $blob)

If $wgCompressRevisions is enabled, we will compress data.

The input string is modified in place. Return value is the flags field: contains 'gzip' if the data is compressed, and 'utf-8' if we're saving in UTF-8 mode.

MCR migration note: this replaces Revision::compressRevisionText

Note
direct use is deprecated!
Todo:
make this private, there should be no need to use this method outside this class.
Parameters
mixed&$blobReference to a text
Returns
string

Definition at line 458 of file SqlBlobStore.php.

References $blob, wfDebug(), and wfLogWarning().

Referenced by MediaWiki\Storage\SqlBlobStore\storeBlob().

◆ decompressData()

MediaWiki\Storage\SqlBlobStore::decompressData (   $blob,
array  $blobFlags 
)

Re-converts revision text according to its flags.

MCR migration note: this replaces Revision::decompressRevisionText

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.
Parameters
string$blobBlob in compressed/encoded form.
array$blobFlagsCompression 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.
Returns
string|bool Decompressed text, or false on failure

Definition at line 498 of file SqlBlobStore.php.

References $blob, unserialize(), and wfWarn().

Referenced by MediaWiki\Storage\SqlBlobStore\expandBlob().

◆ expandBlob()

MediaWiki\Storage\SqlBlobStore::expandBlob (   $raw,
  $flags,
  $cacheKey = null 
)

Expand a raw data blob according to the flags given.

MCR migration note: this replaces Revision::getRevisionText

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.
Parameters
string$rawThe raw blob data, to be processed according to $flags. May be the blob itself, or the blob compressed, or just the address of the actual blob, depending on $flags.
string|string[]$flags Blob flags, such as 'external' or 'gzip'. Note that not including 'utf-8' in $flags will cause the data to be decoded according to the legacy encoding specified via setLegacyEncoding.
string | null$cacheKeyA blob address for use in the cache key. If not given, caching is disabled.
Returns
false|string The expanded blob or false on failure

Definition at line 406 of file SqlBlobStore.php.

References $blob, cache, MediaWiki\Storage\SqlBlobStore\decompressData(), false, MediaWiki\Storage\SqlBlobStore\getCacheKey(), MediaWiki\Storage\SqlBlobStore\getCacheTTL(), IExpiringStore\TTL_PROC_LONG, and use.

Referenced by MediaWiki\Storage\SqlBlobStore\fetchBlob().

◆ fetchBlob()

MediaWiki\Storage\SqlBlobStore::fetchBlob (   $blobAddress,
  $queryFlags 
)
private

MCR migration note: this corresponds to Revision::fetchText.

Parameters
string$blobAddress
int$queryFlags
Exceptions
BlobAccessException
Returns
string|false

Definition at line 307 of file SqlBlobStore.php.

References $blob, $options, MediaWiki\Storage\SqlBlobStore\expandBlob(), MediaWiki\Storage\SqlBlobStore\getDBConnection(), DBAccessObjectUtils\getDBOptions(), DBAccessObjectUtils\hasFlags(), list, null, wfLogWarning(), and wfWarn().

Referenced by MediaWiki\Storage\SqlBlobStore\getBlob().

◆ getBlob()

MediaWiki\Storage\SqlBlobStore::getBlob (   $blobAddress,
  $queryFlags = 0 
)

Retrieve a blob, given an address.

Currently hardcoded to the 'text' table storage engine.

MCR migration note: this replaces Revision::loadText

Parameters
string$blobAddress
int$queryFlags
Exceptions
BlobAccessException
Returns
string

Implements MediaWiki\Storage\BlobStore.

Definition at line 277 of file SqlBlobStore.php.

References $blob, cache, MediaWiki\Storage\SqlBlobStore\fetchBlob(), MediaWiki\Storage\SqlBlobStore\getCacheKey(), MediaWiki\Storage\SqlBlobStore\getCacheTTL(), IExpiringStore\TTL_PROC_LONG, and use.

◆ getCacheExpiry()

MediaWiki\Storage\SqlBlobStore::getCacheExpiry ( )
Returns
int time for which blobs can be cached, in seconds

Definition at line 125 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$cacheExpiry.

◆ getCacheKey()

MediaWiki\Storage\SqlBlobStore::getCacheKey (   $blobAddress)
private

Get a cache key for a given Blob address.

The cache key is constructed in a way that allows cached blobs from the same database to be re-used between wikis. For example, enwiki and frwiki will use the same cache keys for blobs from the wikidatawiki database.

Parameters
string$blobAddress
Returns
string

Definition at line 378 of file SqlBlobStore.php.

References cache.

Referenced by MediaWiki\Storage\SqlBlobStore\expandBlob(), and MediaWiki\Storage\SqlBlobStore\getBlob().

◆ getCacheTTL()

MediaWiki\Storage\SqlBlobStore::getCacheTTL ( )
private

Get the text cache TTL.

MCR migration note: this replaces Revision::getCacheTTL

Returns
int

Definition at line 550 of file SqlBlobStore.php.

References IExpiringStore\ATTR_EMULATION, cache, IExpiringStore\QOS_EMULATION_SQL, and WANObjectCache\TTL_UNCACHEABLE.

Referenced by MediaWiki\Storage\SqlBlobStore\expandBlob(), and MediaWiki\Storage\SqlBlobStore\getBlob().

◆ getCompressBlobs()

MediaWiki\Storage\SqlBlobStore::getCompressBlobs ( )
Returns
bool whether blobs should be compressed for storage

Definition at line 141 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$compressBlobs.

◆ getDBConnection()

MediaWiki\Storage\SqlBlobStore::getDBConnection (   $index)
private
Parameters
int$indexA database index, like DB_MASTER or DB_REPLICA
Returns
IDatabase

Definition at line 208 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\getDBLoadBalancer().

Referenced by MediaWiki\Storage\SqlBlobStore\fetchBlob(), and MediaWiki\Storage\SqlBlobStore\storeBlob().

◆ getDBLoadBalancer()

MediaWiki\Storage\SqlBlobStore::getDBLoadBalancer ( )
private

◆ getLegacyEncoding()

MediaWiki\Storage\SqlBlobStore::getLegacyEncoding ( )
Returns
false|string The legacy encoding to assume for blobs that are not marked as utf8. False means handling of legacy encoding is disabled, and utf8 assumed.

Definition at line 156 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$legacyEncoding.

◆ getLegacyEncodingConversionLang()

MediaWiki\Storage\SqlBlobStore::getLegacyEncodingConversionLang ( )
Returns
Language|null The locale to use when decoding from a legacy encoding, or null if handling of legacy encoding is disabled.

Definition at line 164 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$legacyEncodingConversionLang.

◆ getTextIdFromAddress()

MediaWiki\Storage\SqlBlobStore::getTextIdFromAddress (   $address)

Returns an ID corresponding to the old_id field in the text table, corresponding to the given $address.

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 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.
Parameters
string$address
Returns
int|null

Definition at line 583 of file SqlBlobStore.php.

References list, and null.

◆ getUseExternalStore()

MediaWiki\Storage\SqlBlobStore::getUseExternalStore ( )
Returns
bool Whether to use the ExternalStore mechanism for storing blobs.

Definition at line 183 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$useExternalStore.

◆ isReadOnly()

MediaWiki\Storage\SqlBlobStore::isReadOnly ( )

Check if the blob metadata or backing blob data store is read-only.

Returns
bool

Implements MediaWiki\Storage\BlobStore.

Definition at line 637 of file SqlBlobStore.php.

References false, and MediaWiki\Storage\SqlBlobStore\getDBLoadBalancer().

◆ makeAddressFromTextId()

static MediaWiki\Storage\SqlBlobStore::makeAddressFromTextId (   $id)
static

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.
Parameters
int$id
Returns
string

Definition at line 611 of file SqlBlobStore.php.

Referenced by Revision\RevisionStore\emulateMainSlot_1_29(), MediaWiki\Tests\Storage\SqlBlobStoreTest\testMakeAddressFromTextId(), and Revision\RevisionStore\updateRevisionTextId().

◆ setCacheExpiry()

MediaWiki\Storage\SqlBlobStore::setCacheExpiry (   $cacheExpiry)
Parameters
int$cacheExpirytime for which blobs can be cached, in seconds

Definition at line 132 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$cacheExpiry.

◆ setCompressBlobs()

MediaWiki\Storage\SqlBlobStore::setCompressBlobs (   $compressBlobs)
Parameters
bool$compressBlobswhether blobs should be compressed for storage

Definition at line 148 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$compressBlobs.

Referenced by MediaWiki\Tests\Storage\SqlBlobStoreTest\getBlobStore().

◆ setLegacyEncoding()

MediaWiki\Storage\SqlBlobStore::setLegacyEncoding (   $legacyEncoding,
Language  $language 
)
Parameters
string$legacyEncodingThe legacy encoding to assume for blobs that are not marked as utf8.
Language$languageThe locale to use when decoding from a legacy encoding.

Definition at line 173 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$legacyEncoding.

◆ setUseExternalStore()

MediaWiki\Storage\SqlBlobStore::setUseExternalStore (   $useExternalStore)
Parameters
bool$useExternalStoreWhether to use the ExternalStore mechanism for storing blobs.

Definition at line 190 of file SqlBlobStore.php.

References MediaWiki\Storage\SqlBlobStore\$useExternalStore.

◆ splitBlobAddress()

static MediaWiki\Storage\SqlBlobStore::splitBlobAddress (   $address)
static

Splits a blob address into three parts: the schema, the ID, and parameters/flags.

Since
1.33
Parameters
string$address
Exceptions
InvalidArgumentException
Returns
array [ $schema, $id, $parameters ], with $parameters being an assoc array.

Definition at line 625 of file SqlBlobStore.php.

References wfCgiToArray().

◆ storeBlob()

MediaWiki\Storage\SqlBlobStore::storeBlob (   $data,
  $hints = [] 
)

Stores an arbitrary blob of data and returns an address that can be used with getBlob() to retrieve the same blob of data,.

Parameters
string$data
array$hintsAn array of hints.
Exceptions
BlobAccessException
Returns
string an address that can be used with getBlob() to retrieve the data.

Implements MediaWiki\Storage\BlobStore.

Definition at line 223 of file SqlBlobStore.php.

References $e, MediaWiki\Storage\SqlBlobStore\compressData(), DB_MASTER, and MediaWiki\Storage\SqlBlobStore\getDBConnection().

Member Data Documentation

◆ $cache

WANObjectCache MediaWiki\Storage\SqlBlobStore::$cache
private

Definition at line 67 of file SqlBlobStore.php.

Referenced by MediaWiki\Storage\SqlBlobStore\__construct().

◆ $cacheExpiry

int MediaWiki\Storage\SqlBlobStore::$cacheExpiry = 604800
private

◆ $compressBlobs

bool MediaWiki\Storage\SqlBlobStore::$compressBlobs = false
private

◆ $dbDomain

string bool MediaWiki\Storage\SqlBlobStore::$dbDomain
private

DB domain ID of a wiki or false for the local one.

Definition at line 72 of file SqlBlobStore.php.

Referenced by MediaWiki\Storage\SqlBlobStore\__construct().

◆ $dbLoadBalancer

ILoadBalancer MediaWiki\Storage\SqlBlobStore::$dbLoadBalancer
private

◆ $extStoreAccess

ExternalStoreAccess MediaWiki\Storage\SqlBlobStore::$extStoreAccess
private

Definition at line 62 of file SqlBlobStore.php.

Referenced by MediaWiki\Storage\SqlBlobStore\__construct().

◆ $legacyEncoding

bool string MediaWiki\Storage\SqlBlobStore::$legacyEncoding = false
private

◆ $legacyEncodingConversionLang

Language null MediaWiki\Storage\SqlBlobStore::$legacyEncodingConversionLang = null
private

◆ $useExternalStore

boolean MediaWiki\Storage\SqlBlobStore::$useExternalStore = false
private

◆ TEXT_CACHE_GROUP

const MediaWiki\Storage\SqlBlobStore::TEXT_CACHE_GROUP = 'revisiontext:10'

Definition at line 52 of file SqlBlobStore.php.


The documentation for this class was generated from the following file: