Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5979779
ConcatenatedGzipHistoryBlob.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ConcatenatedGzipHistoryBlob.php
View Options
<?php
/**
* Efficient concatenated text storage.
*
* @license GPL-2.0-or-later
* @file
*/
/**
* Concatenated gzip (CGZ) storage
* Improves compression ratio by concatenating like objects before gzipping
*
* WARNING: Objects of this class are serialized and permanently stored in the DB.
* Do not change the name or visibility of any property!
*/
class
ConcatenatedGzipHistoryBlob
implements
HistoryBlob
{
/** @var int */
public
$mVersion
=
0
;
/** @var bool */
public
$mCompressed
=
false
;
/** @var string[]|string Array if uncompressed, string if compressed */
public
$mItems
=
[];
/** @var string */
public
$mDefaultHash
=
''
;
/** @var int */
public
$mSize
=
0
;
/** @var int */
public
$mMaxSize
=
10
_000_000
;
/** @var int */
public
$mMaxCount
=
100
;
public
function
__construct
()
{
if
(
!
function_exists
(
'gzdeflate'
)
)
{
throw
new
RuntimeException
(
"Need zlib support to read or write this "
.
"kind of history object (ConcatenatedGzipHistoryBlob)
\n
"
);
}
}
/**
* @param string $text
* @return string
*/
public
function
addItem
(
$text
)
{
$this
->
uncompress
();
$hash
=
md5
(
$text
);
if
(
!
isset
(
$this
->
mItems
[
$hash
]
)
)
{
$this
->
mItems
[
$hash
]
=
$text
;
$this
->
mSize
+=
strlen
(
$text
);
}
return
$hash
;
}
/**
* @param string $hash
* @return string|false
*/
public
function
getItem
(
$hash
)
{
$this
->
uncompress
();
if
(
array_key_exists
(
$hash
,
$this
->
mItems
)
)
{
return
$this
->
mItems
[
$hash
];
}
else
{
return
false
;
}
}
/**
* @param string $text
* @return void
*/
public
function
setText
(
$text
)
{
$this
->
uncompress
();
$this
->
mDefaultHash
=
$this
->
addItem
(
$text
);
}
/**
* @return string|false
*/
public
function
getText
()
{
$this
->
uncompress
();
return
$this
->
getItem
(
$this
->
mDefaultHash
);
}
/**
* Remove an item
*
* @param string $hash
*/
public
function
removeItem
(
$hash
)
{
$this
->
mSize
-=
strlen
(
$this
->
mItems
[
$hash
]
);
unset
(
$this
->
mItems
[
$hash
]
);
}
/**
* Compress the bulk data in the object
*/
public
function
compress
()
{
if
(
!
$this
->
mCompressed
)
{
$this
->
mItems
=
gzdeflate
(
serialize
(
$this
->
mItems
)
);
$this
->
mCompressed
=
true
;
}
}
/**
* Uncompress bulk data
*/
public
function
uncompress
()
{
if
(
$this
->
mCompressed
)
{
$this
->
mItems
=
HistoryBlobUtils
::
unserializeArray
(
gzinflate
(
$this
->
mItems
)
);
$this
->
mCompressed
=
false
;
}
}
/**
* @return array
*/
public
function
__sleep
()
{
$this
->
compress
();
return
[
'mVersion'
,
'mCompressed'
,
'mItems'
,
'mDefaultHash'
];
}
public
function
__wakeup
()
{
$this
->
uncompress
();
}
/**
* Helper function for compression jobs
* Returns true until the object is "full" and ready to be committed
*
* @return bool
*/
public
function
isHappy
()
{
return
$this
->
mSize
<
$this
->
mMaxSize
&&
count
(
$this
->
mItems
)
<
$this
->
mMaxCount
;
}
}
// Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
// class name coerced to lowercase. We can improve efficiency by adding
// autoload entries for the lowercase variants of these classes (T166759).
// The code below is never executed, but it is picked up by the AutoloadGenerator
// parser, which scans for class_alias() calls.
/*
class_alias( ConcatenatedGzipHistoryBlob::class, 'concatenatedgziphistoryblob' );
*/
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 21:05 (5 d, 12 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9d/4e/e87e0ff7bcdbd6532377232fec17
Default Alt Text
ConcatenatedGzipHistoryBlob.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment