Completed
Push — master ( fec93e...712a1b )
by mw
02:31
created

SkinTemplateOutputModifier   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 3
dl 0
loc 76
ccs 12
cts 26
cp 0.4615
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A modifyOutput() 0 3 2
A modifyTemplate() 0 6 1
A canModifyOutput() 0 16 5
A doModifyOutput() 0 12 1
A isEnabled() 0 5 3
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
	public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder ) {
29
		$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
30
	}
31
32
	/**
33
	 * @since  1.0
34
	 *
35 4
	 * @param OutputPage $output
36 4
	 *
37 4
	 * @return boolean
38 4
	 */
39
	public function modifyOutput( OutputPage $output ) {
40
		return $this->canModifyOutput( $output ) ? $this->doModifyOutput( $output ) : true;
41
	}
42
43
	/**
44
	 * @since  1.0
45
	 *
46 3
	 * @param &$template
47
	 */
48 3
	public function modifyTemplate( &$template ) {
49 3
50
		// Always set subtitle to be empty when SBL is used to avoid any output
51
		// distraction
52
		$template->data['subtitle'] = '';
53
	}
54
55
	private function canModifyOutput( OutputPage $output ) {
56
57
		if ( !$this->isEnabled( $output->getTitle() ) ) {
58
			return false;
59
		}
60
61
		if ( Action::getActionName( $output->getContext() ) !== 'view' ) {
62
			return false;
63
		}
64
65
		if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) {
66
			return false;
67
		}
68 3
69
		return true;
70 3
	}
71 3
72
	private function doModifyOutput( OutputPage $output ) {
73
74
		$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $output->getTitle() );
75
76
		$this->htmlBreadcrumbLinksBuilder->isRTL(
77
			$output->getTitle()->getPageLanguage()->isRTL()
78
		);
79
80
		$output->prependHTML( $this->htmlBreadcrumbLinksBuilder->getHtml() );
81 3
82 3
		return true;
83
	}
84
85
	private function isEnabled( Title $title ) {
86
		return $title->isKnown() &&
87
			!$title->isSpecialPage() &&
88
			ApplicationFactory::getInstance()->getNamespaceExaminer()->isSemanticEnabled( $title->getNamespace() );
89
	}
90
91
}
92