Created
July 28, 2018 01:33
-
-
Save JeroenDeDauw/cd18cd68d4239a56d129603a2a220056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Maps; | |
use MediaWiki\Storage\RevisionLookup; | |
/** | |
* @licence GNU GPL v2+ | |
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | |
*/ | |
class PageContentFetcher { | |
private $titleParser; | |
private $revisionLookup; | |
public function __construct( \TitleParser $titleParser, RevisionLookup $revisionLookup ) { | |
$this->titleParser = $titleParser; | |
$this->revisionLookup = $revisionLookup; | |
} | |
public function getPageContent( string $pageTitle, int $defaultNamespace )/*: ?\Content */{ | |
try { | |
$title = $this->titleParser->parseTitle( $pageTitle, $defaultNamespace ); | |
} | |
catch ( \MalformedTitleException $e ) { | |
return null; | |
} | |
$revision = $this->revisionLookup->getRevisionByTitle( $title ); | |
if ( $revision === null ) { | |
return null; | |
} | |
return $revision->getContent( 'main' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment