| 1 |
<?php |
| 2 |
|
| 3 |
namespace Cite\ResourceLoader; |
| 4 |
|
| 5 |
use MediaWiki\ResourceLoader as RL; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class CitationToolDefinition { |
| 16 |
|
| 17 |
public static function makeScript( RL\Context $context ): string { |
| 18 |
$citationDefinition = json_decode( |
| 19 |
$context->msg( 'cite-tool-definition.json' ) |
| 20 |
->inContentLanguage() |
| 21 |
->plain() |
| 22 |
); |
| 23 |
|
| 24 |
$citationDefinition ??= json_decode( |
| 25 |
$context->msg( 'visualeditor-cite-tool-definition.json' ) |
| 26 |
->inContentLanguage() |
| 27 |
->plain() |
| 28 |
); |
| 29 |
|
| 30 |
$citationTools = []; |
| 31 |
if ( is_array( $citationDefinition ) ) { |
| 32 |
foreach ( $citationDefinition as $tool ) { |
| 33 |
|
| 34 |
if ( empty( $tool->name ) || !is_string( $tool->name ) ) { |
| 35 |
continue; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
if ( empty( $tool->title ) || !is_string( $tool->title ) ) { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
$msg = $context->msg( 'visualeditor-cite-tool-name-' . $tool->name ); |
| 46 |
|
| 47 |
$tool->title = $msg->isDisabled() ? $tool->name : $msg->text(); |
| 48 |
} |
| 49 |
|
| 50 |
$citationTools[] = $tool; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
$limit = 5; |
| 60 |
$citationTools = array_slice( $citationTools, 0, $limit ); |
| 61 |
return 've.ui.mwCitationTools = ' . $context->encodeJson( $citationTools ) . ';'; |
| 62 |
} |
| 63 |
} |