Completed
Push — master ( ad9ce2...b11c6d )
by mw
02:04
created

hasEnabledSubpageByNamespace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace SBL;
4
5
use OutputPage;
6
use Title;
7
use SMW\DataValueFactory;
8
use SMW\DIWikiPage;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class PageDisplayOutputModifier {
17
18
	/**
19
	 * @var boolean
20
	 */
21
	private $hideSubpageParent;
22
23
	/**
24
	 * @var array
25
	 */
26
	private $subpageByNamespace;
27
28
	/**
29
	 * @since  1.0
30
	 *
31
	 * @param boolean $hideSubpageParent
32
	 */
33 3
	public function hideSubpageParent( $hideSubpageParent ) {
34 3
		$this->hideSubpageParent = $hideSubpageParent;
35 3
	}
36
37
	/**
38
	 * @since  1.0
39
	 *
40
	 * @param array $subpageByNamespace
41
	 */
42 3
	public function setSubpageByNamespace( array $subpageByNamespace ) {
43 3
		$this->subpageByNamespace = $subpageByNamespace;
44 3
	}
45
46
	/**
47
	 * @since  1.0
48
	 *
49
	 * @param OutputPage $outputPage
50
	 */
51 3
	public function modifyOutput( OutputPage $outputPage ) {
52
53 3
		$outputPage->addModuleStyles( 'ext.semanticbreadcrumblinks.styles' );
54 3
		$outputPage->addModules( 'ext.semanticbreadcrumblinks' );
55
56 3
		if ( !$this->hideSubpageParent || !$this->hasEnabledSubpageByNamespace( $outputPage->getTitle()->getNamespace() ) ) {
57 2
			return;
58
		}
59
60 1
		if ( $outputPage->getTitle()->isSubpage() ) {
61 1
			$outputPage->setPageTitle( $this->getPageTitle( $outputPage->getTitle() ) );
62 1
		}
63 1
	}
64
65 1
	private function getPageTitle( Title $title ) {
66
67 1
		$displayTitle = '';
68
69 1
		$dataValue = DataValueFactory::getInstance()->newDataItemValue(
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DataValueFactory::newDataItemValue() has been deprecated with message: since 2.4, use DataValueFactory::newDataValueByItem

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
70 1
			DIWikiPage::newFromTitle( $title )
71 1
		);
72
73
		// 2.4+
74 1
		if ( method_exists( $dataValue , 'getDisplayTitle' ) ) {
75 1
			$displayTitle = $dataValue->getDisplayTitle();
76 1
		}
77
78 1
		return $displayTitle !== '' ? $displayTitle : $title->getSubpageText();
79
	}
80
81 2
	private function hasEnabledSubpageByNamespace( $namespace ) {
82 2
		return isset( $this->subpageByNamespace[ $namespace ] ) && $this->subpageByNamespace[ $namespace ];
83
	}
84
85
}
86