MediaWiki REL1_40
HistoryBlobUtils.php
Go to the documentation of this file.
1<?php
2
4
6 public const NO_CLASSES = [ 'allowed_classes' => false ];
7
13 public static function getAllowedClasses() {
14 return [
15 ConcatenatedGzipHistoryBlob::class,
16 DiffHistoryBlob::class,
17 HistoryBlobCurStub::class,
18 HistoryBlobStub::class
19 ];
20 }
21
29 public static function unserialize( string $str, bool $allowDouble = false ) {
30 $obj = unserialize( $str, [ 'allowed_classes' => self::getAllowedClasses() ] );
31 if ( is_string( $obj ) && $allowDouble ) {
32 // Correct for old double-serialization bug (needed by HistoryBlobStub only)
33 $obj = unserialize( $obj, [ 'allowed_classes' => self::getAllowedClasses() ] );
34 }
35 foreach ( self::getAllowedClasses() as $class ) {
36 if ( $obj instanceof $class ) {
37 return $obj;
38 }
39 }
40 return null;
41 }
42
49 public static function unserializeArray( string $str ): array {
50 $array = unserialize( $str, [ 'allowed_classes' => false ] );
51 if ( !is_array( $array ) ) {
52 throw new BlobAccessException( "Expected array in serialized string" );
53 }
54 return $array;
55 }
56}
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.