Completed
Push — master ( f9239d...c22ee7 )
by mw
09:43
created

SkinTemplateOutputModifier   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 11
c 5
b 0
f 1
lcom 1
cbo 3
dl 0
loc 72
ccs 25
cts 25
cp 1
rs 10

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 12 3
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 5
	public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder ) {
29 5
		$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
30 5
	}
31
32
	/**
33
	 * @since  1.0
34
	 *
35
	 * @param OutputPage $output
36
	 *
37
	 * @return boolean
38
	 */
39 4
	public function modifyOutput( OutputPage $output ) {
40 4
		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 4
	private function canModifyOutput( OutputPage $output ) {
56
57 4
		if ( !$this->isEnabled( $output->getTitle() ) ) {
58 2
			return false;
59
		}
60
61 2
		if ( Action::getActionName( $output->getContext() ) !== 'view' ) {
62 1
			return false;
63
		}
64
65 1
		return true;
66
	}
67
68 1
	private function doModifyOutput( OutputPage $output ) {
69
70 1
		$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $output->getTitle() );
71
72 1
		$this->htmlBreadcrumbLinksBuilder->setRTLDirectionalityState(
73 1
			$output->getTitle()->getPageLanguage()->isRTL()
74 1
		);
75
76 1
		$output->prependHTML( $this->htmlBreadcrumbLinksBuilder->getHtml() );
77
78 1
		return true;
79
	}
80
81 4
	private function isEnabled( Title $title ) {
82 4
		return $title->isKnown() &&
83 4
			!$title->isSpecialPage() &&
84 4
			ApplicationFactory::getInstance()->getNamespaceExaminer()->isSemanticEnabled( $title->getNamespace() );
85
	}
86
87
}
88