1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SBL; |
4
|
|
|
|
5
|
|
|
use SMW\Store; |
6
|
|
|
use SMW\ApplicationFactory; |
7
|
|
|
use DummyLinker; |
8
|
|
|
use Hooks; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class HookRegistry { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private $handlers = array(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @since 1.0 |
25
|
|
|
* |
26
|
|
|
* @param Store $store |
27
|
|
|
* @param Options $options |
28
|
2 |
|
*/ |
29
|
2 |
|
public function __construct( Store $store, Options $options ) { |
30
|
2 |
|
$this->addCallbackHandlers( $store, $options ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @since 1.1 |
35
|
|
|
* |
36
|
|
|
* @param string $name |
37
|
|
|
* |
38
|
|
|
* @return boolean |
39
|
1 |
|
*/ |
40
|
1 |
|
public function isRegistered( $name ) { |
41
|
|
|
return Hooks::isRegistered( $name ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @since 1.1 |
46
|
|
|
* |
47
|
|
|
* @param string $name |
48
|
|
|
* |
49
|
|
|
* @return Callable|false |
50
|
1 |
|
*/ |
51
|
1 |
|
public function getHandlerFor( $name ) { |
52
|
|
|
return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @since 1.0 |
57
|
1 |
|
*/ |
58
|
1 |
|
public function register() { |
59
|
1 |
|
foreach ( $this->handlers as $name => $callback ) { |
60
|
1 |
|
Hooks::register( $name, $callback ); |
61
|
1 |
|
} |
62
|
|
|
} |
63
|
2 |
|
|
64
|
|
|
private function addCallbackHandlers( $store, $options ) { |
65
|
2 |
|
|
66
|
|
|
$propertyRegistry = new PropertyRegistry(); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks.md |
70
|
|
|
*/ |
71
|
1 |
|
$this->handlers['SMW::Property::initProperties'] = function () use ( $propertyRegistry ) { |
72
|
|
|
return $propertyRegistry->register(); |
73
|
|
|
}; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateOutputPageBeforeExec |
77
|
|
|
*/ |
78
|
|
|
$this->handlers['SkinTemplateOutputPageBeforeExec'] = function ( &$skin, &$template ) use( $store, $options ) { |
79
|
1 |
|
|
80
|
1 |
|
$bySubpageLinksFinder = new BySubpageLinksFinder(); |
81
|
1 |
|
$bySubpageLinksFinder->setSubpageDiscoverySupportState( |
82
|
1 |
|
$options->get( 'useSubpageFinderFallback' ) |
83
|
|
|
); |
84
|
1 |
|
|
85
|
1 |
|
$byPropertyHierarchicalLinksFinder = new ByPropertyHierarchicalLinksFinder( $store ); |
86
|
1 |
|
$byPropertyHierarchicalLinksFinder->setFindClosestDescendantState( |
87
|
1 |
|
$options->get( 'tryToFindClosestDescendant' ) |
88
|
|
|
); |
89
|
1 |
|
|
90
|
1 |
|
$byPropertyHierarchicalLinksFinder->setPropertySearchPatternByNamespace( |
91
|
1 |
|
$options->get( 'propertySearchPatternByNamespace' ) |
92
|
|
|
); |
93
|
1 |
|
|
94
|
1 |
|
$htmlBreadcrumbLinksBuilder = new HtmlBreadcrumbLinksBuilder( |
95
|
|
|
$byPropertyHierarchicalLinksFinder, |
96
|
1 |
|
$bySubpageLinksFinder |
97
|
|
|
); |
98
|
1 |
|
|
99
|
1 |
|
$htmlBreadcrumbLinksBuilder->setLinker( new DummyLinker() ); |
100
|
1 |
|
$htmlBreadcrumbLinksBuilder->setBreadcrumbTrailStyleClass( |
101
|
1 |
|
$options->get( 'breadcrumbTrailStyleClass' ) |
102
|
|
|
); |
103
|
1 |
|
|
104
|
1 |
|
$htmlBreadcrumbLinksBuilder->setBreadcrumbDividerStyleClass( |
105
|
1 |
|
$options->get( 'breadcrumbDividerStyleClass' ) |
106
|
|
|
); |
107
|
1 |
|
|
108
|
1 |
|
$htmlBreadcrumbLinksBuilder->setHideSubpageParentState( |
109
|
1 |
|
$options->get( 'hideSubpageParent' ) |
110
|
|
|
); |
111
|
1 |
|
|
112
|
|
|
$skinTemplateOutputModifier = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder ); |
113
|
|
|
$skinTemplateOutputModifier->modifyTemplate( $template ); |
114
|
|
|
$skinTemplateOutputModifier->modifyOutput( $skin->getOutput() ); |
115
|
|
|
|
116
|
|
|
return true; |
117
|
|
|
}; |
118
|
|
|
|
119
|
1 |
|
/** |
120
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay |
121
|
1 |
|
*/ |
122
|
1 |
|
$this->handlers['BeforePageDisplay'] = function ( &$output, &$skin ) use ( $options ) { |
|
|
|
|
123
|
1 |
|
|
124
|
|
|
$pageDisplayOutputModifier = new PageDisplayOutputModifier(); |
125
|
1 |
|
|
126
|
1 |
|
$pageDisplayOutputModifier->setHideSubpageParentState( |
127
|
1 |
|
$options->get( 'hideSubpageParent' ) |
128
|
|
|
); |
129
|
1 |
|
|
130
|
|
|
$pageDisplayOutputModifier->setSubpageByNamespace( |
131
|
1 |
|
$options->get( 'wgNamespacesWithSubpages' ) |
132
|
|
|
); |
133
|
2 |
|
|
134
|
|
|
$pageDisplayOutputModifier->modifyOutput( $output ); |
135
|
|
|
|
136
|
|
|
return true; |
137
|
|
|
}; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy |
141
|
|
|
*/ |
142
|
|
|
$this->handlers['ParserAfterTidy'] = function ( &$parser, &$text ) use ( $options ) { |
|
|
|
|
143
|
|
|
|
144
|
|
|
// ParserOptions::getInterfaceMessage is being used to identify whether a |
145
|
|
|
// parse was initiated by `Message::parse` |
146
|
|
|
if ( $parser->getTitle()->isSpecialPage() || $parser->getOptions()->getInterfaceMessage() ) { |
147
|
|
|
return true; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$parserData = ApplicationFactory::getInstance()->newParserData( |
151
|
|
|
$parser->getTitle(), |
152
|
|
|
$parser->getOutput() |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$subpageParentAnnotator = new SubpageParentAnnotator( |
156
|
|
|
$parserData |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$subpageParentAnnotator->setSubpageParentAnnotationState( |
160
|
|
|
$options->get( 'enabledSubpageParentAnnotation' ) |
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
$subpageParentAnnotator->addAnnotation(); |
164
|
|
|
|
165
|
|
|
return true; |
166
|
|
|
}; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.