Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
VisualEditorDataModule | |
0.00% |
0 / 57 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
getScript | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
getDefinitionSummary | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getMessageInfo | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
6 | |||
enableModuleContentVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDependencies | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Resource loader module providing extra data from the server to VisualEditor. |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt |
8 | * @license MIT |
9 | */ |
10 | |
11 | namespace MediaWiki\Extension\VisualEditor; |
12 | |
13 | use MediaWiki\ResourceLoader\Context as ResourceLoaderContext; |
14 | use MediaWiki\ResourceLoader\Module as ResourceLoaderModule; |
15 | use MediaWiki\Title\Title; |
16 | |
17 | class VisualEditorDataModule extends ResourceLoaderModule { |
18 | |
19 | /** |
20 | * @param ResourceLoaderContext $context Object containing information about the state of this |
21 | * specific loader request. |
22 | * @return string JavaScript code |
23 | */ |
24 | public function getScript( ResourceLoaderContext $context ) { |
25 | $msgInfo = $this->getMessageInfo( $context ); |
26 | $parsedMessages = []; |
27 | $plainMessages = []; |
28 | foreach ( $msgInfo['parse'] as $msgKey => $msgObj ) { |
29 | $parsedMessages[ $msgKey ] = $msgObj->parse(); |
30 | } |
31 | foreach ( $msgInfo['plain'] as $msgKey => $msgObj ) { |
32 | $plainMessages[ $msgKey ] = $msgObj->plain(); |
33 | } |
34 | |
35 | return 've.init.platform.addParsedMessages(' . $context->encodeJson( |
36 | $parsedMessages |
37 | ) . ');' . |
38 | 've.init.platform.addMessages(' . $context->encodeJson( |
39 | $plainMessages |
40 | ) . ');'; |
41 | } |
42 | |
43 | /** |
44 | * Get the definition summary for this module. |
45 | * |
46 | * @param ResourceLoaderContext $context |
47 | * @return array |
48 | */ |
49 | public function getDefinitionSummary( ResourceLoaderContext $context ) { |
50 | $summary = parent::getDefinitionSummary( $context ); |
51 | |
52 | $msgVersion = []; |
53 | $msgInfo = $this->getMessageInfo( $context ); |
54 | $msgInfo = array_merge( $msgInfo['parse'], $msgInfo['plain'] ); |
55 | foreach ( $msgInfo as $msgKey => $msgObj ) { |
56 | $msgVersion[ $msgKey ] = [ |
57 | // Include the text of the message, in case the canonical translation changes |
58 | $msgObj->plain(), |
59 | // Include the page touched time, in case the on-wiki override is invalidated |
60 | Title::makeTitle( NS_MEDIAWIKI, ucfirst( $msgObj->getKey() ) )->getTouched(), |
61 | ]; |
62 | } |
63 | $summary[] = [ 've-messages' => $msgVersion ]; |
64 | return $summary; |
65 | } |
66 | |
67 | /** |
68 | * @param ResourceLoaderContext $context Object containing information about the state of this |
69 | * specific loader request. |
70 | * @return array[] Messages in various states of parsing |
71 | */ |
72 | protected function getMessageInfo( ResourceLoaderContext $context ) { |
73 | $editSubmitButtonLabelPublish = $this->getConfig() |
74 | ->get( 'EditSubmitButtonLabelPublish' ); |
75 | $saveButtonLabelKey = $editSubmitButtonLabelPublish ? 'publishchanges' : 'savechanges'; |
76 | $saveButtonLabel = $context->msg( $saveButtonLabelKey )->text(); |
77 | |
78 | // Messages to be exported as parsed html |
79 | $parseMsgs = [ |
80 | 'missingsummary' => $context->msg( 'missingsummary', $saveButtonLabel ), |
81 | 'summary' => $context->msg( 'summary' ), |
82 | 'visualeditor-browserwarning' => $context->msg( 'visualeditor-browserwarning' ), |
83 | 'visualeditor-wikitext-warning' => $context->msg( 'visualeditor-wikitext-warning' ), |
84 | ]; |
85 | |
86 | // Messages to be exported as plain text |
87 | $plainMsgs = [ |
88 | 'visualeditor-feedback-link' => |
89 | $context->msg( 'visualeditor-feedback-link' ) |
90 | ->inContentLanguage(), |
91 | 'visualeditor-feedback-source-link' => |
92 | $context->msg( 'visualeditor-feedback-source-link' ) |
93 | ->inContentLanguage(), |
94 | 'visualeditor-quick-access-characters.json' => |
95 | $context->msg( 'visualeditor-quick-access-characters.json' ) |
96 | ->inContentLanguage(), |
97 | 'visualeditor-template-tools-definition.json' => |
98 | $context->msg( 'visualeditor-template-tools-definition.json' ) |
99 | ->inContentLanguage(), |
100 | ]; |
101 | |
102 | return [ |
103 | 'parse' => $parseMsgs, |
104 | 'plain' => $plainMsgs, |
105 | ]; |
106 | } |
107 | |
108 | /** |
109 | * @inheritDoc |
110 | * |
111 | * Always true. |
112 | */ |
113 | public function enableModuleContentVersion() { |
114 | return true; |
115 | } |
116 | |
117 | /** |
118 | * @inheritDoc |
119 | */ |
120 | public function getDependencies( ?ResourceLoaderContext $context = null ) { |
121 | return [ |
122 | 'ext.visualEditor.base', |
123 | 'ext.visualEditor.mediawiki', |
124 | ]; |
125 | } |
126 | } |