MediaWiki REL1_33
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
139if ( 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}
serialize()
unserialize( $serialized)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Concatenated gzip (CGZ) storage Improves compression ratio by concatenating like objects before gzipp...
compress()
Compress the bulk data in the object.
isHappy()
Helper function for compression jobs Returns true until the object is "full" and ready to be committe...
MediaWiki exception.
Base class for general text storage via the "object" flag in old_flags, or two-part external storage ...