Completed
Pull Request — master (#47)
by mw
01:29
created

SkinTemplateOutputModifier::modify()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 9.584
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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 6
29 6
	/**
30 6
	 * @since 1.0
31
	 *
32
	 * @param HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder
33
	 * @param NamespaceExaminer $namespaceExaminer
34
	 */
35
	public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder, NamespaceExaminer $namespaceExaminer ) {
36
		$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
37
		$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
	}
39 5
40 5
	/**
41
	 * @since 1.5
42
	 *
43
	 * @param OutputPage $output
44
	 * @param &$template
45
	 */
46
	public function modify( OutputPage $output, &$template ) {
47
48 1
		if ( !$this->canModifyOutput( $output ) ) {
49
			return;
50
		}
51
52 1
		$title = $output->getTitle();
53 1
		$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $title );
54
55 5
		$this->htmlBreadcrumbLinksBuilder->isRTL(
56
			$title->getPageLanguage()->isRTL()
57 5
		);
58 2
59
		if ( !isset( $template->data['subtitle'] ) ) {
60
			$template->data['subtitle'] = '';
61 3
		}
62 1
63
		// We always assume `subtitle` is available!
64
		// https://github.com/wikimedia/mediawiki/blob/23ea2e4c2966f381eb7fd69b66a8d738bb24cc60/includes/skins/SkinTemplate.php#L292-L296
65 2
		$template->data['subtitle'] = $this->htmlBreadcrumbLinksBuilder->getHtml();
66 1
	}
67
68
	private function canModifyOutput( OutputPage $output ) {
69 1
70
		if ( !$this->isEnabled( $output->getTitle() ) ) {
71
			return false;
72 1
		}
73
74 1
		if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) {
75
			return false;
76 1
		}
77 1
78 1
		return true;
79
	}
80 1
81
	private function isEnabled( Title $title ) {
82 1
		return $title->isKnown() && !$title->isSpecialPage() && $this->namespaceExaminer->isSemanticEnabled( $title->getNamespace() );
83
	}
84
85
}
86