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
|
4 |
|
public function hideSubpageParent( $hideSubpageParent ) { |
34
|
4 |
|
$this->hideSubpageParent = $hideSubpageParent; |
35
|
4 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @since 1.0 |
39
|
|
|
* |
40
|
|
|
* @param array $subpageByNamespace |
41
|
|
|
*/ |
42
|
4 |
|
public function setSubpageByNamespace( array $subpageByNamespace ) { |
43
|
4 |
|
$this->subpageByNamespace = $subpageByNamespace; |
44
|
4 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @since 1.0 |
48
|
|
|
* |
49
|
|
|
* @param OutputPage $outputPage |
50
|
|
|
*/ |
51
|
4 |
|
public function modifyOutput( OutputPage $outputPage ) { |
52
|
|
|
|
53
|
4 |
|
$outputPage->addModuleStyles( 'ext.semanticbreadcrumblinks.styles' ); |
54
|
4 |
|
$outputPage->addModules( 'ext.semanticbreadcrumblinks' ); |
55
|
|
|
|
56
|
4 |
|
$title = $outputPage->getTitle(); |
57
|
|
|
|
58
|
4 |
|
if ( !$this->hideSubpageParent || !$this->hasEnabledSubpageByNamespace( $title->getNamespace() ) ) { |
59
|
2 |
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
if ( $this->isSubpage( $title ) ) { |
63
|
1 |
|
$outputPage->setPageTitle( $this->getPageTitle( $title ) ); |
64
|
1 |
|
} |
65
|
2 |
|
} |
66
|
|
|
|
67
|
2 |
|
private function isSubpage( Title $title ) { |
68
|
|
|
|
69
|
2 |
|
if ( !$title->isSubpage() ) { |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
$parts = explode( '/', $title->getText() ); |
74
|
|
|
|
75
|
2 |
|
if ( count( $parts ) > 1 ) { |
76
|
1 |
|
unset( $parts[count( $parts ) - 1] ); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
2 |
|
$base = implode( '/', $parts ); |
80
|
|
|
|
81
|
|
|
// #23 (Foo /Bar vs. Foo/ Bar) |
82
|
2 |
|
return substr( $base, -1 ) !== ' '; |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
private function getPageTitle( Title $title ) { |
86
|
|
|
|
87
|
1 |
|
$displayTitle = ''; |
88
|
|
|
|
89
|
1 |
|
$dataValue = DataValueFactory::getInstance()->newDataItemValue( |
|
|
|
|
90
|
1 |
|
DIWikiPage::newFromTitle( $title ) |
91
|
1 |
|
); |
92
|
|
|
|
93
|
|
|
// 2.4+ |
94
|
1 |
|
if ( method_exists( $dataValue , 'getDisplayTitle' ) ) { |
95
|
1 |
|
$displayTitle = $dataValue->getDisplayTitle(); |
96
|
1 |
|
} |
97
|
|
|
|
98
|
1 |
|
return $displayTitle !== '' ? $displayTitle : $title->getSubpageText(); |
99
|
|
|
} |
100
|
|
|
|
101
|
3 |
|
private function hasEnabledSubpageByNamespace( $namespace ) { |
102
|
3 |
|
return isset( $this->subpageByNamespace[ $namespace ] ) && $this->subpageByNamespace[ $namespace ]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
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.