33use InvalidArgumentException;
37use Wikimedia\Assert\Assert;
121 Assert::parameterType(
'integer',
$cacheExpiry,
'$cacheExpiry' );
165 $this->legacyEncodingConversionLang = $language;
198 return $lb->getConnection( $index, [], $this->wikiId );
215 # Write to external storage if required
216 if ( $this->useExternalStore ) {
225 $flags .=
'external';
234 $old_id = $dbw->nextSequenceValue(
'text_old_id_seq' );
240 'old_flags' => $flags,
245 $textId = $dbw->insertId();
247 return 'tt:' . $textId;
265 public function getBlob( $blobAddress, $queryFlags = 0 ) {
266 Assert::parameterType(
'string', $blobAddress,
'$blobAddress' );
271 $this->
cache->makeKey(
'revisiontext',
'textid', $blobAddress ),
272 $this->getCacheTTL(),
273 function ( $unused, &$ttl, &$setOpts ) use ( $blobAddress, $queryFlags ) {
274 list( $index ) = DBAccessObjectUtils::getDBOptions( $queryFlags );
275 $setOpts += Database::getCacheSetOptions( $this->
getDBConnection( $index ) );
277 return $this->
fetchBlob( $blobAddress, $queryFlags );
282 if (
$blob ===
false ) {
298 private function fetchBlob( $blobAddress, $queryFlags ) {
302 if ( $schema ===
'tt' ) {
303 $textId = intval( $id );
309 if ( !$textId || $id !== (
string)$textId ) {
316 $queryFlags |= DBAccessObjectUtils::hasFlags( $queryFlags, self::READ_LATEST )
317 ? self::READ_LATEST_IMMUTABLE
320 list( $index,
$options, $fallbackIndex, $fallbackOptions ) =
321 DBAccessObjectUtils::getDBOptions( $queryFlags );
326 [
'old_text',
'old_flags' ],
327 [
'old_id' => $textId ],
334 if ( !$row && $fallbackIndex !==
null ) {
337 [
'old_text',
'old_flags' ],
338 [
'old_id' => $textId ],
345 wfWarn( __METHOD__ .
": No text row with ID $textId." );
349 $blob = $this->
expandBlob( $row->old_text, $row->old_flags, $blobAddress );
351 if (
$blob ===
false ) {
352 wfWarn( __METHOD__ .
": Bad data in text row $textId." );
377 public function expandBlob( $raw, $flags, $cacheKey =
null ) {
378 if ( is_string( $flags ) ) {
379 $flags = explode(
',', $flags );
383 if ( in_array(
'external', $flags ) ) {
385 $parts = explode(
'://', $url, 2 );
386 if ( count( $parts ) == 1 || $parts[1] ==
'' ) {
390 if ( $cacheKey && $this->wikiId ===
false ) {
394 return $this->
cache->getWithSetCallback(
396 $this->
cache->makeKey(
'revisiontext',
'textid', $cacheKey ),
397 $this->getCacheTTL(),
437 $blobFlags[] =
'utf-8';
439 if ( $this->compressBlobs ) {
440 if ( function_exists(
'gzdeflate' ) ) {
441 $deflated = gzdeflate(
$blob );
443 if ( $deflated ===
false ) {
447 $blobFlags[] =
'gzip';
450 wfDebug( __METHOD__ .
" -- no zlib support, not compressing\n" );
453 return implode(
',', $blobFlags );
472 if (
$blob ===
false ) {
477 if ( in_array(
'error', $blobFlags ) ) {
482 if ( in_array(
'gzip', $blobFlags ) ) {
483 # Deal with optional compression of archived pages.
484 # This can be done periodically via maintenance/compressOld.php, and
485 # as pages are saved if $wgCompressRevisions is set.
488 if (
$blob ===
false ) {
494 if ( in_array(
'object', $blobFlags ) ) {
495 # Generic compressed storage
497 if ( !is_object( $obj ) ) {
501 $blob = $obj->getText();
505 if (
$blob !==
false && $this->legacyEncoding && $this->legacyEncodingConversionLang
506 && !in_array(
'utf-8', $blobFlags ) && !in_array(
'utf8', $blobFlags )
508 # Old revisions kept around in a legacy encoding?
509 # Upconvert on demand.
510 # ("utf8" checked for compatibility with some broken
511 # conversion scripts 2008-12-30)
512 $blob = $this->legacyEncodingConversionLang->iconv( $this->legacyEncoding,
'UTF-8',
$blob );
526 if ( $this->
cache->getQoS( WANObjectCache::ATTR_EMULATION )
527 <= WANObjectCache::QOS_EMULATION_SQL
530 $ttl = WANObjectCache::TTL_UNCACHEABLE;
532 $ttl = $this->cacheExpiry ?: WANObjectCache::TTL_UNCACHEABLE;
560 if ( $schema !==
'tt' ) {
564 $textId = intval( $id );
566 if ( !$textId || $id !== (
string)$textId ) {
567 throw new InvalidArgumentException(
"Malformed text_id: $id" );
582 if ( !preg_match(
'/^(\w+):(\w+)(\?(.*))?$/', $address, $m ) ) {
583 throw new InvalidArgumentException(
"Bad blob address: $address" );
586 $schema = strtolower( $m[1] );
588 $parameters = isset( $m[4] ) ?
wfCgiToArray( $m[4] ) : [];
590 return [ $schema, $id, $parameters ];
unserialize( $serialized)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Helper class for DAO classes.
Constructor class for key/value blob data kept in external repositories.
static fetchFromURL( $url, array $params=[])
Fetch data from given URL.
static insertToDefault( $data, array $params=[])
Like insert() above, but does more of the work for us.
static defaultStoresAreReadOnly()
Internationalisation code.
Multi-datacenter aware caching interface.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
when a variable name is used in a function
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
returning false will NOT prevent logging $e
Interface for database access objects.
Generic base class for storage interfaces.
you have access to all of the normal MediaWiki so you can get a DB use the cache