summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/src/DataAccess/PageContentFetcher.php
blob: 514cfe0aa10db8a1591502a89cbecd89324b3c71 (plain)
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
37
38
39
40
<?php

declare( strict_types = 1 );

namespace Maps\DataAccess;

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 = NS_MAIN ): ?\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' );
	}

}