Skip to content

Instantly share code, notes, and snippets.

@JeroenDeDauw
Created July 28, 2018 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeroenDeDauw/cd18cd68d4239a56d129603a2a220056 to your computer and use it in GitHub Desktop.
Save JeroenDeDauw/cd18cd68d4239a56d129603a2a220056 to your computer and use it in GitHub Desktop.
<?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