33use InvalidArgumentException;
37use Wikimedia\Assert\Assert;
125 Assert::parameterType(
'integer',
$cacheExpiry,
'$cacheExpiry' );
169 $this->legacyEncodingConversionLang = $language;
202 return $lb->getConnection( $index, [], $this->wikiId );
219 # Write to external storage if required
220 if ( $this->useExternalStore ) {
229 $flags .=
'external';
238 $old_id = $dbw->nextSequenceValue(
'text_old_id_seq' );
244 'old_flags' => $flags,
249 $textId = $dbw->insertId();
269 public function getBlob( $blobAddress, $queryFlags = 0 ) {
270 Assert::parameterType(
'string', $blobAddress,
'$blobAddress' );
276 function ( $unused, &$ttl, &$setOpts )
use ( $blobAddress, $queryFlags ) {
278 return $this->
fetchBlob( $blobAddress, $queryFlags );
283 if (
$blob ===
false ) {
299 private function fetchBlob( $blobAddress, $queryFlags ) {
303 if ( $schema ===
'tt' ) {
304 $textId = intval( $id );
310 if ( !$textId || $id !== (
string)$textId ) {
317 $queryFlags |= DBAccessObjectUtils::hasFlags( $queryFlags, self::READ_LATEST )
318 ? self::READ_LATEST_IMMUTABLE
321 list( $index,
$options, $fallbackIndex, $fallbackOptions ) =
322 DBAccessObjectUtils::getDBOptions( $queryFlags );
327 [
'old_text',
'old_flags' ],
328 [
'old_id' => $textId ],
335 if ( !$row && $fallbackIndex !==
null ) {
338 [
'old_text',
'old_flags' ],
339 [
'old_id' => $textId ],
346 wfWarn( __METHOD__ .
": No text row with ID $textId." );
350 $blob = $this->
expandBlob( $row->old_text, $row->old_flags, $blobAddress );
352 if (
$blob ===
false ) {
353 wfLogWarning( __METHOD__ .
": Bad data in text row $textId." );
371 return $this->
cache->makeGlobalKey(
374 $this->dbLoadBalancer->resolveDomainID( $this->wikiId ),
398 public function expandBlob( $raw, $flags, $cacheKey =
null ) {
399 if ( is_string( $flags ) ) {
400 $flags = explode(
',', $flags );
404 if ( in_array(
'external', $flags ) ) {
406 $parts = explode(
'://', $url, 2 );
407 if ( count( $parts ) == 1 || $parts[1] ==
'' ) {
413 return $this->
cache->getWithSetCallback(
416 function ()
use ( $url, $flags ) {
455 $blobFlags[] =
'utf-8';
457 if ( $this->compressBlobs ) {
458 if ( function_exists(
'gzdeflate' ) ) {
459 $deflated = gzdeflate(
$blob );
461 if ( $deflated ===
false ) {
465 $blobFlags[] =
'gzip';
468 wfDebug( __METHOD__ .
" -- no zlib support, not compressing\n" );
471 return implode(
',', $blobFlags );
491 Assert::parameterType(
'string',
$blob,
'$blob' );
493 if ( in_array(
'error', $blobFlags ) ) {
498 if ( in_array(
'gzip', $blobFlags ) ) {
499 # Deal with optional compression of archived pages.
500 # This can be done periodically via maintenance/compressOld.php, and
501 # as pages are saved if $wgCompressRevisions is set.
504 if (
$blob ===
false ) {
505 wfWarn( __METHOD__ .
': gzinflate() failed' );
510 if ( in_array(
'object', $blobFlags ) ) {
511 # Generic compressed storage
513 if ( !is_object( $obj ) ) {
517 $blob = $obj->getText();
521 if (
$blob !==
false && $this->legacyEncoding && $this->legacyEncodingConversionLang
522 && !in_array(
'utf-8', $blobFlags ) && !in_array(
'utf8', $blobFlags )
524 # Old revisions kept around in a legacy encoding?
525 # Upconvert on demand.
526 # ("utf8" checked for compatibility with some broken
527 # conversion scripts 2008-12-30)
528 $blob = $this->legacyEncodingConversionLang->iconv( $this->legacyEncoding,
'UTF-8',
$blob );
542 if ( $this->
cache->getQoS( WANObjectCache::ATTR_EMULATION )
543 <= WANObjectCache::QOS_EMULATION_SQL
546 $ttl = WANObjectCache::TTL_UNCACHEABLE;
548 $ttl = $this->cacheExpiry ?: WANObjectCache::TTL_UNCACHEABLE;
577 if ( $schema !==
'tt' ) {
581 $textId = intval( $id );
583 if ( !$textId || $id !== (
string)$textId ) {
584 throw new InvalidArgumentException(
"Malformed text_id: $id" );
617 if ( !preg_match(
'/^(\w+):(\w+)(\?(.*))?$/', $address, $m ) ) {
618 throw new InvalidArgumentException(
"Bad blob address: $address" );
621 $schema = strtolower( $m[1] );
623 $parameters = isset( $m[4] ) ?
wfCgiToArray( $m[4] ) : [];
625 return [ $schema, $id, $parameters ];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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
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
Interface for database access objects.
Generic interface for lightweight expiring object stores.
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))