-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAcrolinx.hooks.php
112 lines (98 loc) · 2.6 KB
/
Acrolinx.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Static functions called by various outside hooks, as well as by
* extension.json.
*
* @author Yaron Koren
* @file
* @ingroup Acrolinx
*/
class AcrolinxHooks {
/**
* @param Title $title
*
* @return bool
*/
public static function enableAcrolinxForPage( $title ) {
global $wgAcrolinxNamespaces;
return in_array( $title->getNamespace(), $wgAcrolinxNamespaces );
}
/**
* @param string[] &$vars
* @param OutputPage $out
*
* @return bool
*/
public static function setGlobalJSVariables( &$vars, $out ) {
global $wgAcrolinxServerAddress, $wgAcrolinxClientSignature;
global $wgAcrolinxPageLocationID;
global $wgLanguageCode;
$vars['wgAcrolinxServerAddress'] = $wgAcrolinxServerAddress;
$vars['wgAcrolinxClientSignature'] = $wgAcrolinxClientSignature;
$vars['wgAcrolinxPageLocationID'] = $wgAcrolinxPageLocationID;
$context = $out->getContext();
$mwUserLanguage = $context->getLanguage()->getCode();
// More processing may be needed here, to convert from
// MediaWiki language codes to Acrolinx ones...
$vars['wgAcrolinxPageLanguage'] = $wgLanguageCode;
$vars['wgAcrolinxUserLanguage'] = $mwUserLanguage;
return true;
}
/**
* @param EditPage &$editPage
* @param OutputPage &$output
*
* @return bool
*/
public static function addToEditPage( EditPage &$editPage, OutputPage &$output ) {
$title = $editPage->getTitle();
if ( self::enableAcrolinxForPage( $title ) ) {
$output->addModules( 'ext.acrolinx' );
}
return true;
}
/**
* @param string[] &$otherModules
*
* @return bool
*/
public static function addToFormEditPage( &$otherModules ) {
// We'll just enable Acrolinx for all forms, for now.
$otherModules[] = 'ext.acrolinx';
return true;
}
/**
* Adds extension modules for Visual Editor mode
*
* @param OutputPage $out
* @param Skin $skin
*
* @return bool|void
*/
public static function BeforePageDisplay( OutputPage $out, Skin $skin ) {
// TODO: perhaps find a way to detect VE/Forms more precisely to
// avoid loading the library code on regular pages
/*$isEditOrForm = in_array(
$out->getRequest()->getVal('action'),
[ 'edit', 'formedit' ]
);
$isVe = $out->getRequest()->getVal('veaction') === 'edit';*/
$isEnabled = self::enableAcrolinxForPage( $out->getTitle() );
if ( !$isEnabled /*|| !( $isEditOrForm || $isVe )*/ ) {
return;
}
$out->addModules( 'ext.acrolinx' );
return true;
}
/**
* @param array $paths
*
* @return bool
*
* @deprecated since 1.28, kept for b/c
*/
public static function onUnitTestsList( &$paths ) {
$paths[] = __DIR__ . '/tests/phpunit/';
return true;
}
}