Go to the documentation of this file.
33 use InvalidArgumentException;
37 use 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 ),
273 function ( $unused, &$ttl, &$setOpts )
use ( $blobAddress, $queryFlags ) {
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 ) {
317 ? self::READ_LATEST_IMMUTABLE
320 list( $index,
$options, $fallbackIndex, $fallbackOptions ) =
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 ),
398 function ()
use ( $url, $flags ) {
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 );
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 ];
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()
static defaultStoresAreReadOnly()
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
static fetchFromURL( $url, array $params=[])
Fetch data from given URL.
unserialize( $serialized)
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.
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
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.
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.
the array() calling protocol came about after MediaWiki 1.4rc1.