Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
15 / 15
CRAP
100.00% covered (success)
100.00%
1 / 1
HookRunner
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
15 / 15
15
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslate_TranslatorSandbox_UserPromoted
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslatePrefillTranslation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateBeforeAddModules
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateEventTranslationReview
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateGetSpecialTranslateOptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslate_newTranslation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslate_modifyMessageGroupStates
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateEventMessageGroupStateChange
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateInitGroupLoaders
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslatePostInitGroups
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateProcessAPIMessageGroupsProperties
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateSupportedLanguages
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslateEventMessageMembershipChange
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onTranslate_GettextFormat_headerFields
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare( strict_types = 1 );
3
4// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
5
6namespace MediaWiki\Extension\Translate;
7
8use MediaWiki\Extension\Translate\FileFormatSupport\GettextFormatHeaderFieldsHook;
9use MediaWiki\Extension\Translate\MessageGroupProcessing\EventMessageGroupStateChangeHook;
10use MediaWiki\Extension\Translate\MessageGroupProcessing\EventMessageMembershipChangeHook;
11use MediaWiki\Extension\Translate\MessageGroupProcessing\InitGroupLoadersHook;
12use MediaWiki\Extension\Translate\MessageGroupProcessing\ModifyMessageGroupStatesHook;
13use MediaWiki\Extension\Translate\MessageGroupProcessing\PostInitGroupsHook;
14use MediaWiki\Extension\Translate\MessageGroupProcessing\ProcessAPIMessageGroupsPropertiesHook;
15use MediaWiki\Extension\Translate\MessageLoading\MessageHandle;
16use MediaWiki\Extension\Translate\TranslatorInterface\Aid\PrefillTranslationHook;
17use MediaWiki\Extension\Translate\TranslatorInterface\BeforeAddModulesHook;
18use MediaWiki\Extension\Translate\TranslatorInterface\EventTranslationReviewHook;
19use MediaWiki\Extension\Translate\TranslatorInterface\GetSpecialTranslateOptionsHook;
20use MediaWiki\Extension\Translate\TranslatorInterface\NewTranslationHook;
21use MediaWiki\Extension\Translate\TranslatorSandbox\UserPromotedHook;
22use MediaWiki\Extension\Translate\Utilities\SupportedLanguagesHook;
23use MediaWiki\HookContainer\HookContainer;
24use MediaWiki\User\User;
25use MediaWiki\User\UserIdentity;
26use MessageGroup;
27
28/**
29 * Hook runner for the Translate extension.
30 *
31 * This is a hook runner class, see docs/Hooks.md in core.
32 * @internal
33 * @author Niklas Laxström
34 * @license GPL-2.0-or-later
35 * @since 2023.03
36 */
37class HookRunner implements
38    UserPromotedHook,
39    PrefillTranslationHook,
40    BeforeAddModulesHook,
41    EventTranslationReviewHook,
42    GetSpecialTranslateOptionsHook,
43    NewTranslationHook,
44    ModifyMessageGroupStatesHook,
45    EventMessageGroupStateChangeHook,
46    InitGroupLoadersHook,
47    PostInitGroupsHook,
48    ProcessAPIMessageGroupsPropertiesHook,
49    SupportedLanguagesHook,
50    EventMessageMembershipChangeHook,
51    GettextFormatHeaderFieldsHook
52{
53    private HookContainer $hookContainer;
54
55    public function __construct( HookContainer $hookContainer ) {
56        $this->hookContainer = $hookContainer;
57    }
58
59    public function onTranslate_TranslatorSandbox_UserPromoted( UserIdentity $user ): void {
60        $this->hookContainer->run( 'Translate:TranslatorSandbox:UserPromoted', [ $user ], [ 'abortable' => false ] );
61    }
62
63    public function onTranslatePrefillTranslation( ?string &$translation, MessageHandle $handle ) {
64        return $this->hookContainer->run( 'TranslatePrefillTranslation', [ &$translation, $handle ] );
65    }
66
67    public function onTranslateBeforeAddModules( array &$modules ) {
68        return $this->hookContainer->run( 'TranslateBeforeAddModules', [ &$modules ] );
69    }
70
71    public function onTranslateEventTranslationReview( MessageHandle $handle ) {
72        return $this->hookContainer->run( 'TranslateEventTranslationReview', [ $handle ] );
73    }
74
75    public function onTranslateGetSpecialTranslateOptions( array &$defaults, array &$nonDefaults ) {
76        return $this->hookContainer->run( 'TranslateGetSpecialTranslateOptions', [ &$defaults, &$nonDefaults ] );
77    }
78
79    public function onTranslate_newTranslation( MessageHandle $handle, int $revisionId, string $text, User $user ) {
80        return $this->hookContainer->run( 'Translate:newTranslation', [ $handle, $revisionId, $text, $user ] );
81    }
82
83    public function onTranslate_modifyMessageGroupStates( string $groupId, array &$conf ) {
84        return $this->hookContainer->run( 'Translate:modifyMessageGroupStates', [ $groupId, &$conf ] );
85    }
86
87    public function onTranslateEventMessageGroupStateChange(
88        MessageGroup $group,
89        string $code,
90        $oldState,
91        string $newState
92    ) {
93        return $this->hookContainer->run( 'TranslateEventMessageGroupStateChange',
94            [ $group, $code, $oldState, $newState ] );
95    }
96
97    public function onTranslateInitGroupLoaders( array &$groupLoader, array $deps ) {
98        return $this->hookContainer->run( 'TranslateInitGroupLoaders', [ &$groupLoader, $deps ] );
99    }
100
101    public function onTranslatePostInitGroups( array &$groups, array &$deps, array &$autoload ) {
102        return $this->hookContainer->run( 'TranslatePostInitGroups', [ &$groups, &$deps, &$autoload ] );
103    }
104
105    public function onTranslateProcessAPIMessageGroupsProperties(
106        array &$a,
107        array $props,
108        array $params,
109        MessageGroup $g
110    ) {
111        return $this->hookContainer->run( 'TranslateProcessAPIMessageGroupsProperties', [ &$a, $props, $params, $g ] );
112    }
113
114    public function onTranslateSupportedLanguages( array &$list, ?string $language ) {
115        return $this->hookContainer->run( 'TranslateSupportedLanguages', [ &$list, $language ] );
116    }
117
118    public function onTranslateEventMessageMembershipChange( MessageHandle $handle, array $old, array $new ) {
119        return $this->hookContainer->run( 'TranslateEventMessageMembershipChange', [ $handle, $old, $new ] );
120    }
121
122    public function onTranslate_GettextFormat_headerFields(
123        array &$headers,
124        MessageGroup $group,
125        string $languageCode
126    ) {
127        return $this->hookContainer->run(
128            'Translate:GettextFormat:headerFields',
129            [ &$headers, $group, $languageCode ]
130        );
131    }
132}