Go to the documentation of this file.
33 use InvalidArgumentException;
37 use 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 ) {
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 ) {
321 ? self::READ_LATEST_IMMUTABLE
324 list( $index,
$options, $fallbackIndex, $fallbackOptions ) =
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 );
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 ];
static insertToDefault( $data, array $params=[])
Like insert() above, but does more of the work for us.
const TTL_UNCACHEABLE
Idiom for getWithSetCallback() callbacks to avoid calling set()
processing should stop and the error should be shown to the user * false
static defaultStoresAreReadOnly()
static fetchFromURL( $url, array $params=[])
Fetch data from given URL.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Interface for database access objects.
you have access to all of the normal MediaWiki so you can get a DB use the cache
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Generic base class for storage interfaces.
Constructor class for key/value blob data kept in external repositories.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
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))
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Helper class for DAO classes.
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
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
static hasFlags( $bitfield, $flags)
Multi-datacenter aware caching interface.
unserialize( $serialized)
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
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Internationalisation code.