Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ResourceLoaderData | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| makeMagicWordData | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Utilities for ResourceLoader modules used by VisualEditor. |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @license MIT |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Extension\VisualEditor; |
| 11 | |
| 12 | use MediaWiki\MediaWikiServices; |
| 13 | use MediaWiki\ResourceLoader\Context; |
| 14 | |
| 15 | class ResourceLoaderData { |
| 16 | |
| 17 | /** |
| 18 | * Generate a script populating the list of double-underscore behaviour |
| 19 | * switches (e.g. __TOC__) offered by ve.ui.MWMagicWordCompletionAction. |
| 20 | * |
| 21 | * The list is taken from the wiki's configured magic words, so it reflects |
| 22 | * the content language and any switches added by installed extensions. |
| 23 | * |
| 24 | * The returned script assigns to the action class, so it must be listed |
| 25 | * after that class's own script in the ext.visualEditor.mwwikitext module. |
| 26 | * |
| 27 | * @param Context $context |
| 28 | * @return string JavaScript |
| 29 | */ |
| 30 | public static function makeMagicWordData( Context $context ): string { |
| 31 | $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory(); |
| 32 | $words = []; |
| 33 | foreach ( $magicWordFactory->getDoubleUnderscoreArray()->getNames() as $name ) { |
| 34 | foreach ( $magicWordFactory->get( $name )->getSynonyms() as $synonym ) { |
| 35 | $words[ $synonym ] = true; |
| 36 | } |
| 37 | } |
| 38 | ksort( $words ); |
| 39 | return 've.ui.MWMagicWordCompletionAction.static.magicWords = ' |
| 40 | . $context->encodeJson( array_keys( $words ) ) . ';'; |
| 41 | } |
| 42 | } |