Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
onResourceLoaderGetConfigVars | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getWikibaseInitData | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
onBeforePageDisplay | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
onGetPreferences | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Hooks for Citoid extension |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | */ |
8 | |
9 | namespace MediaWiki\Extension\Citoid; |
10 | |
11 | use ExtensionRegistry; |
12 | use MediaWiki\Config\Config; |
13 | use MediaWiki\Hook\BeforePageDisplayHook; |
14 | use MediaWiki\MediaWikiServices; |
15 | use MediaWiki\Output\OutputPage; |
16 | use MediaWiki\Preferences\Hook\GetPreferencesHook; |
17 | use MediaWiki\ResourceLoader as RL; |
18 | use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook; |
19 | use MediaWiki\User\User; |
20 | use Skin; |
21 | use Wikibase\Repo\WikibaseRepo; |
22 | |
23 | class Hooks implements |
24 | ResourceLoaderGetConfigVarsHook, |
25 | BeforePageDisplayHook, |
26 | GetPreferencesHook |
27 | { |
28 | |
29 | /** |
30 | * Adds extra variables to the global config |
31 | * @param array &$vars |
32 | * @param string $skin |
33 | * @param Config $config |
34 | */ |
35 | public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void { |
36 | $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'citoid' ); |
37 | |
38 | $vars['wgCitoidConfig'] = [ |
39 | 'citoidServiceUrl' => $config->get( 'CitoidServiceUrl' ), |
40 | 'fullRestbaseUrl' => $config->get( 'CitoidFullRestbaseURL' ), |
41 | 'isbnScannerEnabled' => $config->get( 'CitoidIsbnScannerEnabled' ), |
42 | 'wbFullRestbaseUrl' => $config->get( 'WBCitoidFullRestbaseURL' ), |
43 | ]; |
44 | } |
45 | |
46 | /** |
47 | * Virtual data file of 'ext.citoid.wikibase.init' module. |
48 | * |
49 | * @param RL\Context $context |
50 | * @return string[] |
51 | */ |
52 | public static function getWikibaseInitData( RL\Context $context ) { |
53 | return [ |
54 | 'toolConfig' => $context->msg( 'citoid-wikibase-config.json' ) |
55 | ->inContentLanguage() |
56 | ->plain(), |
57 | ]; |
58 | } |
59 | |
60 | /** |
61 | * Loads front-end wikibase citoid module |
62 | * @param OutputPage $out |
63 | * @param Skin $skin |
64 | */ |
65 | public function onBeforePageDisplay( $out, $skin ): void { |
66 | if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseRepository' ) ) { |
67 | return; |
68 | } |
69 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
70 | if ( $lookup->isEntityNamespace( $out->getTitle()->getNamespace() ) ) { |
71 | $services = MediaWikiServices::getInstance(); |
72 | $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
73 | $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
74 | if ( !$isMobileView ) { |
75 | $out->addModules( 'ext.citoid.wikibase.init' ); |
76 | } |
77 | } |
78 | } |
79 | |
80 | /** |
81 | * @param User $user |
82 | * @param array &$preferences |
83 | */ |
84 | public function onGetPreferences( $user, &$preferences ) { |
85 | $preferences['citoid-mode'] = [ |
86 | 'type' => 'api' |
87 | ]; |
88 | } |
89 | } |