-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHookRegistry.php
200 lines (159 loc) · 4.91 KB
/
HookRegistry.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
namespace SBL;
use SMW\Store;
use SMW\ApplicationFactory;
use DummyLinker;
use Hooks;
/**
* @license GNU GPL v2+
* @since 1.0
*
* @author mwjames
*/
class HookRegistry {
/**
* @var array
*/
private $handlers = [];
/**
* @since 1.0
*
* @param Store $store
* @param Options $options
*/
public function __construct( Store $store, Options $options ) {
$this->addCallbackHandlers( $store, $options );
}
/**
* @since 1.1
*
* @param string $name
*
* @return boolean
*/
public function isRegistered( $name ) {
return Hooks::isRegistered( $name );
}
/**
* @since 1.1
*
* @param string $name
*
* @return Callable|false
*/
public function getHandlerFor( $name ) {
return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
}
/**
* @since 1.0
*/
public function register() {
foreach ( $this->handlers as $name => $callback ) {
Hooks::register( $name, $callback );
}
}
private function addCallbackHandlers( $store, $options ) {
/**
* @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks.md
*/
$this->handlers['SMW::Property::initProperties'] = function( $baseRegistry ) {
$propertyRegistry = new PropertyRegistry();
$propertyRegistry->register(
$baseRegistry
);
return true;
};
/**
* @see https://www.semantic-mediawiki.org/wiki/Hooks/SMW::Parser::BeforeMagicWordsFinder
*/
$this->handlers['SMW::Parser::BeforeMagicWordsFinder'] = function( array &$magicWords ) {
$magicWords = array_merge( $magicWords, [ 'SBL_NOBREADCRUMBLINKS' ] );
return true;
};
/**
* @note This is bit of a hack but there is no other way to get access to
* the ParserOutput
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput
*/
$this->handlers['OutputPageParserOutput'] = function( &$outputPage, $parserOutput ) {
$outputPage->smwmagicwords = $parserOutput->getExtensionData( 'smwmagicwords' );
return true;
};
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateOutputPageBeforeExec
*/
$this->handlers['SkinTemplateOutputPageBeforeExec'] = function ( &$skin, &$template ) use( $store, $options ) {
$bySubpageLinksFinder = new BySubpageLinksFinder();
$bySubpageLinksFinder->setSubpageDiscoveryFallback(
$options->get( 'useSubpageFinderFallback' )
);
$byPropertyHierarchicalLinksFinder = new ByPropertyHierarchicalLinksFinder( $store );
$byPropertyHierarchicalLinksFinder->setFindClosestDescendantState(
$options->get( 'tryToFindClosestDescendant' )
);
$byPropertyHierarchicalLinksFinder->setPropertySearchPatternByNamespace(
$options->get( 'propertySearchPatternByNamespace' )
);
$htmlBreadcrumbLinksBuilder = new HtmlBreadcrumbLinksBuilder(
$byPropertyHierarchicalLinksFinder,
$bySubpageLinksFinder
);
$htmlBreadcrumbLinksBuilder->setLinker( new DummyLinker() );
$htmlBreadcrumbLinksBuilder->setBreadcrumbTrailStyleClass(
$options->get( 'breadcrumbTrailStyleClass' )
);
$htmlBreadcrumbLinksBuilder->setBreadcrumbDividerStyleClass(
$options->get( 'breadcrumbDividerStyleClass' )
);
$htmlBreadcrumbLinksBuilder->hideSubpageParent(
$options->get( 'hideSubpageParent' )
);
$skinTemplateOutputModifier = new SkinTemplateOutputModifier(
$htmlBreadcrumbLinksBuilder,
ApplicationFactory::getInstance()->getNamespaceExaminer()
);
$skinTemplateOutputModifier->modify( $skin->getOutput(), $template );
return true;
};
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
*/
$this->handlers['BeforePageDisplay'] = function ( &$output, &$skin ) use ( $options ) {
$pageDisplayOutputModifier = new PageDisplayOutputModifier();
$pageDisplayOutputModifier->hideSubpageParent(
$options->get( 'hideSubpageParent' )
);
$pageDisplayOutputModifier->setSubpageByNamespace(
$options->get( 'wgNamespacesWithSubpages' )
);
$pageDisplayOutputModifier->modifyOutput( $output );
return true;
};
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy
*/
$this->handlers['ParserAfterTidy'] = function ( &$parser, &$text ) use ( $options ) {
// ParserOptions::getInterfaceMessage is being used to identify whether a
// parse was initiated by `Message::parse`
if ( $parser->getTitle()->isSpecialPage() || $parser->getOptions()->getInterfaceMessage() ) {
return true;
}
$parserData = ApplicationFactory::getInstance()->newParserData(
$parser->getTitle(),
$parser->getOutput()
);
$subpageParentAnnotator = new SubpageParentAnnotator(
$parserData
);
$subpageParentAnnotator->enableSubpageParentAnnotation(
$options->get( 'enabledSubpageParentAnnotation' )
);
$subpageParentAnnotator->disableTranslationSubpageAnnotation(
$options->get( 'disableTranslationSubpageAnnotation' )
);
$subpageParentAnnotator->addAnnotation();
return true;
};
}
}