| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Parser\Parsoid; |
| 4 |
|
| 5 |
use MediaWiki\Json\JsonConstants; |
| 6 |
use Wikimedia\Parsoid\Core\PageBundle; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
trait PageBundleJsonTrait { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
protected function newPageBundleFromJson( array $data ): ?PageBundle { |
| 23 |
if ( !$data ) { |
| 24 |
return null; |
| 25 |
} |
| 26 |
return new PageBundle( |
| 27 |
$data['html'], |
| 28 |
$data['parsoid'] ?? null, |
| 29 |
$data['mw'] ?? null, |
| 30 |
$data['version'] ?? null, |
| 31 |
$data['headers'] ?? null, |
| 32 |
$data['contentmodel'] ?? null |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
protected function jsonSerializePageBundle( PageBundle $bundle ): array { |
| 42 |
return [ |
| 43 |
JsonConstants::TYPE_ANNOTATION => get_class( $bundle ), |
| 44 |
'html' => $bundle->html, |
| 45 |
'parsoid' => $bundle->parsoid, |
| 46 |
'mw' => $bundle->mw, |
| 47 |
'version' => $bundle->version, |
| 48 |
'headers' => $bundle->headers, |
| 49 |
'contentmodel' => $bundle->contentmodel |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
} |