Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| JsonSchemaCodeEditorHooks | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onCodeEditorGetPageLanguage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\EventLogging; |
| 4 | |
| 5 | use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook; |
| 6 | use MediaWiki\Title\Title; |
| 7 | |
| 8 | /** |
| 9 | * EventLogging has a soft dependency on CodeEditor. Specifically, if CodeEditor is loaded, then EventLogging sets the |
| 10 | * code language for pages in the Schema namespace to JSON by responding to the CodeEditorGetPageLanguage hook. We |
| 11 | * maintain that soft dependency on CodeEditor by isolating CodeEditor-specific hook handlers to a class that will |
| 12 | * only be autoloaded only when the hook fires. |
| 13 | */ |
| 14 | class JsonSchemaCodeEditorHooks implements CodeEditorGetPageLanguageHook { |
| 15 | private JsonSchemaHooksHelper $jsonSchemaHooksHelper; |
| 16 | |
| 17 | public function __construct( JsonSchemaHooksHelper $jsonSchemaHooksHelper ) { |
| 18 | $this->jsonSchemaHooksHelper = $jsonSchemaHooksHelper; |
| 19 | } |
| 20 | |
| 21 | public function onCodeEditorGetPageLanguage( Title $title, ?string &$lang, string $model, string $format ): void { |
| 22 | if ( |
| 23 | $this->jsonSchemaHooksHelper->isSchemaNamespaceEnabled() && |
| 24 | $title->inNamespace( NS_SCHEMA ) |
| 25 | ) { |
| 26 | $lang = 'json'; |
| 27 | } |
| 28 | } |
| 29 | } |