-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSkinTemplateOutputModifier.php
85 lines (67 loc) · 1.92 KB
/
SkinTemplateOutputModifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace SBL;
use SMW\ApplicationFactory;
use SMW\NamespaceExaminer;
use OutputPage;
use Action;
use Title;
/**
* @license GNU GPL v2+
* @since 1.0
*
* @author mwjames
*/
class SkinTemplateOutputModifier {
/**
* @var HtmlBreadcrumbLinksBuilder
*/
private $htmlBreadcrumbLinksBuilder;
/**
* @var NnamespaceExaminer
*/
private $namespaceExaminer;
/**
* @since 1.0
*
* @param HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder
* @param NamespaceExaminer $namespaceExaminer
*/
public function __construct( HtmlBreadcrumbLinksBuilder $htmlBreadcrumbLinksBuilder, NamespaceExaminer $namespaceExaminer ) {
$this->htmlBreadcrumbLinksBuilder = $htmlBreadcrumbLinksBuilder;
$this->namespaceExaminer = $namespaceExaminer;
}
/**
* @since 1.5
*
* @param OutputPage $output
* @param &$template
*/
public function modify( OutputPage $output, &$template ) {
if ( !$this->canModifyOutput( $output ) ) {
return;
}
$title = $output->getTitle();
$this->htmlBreadcrumbLinksBuilder->buildBreadcrumbs( $title );
$this->htmlBreadcrumbLinksBuilder->isRTL(
$title->getPageLanguage()->isRTL()
);
if ( !isset( $template->data['subtitle'] ) ) {
$template->data['subtitle'] = '';
}
// We always assume `subtitle` is available!
// https://github.com/wikimedia/mediawiki/blob/23ea2e4c2966f381eb7fd69b66a8d738bb24cc60/includes/skins/SkinTemplate.php#L292-L296
$template->data['subtitle'] .= $this->htmlBreadcrumbLinksBuilder->getHtml();
}
private function canModifyOutput( OutputPage $output ) {
if ( !$this->isEnabled( $output->getTitle() ) ) {
return false;
}
if ( isset( $output->smwmagicwords ) && in_array( 'SBL_NOBREADCRUMBLINKS', $output->smwmagicwords ) ) {
return false;
}
return true;
}
private function isEnabled( Title $title ) {
return $title->isKnown() && !$title->isSpecialPage() && $this->namespaceExaminer->isSemanticEnabled( $title->getNamespace() );
}
}