]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - extensions/Cite/includes/CiteDataModule.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / extensions / Cite / includes / CiteDataModule.php
1 <?php
2 /**
3  * Resource loader module providing extra data from the server to Cite.
4  *
5  * Temporary hack for T93800
6  *
7  * @file
8  * @ingroup Extensions
9  * @copyright 2011-2017 Cite VisualEditor Team and others; see AUTHORS.txt
10  * @license The MIT License (MIT); see MIT-LICENSE.txt
11  */
12
13 class CiteDataModule extends ResourceLoaderModule {
14
15         /* Protected Members */
16
17         protected $origin = self::ORIGIN_USER_SITEWIDE;
18         protected $targets = [ 'desktop', 'mobile' ];
19
20         /* Methods */
21
22         public function getScript( ResourceLoaderContext $context ) {
23                 $citationDefinition = json_decode(
24                         $context->msg( 'cite-tool-definition.json' )
25                                 ->inContentLanguage()
26                                 ->plain()
27                 );
28
29                 if ( $citationDefinition === null ) {
30                         $citationDefinition = json_decode(
31                                 $context->msg( 'visualeditor-cite-tool-definition.json' )
32                                         ->inContentLanguage()
33                                         ->plain()
34                         );
35                 }
36
37                 $citationTools = [];
38                 if ( is_array( $citationDefinition ) ) {
39                         foreach ( $citationDefinition as $tool ) {
40                                 if ( !isset( $tool->title ) ) {
41                                         $tool->title = $context->msg( 'visualeditor-cite-tool-name-' . $tool->name )
42                                                 ->text();
43                                 }
44                                 $citationTools[] = $tool;
45                         }
46                 }
47
48                 return
49                         've.init.platform.addMessages(' . FormatJson::encode(
50                                 [
51                                         'cite-tool-definition.json' => json_encode( $citationTools )
52                                 ],
53                                 ResourceLoader::inDebugMode()
54                         ) . ');';
55         }
56
57         public function getDependencies( ResourceLoaderContext $context = null ) {
58                 return [
59                         'ext.visualEditor.base',
60                         'ext.visualEditor.mediawiki',
61                 ];
62         }
63
64         public function getDefinitionSummary( ResourceLoaderContext $context ) {
65                 $summary = parent::getDefinitionSummary( $context );
66                 $summary[] = [
67                         'script' => $this->getScript( $context ),
68                 ];
69                 return $summary;
70         }
71 }