Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikibaseMediaInfoServicesHooks
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 onMediaWikiServices
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Wikibase\MediaInfo;
4
5use MediaWiki\Hook\MediaWikiServicesHook;
6use MediaWiki\MediaWikiServices;
7use MediaWiki\Revision\SlotRoleRegistry;
8use Wikibase\MediaInfo\Content\MediaInfoContent;
9
10/**
11 * MediaWiki hook handlers for the Wikibase MediaInfo extension.
12 *
13 * @license GPL-2.0-or-later
14 */
15class WikibaseMediaInfoServicesHooks implements MediaWikiServicesHook {
16
17    /**
18     * Hook to register the MediaInfo slot role.
19     *
20     * @param MediaWikiServices $services
21     */
22    public function onMediaWikiServices( $services ) {
23        $services->addServiceManipulator( 'SlotRoleRegistry', static function ( SlotRoleRegistry $registry ) {
24            if ( !$registry->isDefinedRole( 'mediainfo' ) ) {
25                // Sense check
26                $registry->defineRoleWithModel(
27                    /* role */ 'mediainfo',
28                    /* content handler */ MediaInfoContent::CONTENT_MODEL_ID
29                    /*, layout – we want to set "prepend" in future, once MediaWiki supports that */
30                );
31            }
32        } );
33    }
34}