Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ServicesHooks | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
onMediaWikiServices | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
wrapCommentParserFactory | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Hashtags; |
4 | |
5 | use MediaWiki\CommentFormatter\CommentParserFactory; |
6 | use MediaWiki\Config\ServiceOptions; |
7 | use MediaWiki\Hook\MediaWikiServicesHook; |
8 | use MediaWiki\MediaWikiServices; |
9 | |
10 | class ServicesHooks implements MediaWikiServicesHook { |
11 | |
12 | /** |
13 | * @inheritDoc |
14 | */ |
15 | public function onMediaWikiServices( $services ) { |
16 | // We don't use redefineService, because we want this to |
17 | // be reasonably stable. Constructors tend to be very unstable |
18 | // between MediaWiki versions. If we simply extended CommentParserFactory |
19 | // we need to pass all the right arguments to the parent constructor |
20 | // which may change. Instead we just add a wrapper object over an |
21 | // already constructed factory |
22 | $services->addServiceManipulator( |
23 | 'CommentParserFactory', |
24 | __CLASS__ . '::wrapCommentParserFactory' |
25 | ); |
26 | } |
27 | |
28 | /** |
29 | * Convert an existing CommentParserFactory to one that returns our version of CommentParser |
30 | * |
31 | * @param CommentParserFactory $factory |
32 | * @param MediaWikiServices $services |
33 | * @return HashtagCommentParserFactory |
34 | */ |
35 | public static function wrapCommentParserFactory( CommentParserFactory $factory, MediaWikiServices $services ) { |
36 | // Not sure if renderForComment should be on. Its some weird |
37 | // hack for wikibase. |
38 | $linkRenderer = $services->getLinkRendererFactory()->create( [ 'renderForComment' => true ] ); |
39 | $changeTagsStore = $services->getChangeTagsStore(); |
40 | $options = new ServiceOptions( |
41 | HashtagCommentParserFactory::CONSTRUCTOR_OPTIONS, |
42 | $services->getMainConfig() |
43 | ); |
44 | return new HashtagCommentParserFactory( |
45 | $factory, |
46 | $linkRenderer, |
47 | $changeTagsStore, |
48 | $services->getSpecialPageFactory(), |
49 | $options, |
50 | $services->getService( 'Hashtags:TagCollector' ) |
51 | ); |
52 | } |
53 | } |