3 * Service for loading and storing data blobs.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Storage
;
26 * Service for loading and storing data blobs.
28 * @note This was written to act as a drop-in replacement for the corresponding
29 * static methods in Revision.
36 * Hint key for use with storeBlob, indicating the general role the block
37 * takes in the application. For instance, it should be "page-content" if
38 * the blob represents a Content object.
40 const DESIGNATION_HINT
= 'designation';
43 * Hint key for use with storeBlob, indicating the page the blob is associated with.
44 * This may be used for sharding.
46 const PAGE_HINT
= 'page_id';
49 * Hint key for use with storeBlob, indicating the slot the blob is associated with.
50 * May be relevant for reference counting.
52 const ROLE_HINT
= 'role_name';
55 * Hint key for use with storeBlob, indicating the revision the blob is associated with.
56 * This may be used for differential storage and reference counting.
58 const REVISION_HINT
= 'rev_id';
61 * Hint key for use with storeBlob, indicating the parent revision of the revision
62 * the blob is associated with. This may be used for differential storage.
64 const PARENT_HINT
= 'rev_parent_id';
67 * Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the
68 * method. This can be used to avoid re-calculating the hash if it is needed by the BlobStore.
70 const SHA1_HINT
= 'cont_sha1';
73 * Hint key for use with storeBlob, indicating the model of the content encoded in the
74 * given blob. May be used to implement optimized storage for some well known models.
76 const MODEL_HINT
= 'cont_model';
79 * Hint key for use with storeBlob, indicating the serialization format used to create
80 * the blob, as a MIME type. May be used for optimized storage in the underlying database.
82 const FORMAT_HINT
= 'cont_format';
85 * Retrieve a blob, given an address.
87 * MCR migration note: this replaces Revision::loadText
89 * @param string $blobAddress The blob address as returned by storeBlob(),
90 * such as "tt:12345" or "ex:DB://s16/456/9876".
91 * @param int $queryFlags See IDBAccessObject.
93 * @throws BlobAccessException
94 * @return string binary blob data
96 public function getBlob( $blobAddress, $queryFlags = 0 );
99 * Stores an arbitrary blob of data and returns an address that can be used with
100 * getBlob() to retrieve the same blob of data,
102 * @param string $data raw binary data
103 * @param array $hints An array of hints. Implementations may use the hints to optimize storage.
104 * All hints are optional, supported hints depend on the implementation. Hint names by
105 * convention correspond to the names of fields in the database. Callers are encouraged to
106 * provide the well known hints as defined by the XXX_HINT constants.
108 * @throws BlobAccessException
109 * @return string an address that can be used with getBlob() to retrieve the data.
111 public function storeBlob( $data, $hints = [] );