33use InvalidArgumentException;
37use Wikimedia\Assert\Assert;
126 Assert::parameterType(
'integer',
$cacheExpiry,
'$cacheExpiry' );
170 $this->legacyEncodingConversionLang = $language;
203 return $lb->getConnection( $index, [], $this->wikiId );
220 # Write to external storage if required
221 if ( $this->useExternalStore ) {
230 $flags .=
'external';
239 $old_id = $dbw->nextSequenceValue(
'text_old_id_seq' );
245 'old_flags' => $flags,
250 $textId = $dbw->insertId();
270 public function getBlob( $blobAddress, $queryFlags = 0 ) {
271 Assert::parameterType(
'string', $blobAddress,
'$blobAddress' );
277 function ( $unused, &$ttl, &$setOpts ) use ( $blobAddress, $queryFlags ) {
278 list( $index ) = DBAccessObjectUtils::getDBOptions( $queryFlags );
279 $setOpts += Database::getCacheSetOptions( $this->
getDBConnection( $index ) );
281 return $this->
fetchBlob( $blobAddress, $queryFlags );
286 if (
$blob ===
false ) {
302 private function fetchBlob( $blobAddress, $queryFlags ) {
306 if ( $schema ===
'tt' ) {
307 $textId = intval( $id );
313 if ( !$textId || $id !== (
string)$textId ) {
320 $queryFlags |= DBAccessObjectUtils::hasFlags( $queryFlags, self::READ_LATEST )
321 ? self::READ_LATEST_IMMUTABLE
324 list( $index,
$options, $fallbackIndex, $fallbackOptions ) =
325 DBAccessObjectUtils::getDBOptions( $queryFlags );
330 [
'old_text',
'old_flags' ],
331 [
'old_id' => $textId ],
338 if ( !$row && $fallbackIndex !==
null ) {
341 [
'old_text',
'old_flags' ],
342 [
'old_id' => $textId ],
349 wfWarn( __METHOD__ .
": No text row with ID $textId." );
353 $blob = $this->
expandBlob( $row->old_text, $row->old_flags, $blobAddress );
355 if (
$blob ===
false ) {
356 wfLogWarning( __METHOD__ .
": Bad data in text row $textId." );
374 return $this->
cache->makeGlobalKey(
377 $this->dbLoadBalancer->resolveDomainID( $this->wikiId ),
401 public function expandBlob( $raw, $flags, $cacheKey =
null ) {
402 if ( is_string( $flags ) ) {
403 $flags = explode(
',', $flags );
407 if ( in_array(
'external', $flags ) ) {
409 $parts = explode(
'://', $url, 2 );
410 if ( count( $parts ) == 1 || $parts[1] ==
'' ) {
416 return $this->
cache->getWithSetCallback(
419 function () use ( $url, $flags ) {
458 $blobFlags[] =
'utf-8';
460 if ( $this->compressBlobs ) {
461 if ( function_exists(
'gzdeflate' ) ) {
462 $deflated = gzdeflate(
$blob );
464 if ( $deflated ===
false ) {
468 $blobFlags[] =
'gzip';
471 wfDebug( __METHOD__ .
" -- no zlib support, not compressing\n" );
474 return implode(
',', $blobFlags );
494 Assert::parameterType(
'string',
$blob,
'$blob' );
496 if ( in_array(
'error', $blobFlags ) ) {
501 if ( in_array(
'gzip', $blobFlags ) ) {
502 # Deal with optional compression of archived pages.
503 # This can be done periodically via maintenance/compressOld.php, and
504 # as pages are saved if $wgCompressRevisions is set.
507 if (
$blob ===
false ) {
508 wfWarn( __METHOD__ .
': gzinflate() failed' );
513 if ( in_array(
'object', $blobFlags ) ) {
514 # Generic compressed storage
516 if ( !is_object( $obj ) ) {
520 $blob = $obj->getText();
524 if (
$blob !==
false && $this->legacyEncoding && $this->legacyEncodingConversionLang
525 && !in_array(
'utf-8', $blobFlags ) && !in_array(
'utf8', $blobFlags )
527 # Old revisions kept around in a legacy encoding?
528 # Upconvert on demand.
529 # ("utf8" checked for compatibility with some broken
530 # conversion scripts 2008-12-30)
531 $blob = $this->legacyEncodingConversionLang->iconv( $this->legacyEncoding,
'UTF-8',
$blob );
545 if ( $this->
cache->getQoS( WANObjectCache::ATTR_EMULATION )
546 <= WANObjectCache::QOS_EMULATION_SQL
549 $ttl = WANObjectCache::TTL_UNCACHEABLE;
551 $ttl = $this->cacheExpiry ?: WANObjectCache::TTL_UNCACHEABLE;
580 if ( $schema !==
'tt' ) {
584 $textId = intval( $id );
586 if ( !$textId || $id !== (
string)$textId ) {
587 throw new InvalidArgumentException(
"Malformed text_id: $id" );
618 if ( !preg_match(
'/^(\w+):(\w+)(\?(.*))?$/', $address, $m ) ) {
619 throw new InvalidArgumentException(
"Bad blob address: $address" );
622 $schema = strtolower( $m[1] );
624 $parameters = isset( $m[4] ) ?
wfCgiToArray( $m[4] ) : [];
626 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
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
processing should stop and the error should be shown to the user * false
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))