Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
40.00% |
8 / 20 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LocalWikiPageProvider | |
40.00% |
8 / 20 |
|
50.00% |
2 / 4 |
13.78 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| loadPageRevisionProperties | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| loadData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| getCachedSegmentsKeyComponents | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Wikispeech\Segment; |
| 4 | |
| 5 | /** |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @license GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | use IContextSource; |
| 12 | use MediaWiki\MediaWikiServices; |
| 13 | use MediaWiki\Revision\RevisionRecord; |
| 14 | use MediaWiki\Revision\RevisionStore; |
| 15 | use Mediawiki\Title\Title; |
| 16 | |
| 17 | /** |
| 18 | * @since 0.1.10 |
| 19 | */ |
| 20 | class LocalWikiPageProvider extends AbstractPageProvider { |
| 21 | |
| 22 | /** @var IContextSource */ |
| 23 | private $context; |
| 24 | |
| 25 | /** @var RevisionStore */ |
| 26 | private $revisionStore; |
| 27 | |
| 28 | /** |
| 29 | * @since 0.1.10 |
| 30 | * @param IContextSource $context |
| 31 | * @param RevisionStore $revisionStore |
| 32 | */ |
| 33 | public function __construct( |
| 34 | IContextSource $context, |
| 35 | RevisionStore $revisionStore |
| 36 | ) { |
| 37 | $this->context = $context; |
| 38 | $this->revisionStore = $revisionStore; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 0.1.10 |
| 43 | * @param int $revisionId |
| 44 | * @return PageRevisionProperties |
| 45 | * @throws DeletedRevisionException |
| 46 | */ |
| 47 | public function loadPageRevisionProperties( int $revisionId ): PageRevisionProperties { |
| 48 | $revisionRecord = $this->revisionStore->getRevisionById( $revisionId ); |
| 49 | if ( !$revisionRecord || !$revisionRecord->audienceCan( |
| 50 | RevisionRecord::DELETED_TEXT, |
| 51 | RevisionRecord::FOR_THIS_USER, |
| 52 | $this->context->getUser() |
| 53 | ) |
| 54 | ) { |
| 55 | throw new DeletedRevisionException( 'A deleted revision id was provided' ); |
| 56 | } |
| 57 | return new PageRevisionProperties( |
| 58 | Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() ), |
| 59 | $revisionRecord->getPageId() |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param Title $title |
| 65 | * @since 0.1.10 |
| 66 | */ |
| 67 | public function loadData( Title $title ): void { |
| 68 | $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title ); |
| 69 | $parserOptions = $page->makeParserOptions( $this->context ); |
| 70 | $parserOutput = $page->getParserOutput( $parserOptions ); |
| 71 | $this->setDisplayTitle( $parserOutput->getDisplayTitle() ); |
| 72 | $this->setPageContent( $parserOutput->runOutputPipeline( $parserOptions )->getContentHolderText() ); |
| 73 | $this->setRevisionId( $page->getLatest() ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @since 0.1.10 |
| 78 | * @return string |
| 79 | */ |
| 80 | public function getCachedSegmentsKeyComponents(): string { |
| 81 | return 'local'; |
| 82 | } |
| 83 | |
| 84 | } |