1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SBL; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\NamespaceExaminer; |
7
|
|
|
use OutputPage; |
8
|
|
|
use Action; |
9
|
|
|
use Title; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class SkinTemplateOutputModifier { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var HtmlBreadcrumbLinksBuilder |
21
|
|
|
*/ |
22
|
|
|
private $htmlBreadcrumbLinksBuilder; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var NnamespaceExaminer |
26
|
|
|
*/ |
27
|
|
|
private $namespaceExaminer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @since 1.0 |
31
|
|
|
* |
32
|
|
|
* @param HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder |
33
|
|
|
* @param NamespaceExaminer $namespaceExaminer |
34
|
|
|
*/ |
35
|
5 |
|
public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder, NamespaceExaminer $namespaceExaminer ) { |
36
|
5 |
|
$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder; |
37
|
5 |
|
$this->namespaceExaminer = $namespaceExaminer; |
|
|
|
|
38
|
5 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @since 1.5 |
42
|
|
|
* |
43
|
|
|
* @param OutputPage $output |
44
|
|
|
* @param &$template |
45
|
|
|
*/ |
46
|
4 |
|
public function modify( OutputPage $output, &$template ) { |
47
|
|
|
|
48
|
4 |
|
if ( !$this->canModifyOutput( $output ) ) { |
49
|
3 |
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
$title = $output->getTitle(); |
53
|
1 |
|
$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $title ); |
54
|
|
|
|
55
|
1 |
|
$this->htmlBreadcrumbLinksBuilder->isRTL( |
56
|
1 |
|
$title->getPageLanguage()->isRTL() |
57
|
1 |
|
); |
58
|
|
|
|
59
|
1 |
|
if ( !isset( $template->data['subtitle'] ) ) { |
60
|
|
|
$template->data['subtitle'] = ''; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// We always assume `subtitle` is available! |
64
|
|
|
// https://github.com/wikimedia/mediawiki/blob/23ea2e4c2966f381eb7fd69b66a8d738bb24cc60/includes/skins/SkinTemplate.php#L292-L296 |
65
|
1 |
|
$template->data['subtitle'] .= $this->htmlBreadcrumbLinksBuilder->getHtml(); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
4 |
|
/** |
69
|
|
|
* For MW 1.35 |
70
|
4 |
|
* @since 2.0.1 |
71
|
3 |
|
* |
72
|
|
|
* @param OutputPage $output |
73
|
|
|
*/ |
74
|
1 |
|
public function modify2( OutputPage $output) |
75
|
|
|
{ |
76
|
|
|
if ( !$this->canModifyOutput( $output ) ) { |
77
|
|
|
return; |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
$title = $output->getTitle(); |
81
|
4 |
|
$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $title ); |
82
|
4 |
|
|
83
|
|
|
$this->htmlBreadcrumbLinksBuilder->isRTL( |
84
|
|
|
$title->getPageLanguage()->isRTL() |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$output->addSubtitle($this->htmlBreadcrumbLinksBuilder->getHtml()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function canModifyOutput( OutputPage $output ) { |
91
|
|
|
|
92
|
|
|
if ( !$this->isEnabled( $output->getTitle() ) ) { |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) { |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return true; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function isEnabled( Title $title ) { |
104
|
|
|
return $title->isKnown() && !$title->isSpecialPage() && $this->namespaceExaminer->isSemanticEnabled( $title->getNamespace() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..