MediaWiki 1.42.0
HistoryBlobUtils.php
Go to the documentation of this file.
1<?php
2
4
6
12 public static function getAllowedClasses() {
13 return [
14 ConcatenatedGzipHistoryBlob::class,
15 DiffHistoryBlob::class,
16 HistoryBlobCurStub::class,
17 HistoryBlobStub::class
18 ];
19 }
20
28 public static function unserialize( string $str, bool $allowDouble = false ) {
29 $obj = unserialize( $str, [ 'allowed_classes' => self::getAllowedClasses() ] );
30 if ( is_string( $obj ) && $allowDouble ) {
31 // Correct for old double-serialization bug (needed by HistoryBlobStub only)
32 $obj = unserialize( $obj, [ 'allowed_classes' => self::getAllowedClasses() ] );
33 }
34 foreach ( self::getAllowedClasses() as $class ) {
35 if ( $obj instanceof $class ) {
36 return $obj;
37 }
38 }
39 return null;
40 }
41
48 public static function unserializeArray( string $str ): array {
49 $array = unserialize( $str, [ 'allowed_classes' => false ] );
50 if ( !is_array( $array ) ) {
51 throw new BlobAccessException( "Expected array in serialized string" );
52 }
53 return $array;
54 }
55}
static unserializeArray(string $str)
Unserialize array data with no classes.
static unserialize(string $str, bool $allowDouble=false)
Unserialize a HistoryBlob.
static getAllowedClasses()
Get the classes which are allowed to be contained in a text or ES row.
Exception representing a failure to access a data blob.