| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Storage\BlobAccessException; |
| 4 |
|
| 5 |
class HistoryBlobUtils { |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
public static function getAllowedClasses() { |
| 13 |
return [ |
| 14 |
ConcatenatedGzipHistoryBlob::class, |
| 15 |
DiffHistoryBlob::class, |
| 16 |
HistoryBlobCurStub::class, |
| 17 |
HistoryBlobStub::class |
| 18 |
]; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 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 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 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 |
} |