MediaWiki  1.33.0
ConcatenatedGzipHistoryBlob.php
Go to the documentation of this file.
1 <?php
28  public $mVersion = 0, $mCompressed = false, $mItems = [], $mDefaultHash = '';
29  public $mSize = 0;
30  public $mMaxSize = 10000000;
31  public $mMaxCount = 100;
32 
33  public function __construct() {
34  if ( !function_exists( 'gzdeflate' ) ) {
35  throw new MWException( "Need zlib support to read or write this "
36  . "kind of history object (ConcatenatedGzipHistoryBlob)\n" );
37  }
38  }
39 
44  public function addItem( $text ) {
45  $this->uncompress();
46  $hash = md5( $text );
47  if ( !isset( $this->mItems[$hash] ) ) {
48  $this->mItems[$hash] = $text;
49  $this->mSize += strlen( $text );
50  }
51  return $hash;
52  }
53 
58  public function getItem( $hash ) {
59  $this->uncompress();
60  if ( array_key_exists( $hash, $this->mItems ) ) {
61  return $this->mItems[$hash];
62  } else {
63  return false;
64  }
65  }
66 
71  public function setText( $text ) {
72  $this->uncompress();
73  $this->mDefaultHash = $this->addItem( $text );
74  }
75 
79  public function getText() {
80  $this->uncompress();
81  return $this->getItem( $this->mDefaultHash );
82  }
83 
89  public function removeItem( $hash ) {
90  $this->mSize -= strlen( $this->mItems[$hash] );
91  unset( $this->mItems[$hash] );
92  }
93 
97  public function compress() {
98  if ( !$this->mCompressed ) {
99  $this->mItems = gzdeflate( serialize( $this->mItems ) );
100  $this->mCompressed = true;
101  }
102  }
103 
107  public function uncompress() {
108  if ( $this->mCompressed ) {
109  $this->mItems = unserialize( gzinflate( $this->mItems ) );
110  $this->mCompressed = false;
111  }
112  }
113 
117  function __sleep() {
118  $this->compress();
119  return [ 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' ];
120  }
121 
122  function __wakeup() {
123  $this->uncompress();
124  }
125 
132  public function isHappy() {
133  return $this->mSize < $this->mMaxSize
134  && count( $this->mItems ) < $this->mMaxCount;
135  }
136 }
137 
138 // phpcs:ignore Generic.CodeAnalysis.UnconditionalIfStatement.Found
139 if ( false ) {
140  // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
141  // class name coerced to lowercase. We can improve efficiency by adding
142  // autoload entries for the lowercase variants of these classes (T166759).
143  // The code below is never executed, but it is picked up by the AutoloadGenerator
144  // parser, which scans for class_alias() calls.
145  class_alias( ConcatenatedGzipHistoryBlob::class, 'concatenatedgziphistoryblob' );
146 }
HistoryBlob
Base class for general text storage via the "object" flag in old_flags, or two-part external storage ...
Definition: HistoryBlob.php:28
ConcatenatedGzipHistoryBlob\$mMaxSize
$mMaxSize
Definition: ConcatenatedGzipHistoryBlob.php:30
ConcatenatedGzipHistoryBlob\__sleep
__sleep()
Definition: ConcatenatedGzipHistoryBlob.php:117
ConcatenatedGzipHistoryBlob\isHappy
isHappy()
Helper function for compression jobs Returns true until the object is "full" and ready to be committe...
Definition: ConcatenatedGzipHistoryBlob.php:132
captcha-old.count
count
Definition: captcha-old.py:249
ConcatenatedGzipHistoryBlob
Concatenated gzip (CGZ) storage Improves compression ratio by concatenating like objects before gzipp...
Definition: ConcatenatedGzipHistoryBlob.php:27
ConcatenatedGzipHistoryBlob\removeItem
removeItem( $hash)
Remove an item.
Definition: ConcatenatedGzipHistoryBlob.php:89
serialize
serialize()
Definition: ApiMessageTrait.php:134
php
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
ConcatenatedGzipHistoryBlob\$mMaxCount
$mMaxCount
Definition: ConcatenatedGzipHistoryBlob.php:31
ConcatenatedGzipHistoryBlob\$mVersion
$mVersion
Definition: ConcatenatedGzipHistoryBlob.php:28
MWException
MediaWiki exception.
Definition: MWException.php:26
ConcatenatedGzipHistoryBlob\getText
getText()
Definition: ConcatenatedGzipHistoryBlob.php:79
ConcatenatedGzipHistoryBlob\$mItems
$mItems
Definition: ConcatenatedGzipHistoryBlob.php:28
ConcatenatedGzipHistoryBlob\__construct
__construct()
Definition: ConcatenatedGzipHistoryBlob.php:33
ConcatenatedGzipHistoryBlob\$mDefaultHash
$mDefaultHash
Definition: ConcatenatedGzipHistoryBlob.php:28
ConcatenatedGzipHistoryBlob\$mCompressed
$mCompressed
Definition: ConcatenatedGzipHistoryBlob.php:28
ConcatenatedGzipHistoryBlob\uncompress
uncompress()
Uncompress bulk data.
Definition: ConcatenatedGzipHistoryBlob.php:107
ConcatenatedGzipHistoryBlob\$mSize
$mSize
Definition: ConcatenatedGzipHistoryBlob.php:29
ConcatenatedGzipHistoryBlob\getItem
getItem( $hash)
Definition: ConcatenatedGzipHistoryBlob.php:58
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:142
ConcatenatedGzipHistoryBlob\__wakeup
__wakeup()
Definition: ConcatenatedGzipHistoryBlob.php:122
ConcatenatedGzipHistoryBlob\addItem
addItem( $text)
Definition: ConcatenatedGzipHistoryBlob.php:44
ConcatenatedGzipHistoryBlob\compress
compress()
Compress the bulk data in the object.
Definition: ConcatenatedGzipHistoryBlob.php:97
class
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
ConcatenatedGzipHistoryBlob\setText
setText( $text)
Definition: ConcatenatedGzipHistoryBlob.php:71