summaryrefslogtreecommitdiff
blob: 4f287c443e041748746d8ad530cfe7dcf9b36bc0 (plain)
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
This document describes how event hooks work in the Translate extension;
how to add hooks for an event; and how to run hooks for an event.

For a more comprehensive guide to hooks, navigate to your root MediaWiki
directory, and then find /docs/hooks.txt.

== Rationale ==

Hooks allow us to decouple optionally-run code from code that is run for
everyone. It allows MediaWiki hackers, third-party developers and local
administrators to define code that will be run at certain points in the mainline
code, and to modify the data run by that mainline code. Hooks can keep mainline
code simple, and make it easier to write extensions. Hooks are a principled
alternative to local patches.

== Writing hooks ==

=== PHP hooks ===
For a guide to PHP hooks, navigate to your root MediaWiki
directory, and then find docs/hooks.txt.

=== JavaScript hooks ===
JavaScript hooks for the Translate extension use the standard mw.hook API provided
by MediaWiki.

Hooks are prefixed with mw.translate as a convention.

== Events and parameters ==

This is a list of known events and parameters; please add to it if you're going
to add events to the Translate extension.

<!--
Post processing step to format in wiki
^;([^ ]+): >>> ;<nowiki>\1</nowiki>:
-->

=== PHP events ===

;TranslateBeforeAddModules: Provides an opportunity to load extra modules
 array          &$modules: List of resource loader module names

;TranslateEventMessageMembershipChange: When group gets new messages or loses messages
 MessageHandle   $handle
 array           $old Previous groups
 array           $new Current groups

;TranslateEventMessageGroupStateChange: Event triggered when a message group workflow state is changed in a language
 MessageGroup    $group: Message group instance
 string          $code: Language code
 string          $oldState
 string          $newState

;TranslateEventTranslationReview: Event triggered when a translation is proofread
 MessageHandle   $handle

;TranslateGetAPIMessageGroupsParameterList: Allows extra parameters to be added to the action=query&meta=messagegroups module
 array          &$params: An associative array of possible parameters (name => details; see ApiQueryMessageGroups.php for correct spacing)

;TranslateGetAPIMessageGroupsPropertyDescs: Allows extra properties to be added to captured by action=query&meta=messagegroups&mgprop=foo|bar|bat module
 array          &$properties: An associative array of properties, name => description (which is ignored).

;TranslateGetSpecialTranslateOptions: Provides an opportunity for overriding task values
 array          &$defaults: Associative array of default values
 array          &$nondefaults: Associative array of nondefault (override) values

;Translate:GettextFFS:headerFields: Allows customizing headers of exported Gettext files per group. Certain X-headers nor Plural-Forms cannot be customized.
 array          &$headers: List of prefilled headers. You can remove, change or add new headers.
 MessageGroup    $group: Message group instance
 string          $code: Language code

;Translate:newTranslation: Event triggered when non-fuzzy translation has been made
 MessageHandle   $handle
 int             $revisionId
 string          $text: Content of the new translation
 User            $user: User who created or changed the translation

;TranslatePostInitGroups: Hook to register new message groups to Translate. Manual cache clear may be needed to have this hook executed.
 array          &$groups: Map of message group id to message group instance
 array          &$deps: List of dependencies as supported by DependencyWrapper class from MediaWiki
 array          &$autoload: List of autoloaded classes. Key is the name of the class and value is filename.

;TranslateInitGroupLoaders: Hook to register new message group loaders that can then load MessageGroups for translation purpose.
 array          &$groupLoader: List of message group loader class names that implement the MessageGroupLoader

;TranslatePrefillTranslation: Provides an opportunity for a new translation to start not from as a carte blanche (the default) but from some prefilled string
 string         &$translation: The translation string as it stands
 MessageHandle   $handle: The current MessageHandle object

;TranslateProcessAPIMessageGroupsProperties: Allows extra property requests to be acted upon, and the new properties returned
 array          &$a: Associative array of the properties of $group that will be returned
 array           $props: Associative array ($name => true) of properties the user has specifically requested
 array           $params: Parameter input by the user (unprefixed name => value)
 MessageGroup    $g: The group in question

;TranslateSupportedLanguages: Allows removing languages from language selectors. For adding $wgExtraLanguage names is recommended.
 array          &$list: List of languages indexed by language code
 string          $language: Language code of the language of which language names are in

;Translate:modifyMessageGroupStates: Allow hooks to change workflow states depending on the group's ID.
 string         $groupId: ID of the current message group.
 array          &$conf: Workflow states, can be modified.

=== JavaScript events ===

;mw.translate.editor.afterSubmit: Provides an opportunity to modify a Translate translation form immediately after it is submitted
 jQuery          form: The form that has just been submitted

;mw.translate.editor.afterEditorShown: Provides an opportunity to manipulate the editing interface once it's shown
 jQuery          translateEditor.$editor: The current translation-editing form

;mw.translate.editor.beforeSubmit: Provides an opportunity to modify a Translate translation form immediately before it is submitted
 jQuery          form: The form being submitted

;mw.translate.messagetable.formatMessageBeforeTable: Provides an opportunity to manipulate the display of translation strings (messages) in the main table
 object          message: The message object, with a range of useful (and manipulable) properties

;mw.translate.editor.showTranslationHelpers: Provides an opportunity to handle custom translation helpers
 object          result.helpers: JSON subset focusing on the helpers returned e.g. result.helpers.definition
 jQuery          translateEditor.$editor: The current translation-editing form

;wikipage.content: See this hook in MediaWiki core. Fired for message documentation in the translation editor.
 jQuery          $content