| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace MediaWiki\Parser\Parsoid\Config; |
| 21 |
|
| 22 |
use InvalidArgumentException; |
| 23 |
use MediaWiki\Revision\RevisionRecord; |
| 24 |
use Wikimedia\Parsoid\Config\PageContent as IPageContent; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PageContent extends IPageContent { |
| 32 |
private RevisionRecord $rev; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function __construct( RevisionRecord $rev ) { |
| 38 |
$this->rev = $rev; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
public function getRoles(): array { |
| 43 |
return $this->rev->getSlotRoles(); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
public function hasRole( string $role ): bool { |
| 48 |
return $this->rev->hasSlot( $role ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
private function checkRole( string $role ): void { |
| 57 |
if ( !$this->rev->hasSlot( $role ) ) { |
| 58 |
throw new InvalidArgumentException( "PageContent does not have role '$role'" ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public function getModel( string $role ): string { |
| 64 |
$this->checkRole( $role ); |
| 65 |
return $this->rev->getContent( $role )->getModel(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public function getFormat( string $role ): string { |
| 70 |
$this->checkRole( $role ); |
| 71 |
return $this->rev->getContent( $role )->getDefaultFormat(); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
public function getContent( string $role ): string { |
| 76 |
$this->checkRole( $role ); |
| 77 |
return $this->rev->getContentOrThrow( $role )->serialize(); |
| 78 |
} |
| 79 |
|
| 80 |
} |