MediaWiki  master
BagOStuff.php
Go to the documentation of this file.
1 <?php
34 
64 abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
66  protected $locks = [];
68  protected $lastError = self::ERR_NONE;
70  protected $keyspace = 'local';
72  protected $logger;
74  protected $asyncHandler;
76  protected $syncTimeout;
78  protected $segmentationSize;
81 
83  private $debugMode = false;
85  private $duplicateKeyLookups = [];
87  private $reportDupes = false;
89  private $dupeTrackScheduled = false;
90 
92  protected $busyCallbacks = [];
93 
96 
98  protected $attrMap = [];
99 
101  const READ_LATEST = 1; // use latest data for replicated stores
102  const READ_VERIFIED = 2; // promise that caller can tell when keys are stale
104  const WRITE_SYNC = 4; // synchronously write to all locations for replicated stores
105  const WRITE_CACHE_ONLY = 8; // Only change state of the in-memory cache
106  const WRITE_ALLOW_SEGMENTS = 16; // Allow partitioning of the value if it is large
107  const WRITE_PRUNE_SEGMENTS = 32; // Delete all partition segments of the value
108 
110  const SEGMENT_COMPONENT = 'segment';
111 
129  public function __construct( array $params = [] ) {
130  $this->setLogger( $params['logger'] ?? new NullLogger() );
131 
132  if ( isset( $params['keyspace'] ) ) {
133  $this->keyspace = $params['keyspace'];
134  }
135 
136  $this->asyncHandler = $params['asyncHandler'] ?? null;
137 
138  if ( !empty( $params['reportDupes'] ) && is_callable( $this->asyncHandler ) ) {
139  $this->reportDupes = true;
140  }
141 
142  $this->syncTimeout = $params['syncTimeout'] ?? 3;
143  $this->segmentationSize = $params['segmentationSize'] ?? 8388608; // 8MiB
144  $this->segmentedValueMaxSize = $params['segmentedValueMaxSize'] ?? 67108864; // 64MiB
145  }
146 
151  public function setLogger( LoggerInterface $logger ) {
152  $this->logger = $logger;
153  }
154 
158  public function setDebug( $bool ) {
159  $this->debugMode = $bool;
160  }
161 
174  final public function getWithSetCallback( $key, $ttl, $callback, $flags = 0 ) {
175  $value = $this->get( $key, $flags );
176 
177  if ( $value === false ) {
178  if ( !is_callable( $callback ) ) {
179  throw new InvalidArgumentException( "Invalid cache miss callback provided." );
180  }
181  $value = call_user_func( $callback );
182  if ( $value !== false ) {
183  $this->set( $key, $value, $ttl, $flags );
184  }
185  }
186 
187  return $value;
188  }
189 
203  public function get( $key, $flags = 0 ) {
204  $this->trackDuplicateKeys( $key );
205 
206  return $this->resolveSegments( $key, $this->doGet( $key, $flags ) );
207  }
208 
213  private function trackDuplicateKeys( $key ) {
214  if ( !$this->reportDupes ) {
215  return;
216  }
217 
218  if ( !isset( $this->duplicateKeyLookups[$key] ) ) {
219  // Track that we have seen this key. This N-1 counting style allows
220  // easy filtering with array_filter() later.
221  $this->duplicateKeyLookups[$key] = 0;
222  } else {
223  $this->duplicateKeyLookups[$key] += 1;
224 
225  if ( $this->dupeTrackScheduled === false ) {
226  $this->dupeTrackScheduled = true;
227  // Schedule a callback that logs keys processed more than once by get().
228  call_user_func( $this->asyncHandler, function () {
229  $dups = array_filter( $this->duplicateKeyLookups );
230  foreach ( $dups as $key => $count ) {
231  $this->logger->warning(
232  'Duplicate get(): "{key}" fetched {count} times',
233  // Count is N-1 of the actual lookup count
234  [ 'key' => $key, 'count' => $count + 1, ]
235  );
236  }
237  } );
238  }
239  }
240  }
241 
248  abstract protected function doGet( $key, $flags = 0, &$casToken = null );
249 
259  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
260  if (
261  ( $flags & self::WRITE_ALLOW_SEGMENTS ) != self::WRITE_ALLOW_SEGMENTS ||
262  is_infinite( $this->segmentationSize )
263  ) {
264  return $this->doSet( $key, $value, $exptime, $flags );
265  }
266 
267  $serialized = $this->serialize( $value );
268  $segmentSize = $this->getSegmentationSize();
269  $maxTotalSize = $this->getSegmentedValueMaxSize();
270 
271  $size = strlen( $serialized );
272  if ( $size <= $segmentSize ) {
273  // Since the work of serializing it was already done, just use it inline
274  return $this->doSet(
275  $key,
277  $exptime,
278  $flags
279  );
280  } elseif ( $size > $maxTotalSize ) {
281  $this->setLastError( "Key $key exceeded $maxTotalSize bytes." );
282 
283  return false;
284  }
285 
286  $chunksByKey = [];
287  $segmentHashes = [];
288  $count = intdiv( $size, $segmentSize ) + ( ( $size % $segmentSize ) ? 1 : 0 );
289  for ( $i = 0; $i < $count; ++$i ) {
290  $segment = substr( $serialized, $i * $segmentSize, $segmentSize );
291  $hash = sha1( $segment );
292  $chunkKey = $this->makeGlobalKey( self::SEGMENT_COMPONENT, $key, $hash );
293  $chunksByKey[$chunkKey] = $segment;
294  $segmentHashes[] = $hash;
295  }
296 
297  $ok = $this->setMulti( $chunksByKey, $exptime, $flags );
298  if ( $ok ) {
299  // Only when all segments are stored should the main key be changed
300  $ok = $this->doSet(
301  $key,
302  SerializedValueContainer::newSegmented( $segmentHashes ),
303  $exptime,
304  $flags
305  );
306  }
307 
308  return $ok;
309  }
310 
320  abstract protected function doSet( $key, $value, $exptime = 0, $flags = 0 );
321 
333  public function delete( $key, $flags = 0 ) {
334  if ( ( $flags & self::WRITE_PRUNE_SEGMENTS ) != self::WRITE_PRUNE_SEGMENTS ) {
335  return $this->doDelete( $key, $flags );
336  }
337 
338  $mainValue = $this->doGet( $key, self::READ_LATEST );
339  if ( !$this->doDelete( $key, $flags ) ) {
340  return false;
341  }
342 
343  if ( !SerializedValueContainer::isSegmented( $mainValue ) ) {
344  return true; // no segments to delete
345  }
346 
347  $orderedKeys = array_map(
348  function ( $segmentHash ) use ( $key ) {
349  return $this->makeGlobalKey( self::SEGMENT_COMPONENT, $key, $segmentHash );
350  },
352  );
353 
354  return $this->deleteMulti( $orderedKeys, $flags );
355  }
356 
364  abstract protected function doDelete( $key, $flags = 0 );
365 
375  abstract public function add( $key, $value, $exptime = 0, $flags = 0 );
376 
394  public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
395  return $this->mergeViaCas( $key, $callback, $exptime, $attempts, $flags );
396  }
397 
408  protected function mergeViaCas( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
409  do {
410  $casToken = null; // passed by reference
411  // Get the old value and CAS token from cache
412  $this->clearLastError();
413  $currentValue = $this->resolveSegments(
414  $key,
415  $this->doGet( $key, self::READ_LATEST, $casToken )
416  );
417  if ( $this->getLastError() ) {
418  $this->logger->warning(
419  __METHOD__ . ' failed due to I/O error on get() for {key}.',
420  [ 'key' => $key ]
421  );
422 
423  return false; // don't spam retries (retry only on races)
424  }
425 
426  // Derive the new value from the old value
427  $value = call_user_func( $callback, $this, $key, $currentValue, $exptime );
428  $hadNoCurrentValue = ( $currentValue === false );
429  unset( $currentValue ); // free RAM in case the value is large
430 
431  $this->clearLastError();
432  if ( $value === false ) {
433  $success = true; // do nothing
434  } elseif ( $hadNoCurrentValue ) {
435  // Try to create the key, failing if it gets created in the meantime
436  $success = $this->add( $key, $value, $exptime, $flags );
437  } else {
438  // Try to update the key, failing if it gets changed in the meantime
439  $success = $this->cas( $casToken, $key, $value, $exptime, $flags );
440  }
441  if ( $this->getLastError() ) {
442  $this->logger->warning(
443  __METHOD__ . ' failed due to I/O error for {key}.',
444  [ 'key' => $key ]
445  );
446 
447  return false; // IO error; don't spam retries
448  }
449 
450  } while ( !$success && --$attempts );
451 
452  return $success;
453  }
454 
465  protected function cas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
466  if ( !$this->lock( $key, 0 ) ) {
467  return false; // non-blocking
468  }
469 
470  $curCasToken = null; // passed by reference
471  $this->doGet( $key, self::READ_LATEST, $curCasToken );
472  if ( $casToken === $curCasToken ) {
473  $success = $this->set( $key, $value, $exptime, $flags );
474  } else {
475  $this->logger->info(
476  __METHOD__ . ' failed due to race condition for {key}.',
477  [ 'key' => $key ]
478  );
479 
480  $success = false; // mismatched or failed
481  }
482 
483  $this->unlock( $key );
484 
485  return $success;
486  }
487 
505  public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
506  $expiry = $this->convertToExpiry( $exptime );
507  $delete = ( $expiry != 0 && $expiry < $this->getCurrentTime() );
508 
509  if ( !$this->lock( $key, 0 ) ) {
510  return false;
511  }
512  // Use doGet() to avoid having to trigger resolveSegments()
513  $blob = $this->doGet( $key, self::READ_LATEST );
514  if ( $blob ) {
515  if ( $delete ) {
516  $ok = $this->doDelete( $key, $flags );
517  } else {
518  $ok = $this->doSet( $key, $blob, $exptime, $flags );
519  }
520  } else {
521  $ok = false;
522  }
523 
524  $this->unlock( $key );
525 
526  return $ok;
527  }
528 
540  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
541  // Avoid deadlocks and allow lock reentry if specified
542  if ( isset( $this->locks[$key] ) ) {
543  if ( $rclass != '' && $this->locks[$key]['class'] === $rclass ) {
544  ++$this->locks[$key]['depth'];
545  return true;
546  } else {
547  return false;
548  }
549  }
550 
551  $fname = __METHOD__;
552  $expiry = min( $expiry ?: INF, self::TTL_DAY );
553  $loop = new WaitConditionLoop(
554  function () use ( $key, $expiry, $fname ) {
555  $this->clearLastError();
556  if ( $this->add( "{$key}:lock", 1, $expiry ) ) {
557  return WaitConditionLoop::CONDITION_REACHED; // locked!
558  } elseif ( $this->getLastError() ) {
559  $this->logger->warning(
560  $fname . ' failed due to I/O error for {key}.',
561  [ 'key' => $key ]
562  );
563 
564  return WaitConditionLoop::CONDITION_ABORTED; // network partition?
565  }
566 
567  return WaitConditionLoop::CONDITION_CONTINUE;
568  },
569  $timeout
570  );
571 
572  $code = $loop->invoke();
573  $locked = ( $code === $loop::CONDITION_REACHED );
574  if ( $locked ) {
575  $this->locks[$key] = [ 'class' => $rclass, 'depth' => 1 ];
576  } elseif ( $code === $loop::CONDITION_TIMED_OUT ) {
577  $this->logger->warning(
578  "$fname failed due to timeout for {key}.",
579  [ 'key' => $key, 'timeout' => $timeout ]
580  );
581  }
582 
583  return $locked;
584  }
585 
592  public function unlock( $key ) {
593  if ( isset( $this->locks[$key] ) && --$this->locks[$key]['depth'] <= 0 ) {
594  unset( $this->locks[$key] );
595 
596  $ok = $this->doDelete( "{$key}:lock" );
597  if ( !$ok ) {
598  $this->logger->warning(
599  __METHOD__ . ' failed to release lock for {key}.',
600  [ 'key' => $key ]
601  );
602  }
603 
604  return $ok;
605  }
606 
607  return true;
608  }
609 
626  final public function getScopedLock( $key, $timeout = 6, $expiry = 30, $rclass = '' ) {
627  $expiry = min( $expiry ?: INF, self::TTL_DAY );
628 
629  if ( !$this->lock( $key, $timeout, $expiry, $rclass ) ) {
630  return null;
631  }
632 
633  $lSince = $this->getCurrentTime(); // lock timestamp
634 
635  return new ScopedCallback( function () use ( $key, $lSince, $expiry ) {
636  $latency = 0.050; // latency skew (err towards keeping lock present)
637  $age = ( $this->getCurrentTime() - $lSince + $latency );
638  if ( ( $age + $latency ) >= $expiry ) {
639  $this->logger->warning(
640  "Lock for {key} held too long ({age} sec).",
641  [ 'key' => $key, 'age' => $age ]
642  );
643  return; // expired; it's not "safe" to delete the key
644  }
645  $this->unlock( $key );
646  } );
647  }
648 
658  public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
659  // stub
660  return false;
661  }
662 
669  public function getMulti( array $keys, $flags = 0 ) {
670  $valuesBykey = $this->doGetMulti( $keys, $flags );
671  foreach ( $valuesBykey as $key => $value ) {
672  // Resolve one blob at a time (avoids too much I/O at once)
673  $valuesBykey[$key] = $this->resolveSegments( $key, $value );
674  }
675 
676  return $valuesBykey;
677  }
678 
685  protected function doGetMulti( array $keys, $flags = 0 ) {
686  $res = [];
687  foreach ( $keys as $key ) {
688  $val = $this->doGet( $key, $flags );
689  if ( $val !== false ) {
690  $res[$key] = $val;
691  }
692  }
693 
694  return $res;
695  }
696 
708  public function setMulti( array $data, $exptime = 0, $flags = 0 ) {
709  if ( ( $flags & self::WRITE_ALLOW_SEGMENTS ) === self::WRITE_ALLOW_SEGMENTS ) {
710  throw new InvalidArgumentException( __METHOD__ . ' got WRITE_ALLOW_SEGMENTS' );
711  }
712 
713  $res = true;
714  foreach ( $data as $key => $value ) {
715  $res = $this->doSet( $key, $value, $exptime, $flags ) && $res;
716  }
717 
718  return $res;
719  }
720 
731  public function deleteMulti( array $keys, $flags = 0 ) {
732  $res = true;
733  foreach ( $keys as $key ) {
734  $res = $this->doDelete( $key, $flags ) && $res;
735  }
736 
737  return $res;
738  }
739 
746  abstract public function incr( $key, $value = 1 );
747 
754  public function decr( $key, $value = 1 ) {
755  return $this->incr( $key, - $value );
756  }
757 
770  public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) {
771  $this->clearLastError();
772  $newValue = $this->incr( $key, $value );
773  if ( $newValue === false && !$this->getLastError() ) {
774  // No key set; initialize
775  $newValue = $this->add( $key, (int)$init, $ttl ) ? $init : false;
776  if ( $newValue === false && !$this->getLastError() ) {
777  // Raced out initializing; increment
778  $newValue = $this->incr( $key, $value );
779  }
780  }
781 
782  return $newValue;
783  }
784 
792  protected function resolveSegments( $key, $mainValue ) {
793  if ( SerializedValueContainer::isUnified( $mainValue ) ) {
794  return $this->unserialize( $mainValue->{SerializedValueContainer::UNIFIED_DATA} );
795  }
796 
797  if ( SerializedValueContainer::isSegmented( $mainValue ) ) {
798  $orderedKeys = array_map(
799  function ( $segmentHash ) use ( $key ) {
800  return $this->makeGlobalKey( self::SEGMENT_COMPONENT, $key, $segmentHash );
801  },
803  );
804 
805  $segmentsByKey = $this->doGetMulti( $orderedKeys );
806 
807  $parts = [];
808  foreach ( $orderedKeys as $segmentKey ) {
809  if ( isset( $segmentsByKey[$segmentKey] ) ) {
810  $parts[] = $segmentsByKey[$segmentKey];
811  } else {
812  return false; // missing segment
813  }
814  }
815 
816  return $this->unserialize( implode( '', $parts ) );
817  }
818 
819  return $mainValue;
820  }
821 
827  public function getLastError() {
828  return $this->lastError;
829  }
830 
835  public function clearLastError() {
836  $this->lastError = self::ERR_NONE;
837  }
838 
844  protected function setLastError( $err ) {
845  $this->lastError = $err;
846  }
847 
868  public function addBusyCallback( callable $workCallback ) {
869  $this->busyCallbacks[] = $workCallback;
870  }
871 
875  protected function debug( $text ) {
876  if ( $this->debugMode ) {
877  $this->logger->debug( "{class} debug: $text", [
878  'class' => static::class,
879  ] );
880  }
881  }
882 
887  protected function expiryIsRelative( $exptime ) {
888  return ( $exptime != 0 && $exptime < ( 10 * self::TTL_YEAR ) );
889  }
890 
896  protected function convertToExpiry( $exptime ) {
897  if ( $this->expiryIsRelative( $exptime ) ) {
898  return (int)$this->getCurrentTime() + $exptime;
899  } else {
900  return $exptime;
901  }
902  }
903 
911  protected function convertToRelative( $exptime ) {
912  if ( $exptime >= ( 10 * self::TTL_YEAR ) ) {
913  $exptime -= (int)$this->getCurrentTime();
914  if ( $exptime <= 0 ) {
915  $exptime = 1;
916  }
917  return $exptime;
918  } else {
919  return $exptime;
920  }
921  }
922 
929  protected function isInteger( $value ) {
930  if ( is_int( $value ) ) {
931  return true;
932  } elseif ( !is_string( $value ) ) {
933  return false;
934  }
935 
936  $integer = (int)$value;
937 
938  return ( $value === (string)$integer );
939  }
940 
949  public function makeKeyInternal( $keyspace, $args ) {
950  $key = $keyspace;
951  foreach ( $args as $arg ) {
952  $key .= ':' . str_replace( ':', '%3A', $arg );
953  }
954  return strtr( $key, ' ', '_' );
955  }
956 
965  public function makeGlobalKey( $class, $component = null ) {
966  return $this->makeKeyInternal( 'global', func_get_args() );
967  }
968 
977  public function makeKey( $class, $component = null ) {
978  return $this->makeKeyInternal( $this->keyspace, func_get_args() );
979  }
980 
986  public function getQoS( $flag ) {
987  return $this->attrMap[$flag] ?? self::QOS_UNKNOWN;
988  }
989 
994  public function getSegmentationSize() {
996  }
997 
1002  public function getSegmentedValueMaxSize() {
1004  }
1005 
1012  protected function mergeFlagMaps( array $bags ) {
1013  $map = [];
1014  foreach ( $bags as $bag ) {
1015  foreach ( $bag->attrMap as $attr => $rank ) {
1016  if ( isset( $map[$attr] ) ) {
1017  $map[$attr] = min( $map[$attr], $rank );
1018  } else {
1019  $map[$attr] = $rank;
1020  }
1021  }
1022  }
1023 
1024  return $map;
1025  }
1026 
1032  public function getCurrentTime() {
1033  return $this->wallClockOverride ?: microtime( true );
1034  }
1035 
1041  public function setMockTime( &$time ) {
1042  $this->wallClockOverride =& $time;
1043  }
1044 
1050  protected function serialize( $value ) {
1051  return is_int( $value ) ? $value : serialize( $value );
1052  }
1053 
1059  protected function unserialize( $value ) {
1060  return $this->isInteger( $value ) ? (int)$value : unserialize( $value );
1061  }
1062 }
clearLastError()
Clear the "last error" registry.
Definition: BagOStuff.php:835
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))
getWithSetCallback( $key, $ttl, $callback, $flags=0)
Get an item with the given key, regenerating and setting it if not found.
Definition: BagOStuff.php:174
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
Definition: BagOStuff.php:540
deleteMulti(array $keys, $flags=0)
Batch deletion.
Definition: BagOStuff.php:731
doGetMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
Definition: BagOStuff.php:685
bool $reportDupes
Definition: BagOStuff.php:87
$success
bool $dupeTrackScheduled
Definition: BagOStuff.php:89
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
int [] $attrMap
Map of (ATTR_* class constant => QOS_* class constant)
Definition: BagOStuff.php:98
unlock( $key)
Release an advisory lock on a key string.
Definition: BagOStuff.php:592
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
debug( $text)
Definition: BagOStuff.php:875
const WRITE_PRUNE_SEGMENTS
Definition: BagOStuff.php:107
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
unserialize( $value)
Definition: BagOStuff.php:1059
$value
int $segmentedValueMaxSize
Bytes; maximum total size of a segmented cache value.
Definition: BagOStuff.php:80
makeKey( $class, $component=null)
Make a cache key, scoped to this instance&#39;s keyspace.
Definition: BagOStuff.php:977
float null $wallClockOverride
Definition: BagOStuff.php:95
doGet( $key, $flags=0, &$casToken=null)
expiryIsRelative( $exptime)
Definition: BagOStuff.php:887
int $lastError
ERR_* class constant.
Definition: BagOStuff.php:68
setLastError( $err)
Set the "last error" registry.
Definition: BagOStuff.php:844
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1799
getSegmentationSize()
Definition: BagOStuff.php:994
string $keyspace
Definition: BagOStuff.php:70
getCurrentTime()
Definition: BagOStuff.php:1032
if( $line===false) $args
Definition: cdb.php:64
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: BagOStuff.php:827
convertToExpiry( $exptime)
Convert an optionally relative time to an absolute time.
Definition: BagOStuff.php:896
setDebug( $bool)
Definition: BagOStuff.php:158
__construct(array $params=[])
$params include:
Definition: BagOStuff.php:129
int $syncTimeout
Seconds.
Definition: BagOStuff.php:76
bool $debugMode
Definition: BagOStuff.php:83
callable [] $busyCallbacks
Definition: BagOStuff.php:92
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
const READ_VERIFIED
Definition: BagOStuff.php:102
array $duplicateKeyLookups
Definition: BagOStuff.php:85
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
Definition: BagOStuff.php:505
doDelete( $key, $flags=0)
Delete an item.
$res
Definition: database.txt:21
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
Definition: BagOStuff.php:669
const WRITE_SYNC
Bitfield constants for set()/merge()
Definition: BagOStuff.php:104
static newSegmented(array $segmentHashList)
$params
const READ_LATEST
Bitfield constants for get()/getMulti()
Definition: BagOStuff.php:101
setMockTime(&$time)
Definition: BagOStuff.php:1041
makeKeyInternal( $keyspace, $args)
Construct a cache key.
Definition: BagOStuff.php:949
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map...
Definition: BagOStuff.php:1012
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
Definition: BagOStuff.php:754
trackDuplicateKeys( $key)
Track the number of times that a given key has been used.
Definition: BagOStuff.php:213
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:780
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:123
resolveSegments( $key, $mainValue)
Get and reassemble the chunks of blob at the given key.
Definition: BagOStuff.php:792
convertToRelative( $exptime)
Convert an optionally absolute expiry time to a relative time.
Definition: BagOStuff.php:911
getQoS( $flag)
Definition: BagOStuff.php:986
int $segmentationSize
Bytes; chunk size of segmented cache values.
Definition: BagOStuff.php:78
const WRITE_CACHE_ONLY
Definition: BagOStuff.php:105
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
Definition: injection.txt:35
const WRITE_ALLOW_SEGMENTS
Definition: BagOStuff.php:106
getScopedLock( $key, $timeout=6, $expiry=30, $rclass='')
Get a lightweight exclusive self-unlocking lock.
Definition: BagOStuff.php:626
LoggerInterface $logger
Definition: BagOStuff.php:72
setLogger(LoggerInterface $logger)
Definition: BagOStuff.php:151
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
Definition: BagOStuff.php:394
mergeViaCas( $key, $callback, $exptime=0, $attempts=10, $flags=0)
Definition: BagOStuff.php:408
setMulti(array $data, $exptime=0, $flags=0)
Batch insertion/replace.
Definition: BagOStuff.php:708
addBusyCallback(callable $workCallback)
Let a callback be run to avoid wasting time on special blocking calls.
Definition: BagOStuff.php:868
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete all objects expiring before a certain date.
Definition: BagOStuff.php:658
serialize( $value)
Definition: BagOStuff.php:1050
array [] $locks
Lock tracking.
Definition: BagOStuff.php:66
foreach( $res as $row) $serialized
isInteger( $value)
Check if a value is an integer.
Definition: BagOStuff.php:929
getSegmentedValueMaxSize()
Definition: BagOStuff.php:1002
makeGlobalKey( $class, $component=null)
Make a global cache key.
Definition: BagOStuff.php:965
cas( $casToken, $key, $value, $exptime=0, $flags=0)
Check and set an item.
Definition: BagOStuff.php:465
callable null $asyncHandler
Definition: BagOStuff.php:74
incrWithInit( $key, $ttl, $value=1, $init=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: BagOStuff.php:770