-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPageContentFetcher.php
More file actions
36 lines (25 loc) · 838 Bytes
/
PageContentFetcher.php
File metadata and controls
36 lines (25 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare( strict_types = 1 );
namespace ProfessionalWiki\AutomatedValues\DataAccess;
use MediaWiki\Revision\RevisionLookup;
class PageContentFetcher {
private \TitleParser $titleParser;
private RevisionLookup $revisionLookup;
public function __construct( \TitleParser $titleParser, RevisionLookup $revisionLookup ) {
$this->titleParser = $titleParser;
$this->revisionLookup = $revisionLookup;
}
public function getPageContent( string $pageTitle ): ?\Content {
try {
$title = $this->titleParser->parseTitle( $pageTitle );
} catch ( \MalformedTitleException $e ) {
return null;
}
$revision = $this->revisionLookup->getRevisionByTitle( $title );
if ( $revision === null ) {
return null;
}
// $revision->getRevisionRecord()->getContent( 'main' );
return $revision->getContent( 'main' );
}
}