Completed
Push — master ( 712a1b...ea14c4 )
by mw
03:33 queued 02:13
created

src/SkinTemplateOutputModifier.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SBL;
4
5
use SMW\ApplicationFactory;
6
use SMW\NamespaceExaminer;
7
use OutputPage;
8
use Action;
9
use Title;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class SkinTemplateOutputModifier {
18
19
	/**
20
	 * @var HtmlBreadcrumbLinksBuilder
21
	 */
22
	private $htmlBreadcrumbLinksBuilder;
23
24
	/**
25
	 * @var NnamespaceExaminer
26
	 */
27
	private $namespaceExaminer;
28
29
	/**
30
	 * @since 1.0
31
	 *
32
	 * @param HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder
33
	 * @param NamespaceExaminer $namespaceExaminer
34
	 */
35 4
	public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder, NamespaceExaminer $namespaceExaminer ) {
36 4
		$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
37 4
		$this->namespaceExaminer = $namespaceExaminer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $namespaceExaminer of type object<SMW\NamespaceExaminer> is incompatible with the declared type object<SBL\NnamespaceExaminer> of property $namespaceExaminer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38 4
	}
39
40
	/**
41
	 * @since 1.5
42
	 *
43
	 * @param OutputPage $output
44
	 * @param &$template
45
	 */
46 3
	public function modify( OutputPage $output, &$template ) {
47
48 3
		if ( !$this->canModifyOutput( $output ) ) {
49 3
			return;
50
		}
51
52
		$title = $output->getTitle();
53
		$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $title );
54
55
		$this->htmlBreadcrumbLinksBuilder->isRTL(
56
			$title->getPageLanguage()->isRTL()
57
		);
58
59
		if ( !isset( $template->data['subtitle'] ) ) {
60
			$template->data['subtitle'] = '';
61
		}
62
63
		// We always assume `subtitle` is available!
64
		// https://github.com/wikimedia/mediawiki/blob/23ea2e4c2966f381eb7fd69b66a8d738bb24cc60/includes/skins/SkinTemplate.php#L292-L296
65
		$template->data['subtitle'] = $this->htmlBreadcrumbLinksBuilder->getHtml();
66
	}
67
68 3
	private function canModifyOutput( OutputPage $output ) {
69
70 3
		if ( !$this->isEnabled( $output->getTitle() ) ) {
71 3
			return false;
72
		}
73
74
		if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) {
75
			return false;
76
		}
77
78
		return true;
79
	}
80
81 3
	private function isEnabled( Title $title ) {
82 3
		return $title->isKnown() && !$title->isSpecialPage() && $this->namespaceExaminer->isSemanticEnabled( $title->getNamespace() );
83
	}
84
85
}
86