Completed
Push — master ( 43bf95...2d7f23 )
by mw
02:19
created

SkinTemplateOutputModifier::canModifyOutput()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
rs 8.8571
c 1
b 0
f 0
ccs 8
cts 8
cp 1
cc 5
eloc 8
nc 4
nop 1
crap 5
1
<?php
2
3
namespace SBL;
4
5
use SMW\ApplicationFactory;
6
use OutputPage;
7
use Action;
8
use Title;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class SkinTemplateOutputModifier {
17
18
	/**
19
	 * @var HtmlBreadcrumbLinksBuilder
20
	 */
21
	private $htmlBreadcrumbLinksBuilder;
22
23
	/**
24
	 * @since 1.0
25
	 *
26
	 * @param HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder
27
	 */
28 6
	public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder ) {
29 6
		$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
30 6
	}
31
32
	/**
33
	 * @since  1.0
34
	 *
35
	 * @param OutputPage $output
36
	 *
37
	 * @return boolean
38
	 */
39 5
	public function modifyOutput( OutputPage $output ) {
40 5
		return $this->canModifyOutput( $output ) ? $this->doModifyOutput( $output ) : true;
41
	}
42
43
	/**
44
	 * @since  1.0
45
	 *
46
	 * @param &$template
47
	 */
48 1
	public function modifyTemplate( &$template ) {
49
50
		// Always set subtitle to be empty when SBL is used to avoid any output
51
		// distraction
52 1
		$template->data['subtitle'] = '';
53 1
	}
54
55 5
	private function canModifyOutput( OutputPage $output ) {
56
57 5
		if ( !$this->isEnabled( $output->getTitle() ) ) {
58 2
			return false;
59
		}
60
61 3
		if ( Action::getActionName( $output->getContext() ) !== 'view' ) {
62 1
			return false;
63
		}
64
65 2
		if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) {
66 1
			return false;
67
		}
68
69 1
		return true;
70
	}
71
72 1
	private function doModifyOutput( OutputPage $output ) {
73
74 1
		$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $output->getTitle() );
75
76 1
		$this->htmlBreadcrumbLinksBuilder->isRTL(
77 1
			$output->getTitle()->getPageLanguage()->isRTL()
78 1
		);
79
80 1
		$output->prependHTML( $this->htmlBreadcrumbLinksBuilder->getHtml() );
81
82 1
		return true;
83
	}
84
85 5
	private function isEnabled( Title $title ) {
86 5
		return $title->isKnown() &&
87 5
			!$title->isSpecialPage() &&
88 5
			ApplicationFactory::getInstance()->getNamespaceExaminer()->isSemanticEnabled( $title->getNamespace() );
89
	}
90
91
}
92