Index: trunk/extensions/MathStatFunctions/MathStatFunctions.i18n.magic.php |
— | — | @@ -1,34 +1,34 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) { |
5 | | - die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
| 5 | + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
6 | 6 | } |
7 | 7 | |
8 | 8 | $wgMathStatFunctionsMagic = array(); |
9 | 9 | |
10 | 10 | $wgMathStatFunctionsMagic['en'] = array( |
11 | | - 'const' => array( 0, 'const' ), |
12 | | - 'median' => array( 0, 'median' ), |
13 | | - 'mean' => array( 0, 'mean' ), |
14 | | - 'exp' => array( 0, 'exp' ), |
15 | | - 'log' => array( 0, 'log' ), |
16 | | - 'ln' => array( 0, 'ln' ), |
17 | | - 'tan' => array( 0, 'tan' ), |
18 | | - 'atan' => array( 0, 'atan', 'arctan' ), |
19 | | - 'tanh' => array( 0, 'tanh' ), |
20 | | - 'atanh' => array( 0, 'atanh', 'arctanh' ), |
21 | | - 'cot' => array( 0, 'cot' ), |
22 | | - 'acot' => array( 0, 'acot', 'arccot' ), |
23 | | - 'cos' => array( 0, 'cos', ), |
24 | | - 'acos' => array( 0, 'acos', 'arccos' ), |
25 | | - 'cosh' => array( 0, 'cosh', ), |
26 | | - 'acosh' => array( 0, 'acosh', 'arccosh' ), |
27 | | - 'sec' => array( 0, 'sec' ), |
28 | | - 'asec' => array( 0, 'asec', 'arcsec' ), |
29 | | - 'sin' => array( 0, 'sin' ), |
30 | | - 'asin' => array( 0, 'asin', 'arcsin' ), |
31 | | - 'sinh' => array( 0, 'sinh' ), |
32 | | - 'asinh' => array( 0, 'asinh', 'arcsinh' ), |
33 | | - 'csc' => array( 0, 'csc' ), |
34 | | - 'acsc' => array( 0, 'acsc', 'arccsc' ), |
| 11 | + 'const' => array( 0, 'const' ), |
| 12 | + 'median' => array( 0, 'median' ), |
| 13 | + 'mean' => array( 0, 'mean' ), |
| 14 | + 'exp' => array( 0, 'exp' ), |
| 15 | + 'log' => array( 0, 'log' ), |
| 16 | + 'ln' => array( 0, 'ln' ), |
| 17 | + 'tan' => array( 0, 'tan' ), |
| 18 | + 'atan' => array( 0, 'atan', 'arctan' ), |
| 19 | + 'tanh' => array( 0, 'tanh' ), |
| 20 | + 'atanh' => array( 0, 'atanh', 'arctanh' ), |
| 21 | + 'cot' => array( 0, 'cot' ), |
| 22 | + 'acot' => array( 0, 'acot', 'arccot' ), |
| 23 | + 'cos' => array( 0, 'cos', ), |
| 24 | + 'acos' => array( 0, 'acos', 'arccos' ), |
| 25 | + 'cosh' => array( 0, 'cosh', ), |
| 26 | + 'acosh' => array( 0, 'acosh', 'arccosh' ), |
| 27 | + 'sec' => array( 0, 'sec' ), |
| 28 | + 'asec' => array( 0, 'asec', 'arcsec' ), |
| 29 | + 'sin' => array( 0, 'sin' ), |
| 30 | + 'asin' => array( 0, 'asin', 'arcsin' ), |
| 31 | + 'sinh' => array( 0, 'sinh' ), |
| 32 | + 'asinh' => array( 0, 'asinh', 'arcsinh' ), |
| 33 | + 'csc' => array( 0, 'csc' ), |
| 34 | + 'acsc' => array( 0, 'acsc', 'arccsc' ), |
35 | 35 | ); |
Index: trunk/extensions/MathStatFunctions/MathStatFunctions.i18n.php |
— | — | @@ -8,10 +8,10 @@ |
9 | 9 | $messages = array(); |
10 | 10 | |
11 | 11 | $messages['en'] = array( |
12 | | - 'msfunc_desc' => 'A collection of mathematical and statistical functions', |
13 | | - 'msfunc_nan' => 'Resulting value is not a number', |
14 | | - 'msfunc_inf' => 'Resulting value is infinity', |
15 | | - 'msfunc_div_zero' => 'Division by zero', |
| 12 | + 'msfunc_desc' => 'A collection of mathematical and statistical functions', |
| 13 | + 'msfunc_nan' => 'Resulting value is not a number', |
| 14 | + 'msfunc_inf' => 'Resulting value is infinity', |
| 15 | + 'msfunc_div_zero' => 'Division by zero', |
16 | 16 | ); |
17 | 17 | |
18 | 18 | /** Message documentation (Message documentation) |
Index: trunk/extensions/MathStatFunctions/MathStatFunctions.php |
— | — | @@ -1,20 +1,20 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) { |
5 | | - die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
| 5 | + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
6 | 6 | } |
7 | 7 | |
8 | 8 | $wgExtensionCredits['parserhook'][] = array( |
9 | 9 | 'path' => __FILE__, |
10 | | - 'name' => 'MathStatFunctions', |
11 | | - 'version' => '1.1', |
12 | | - 'author' => 'Carl Fürstenberg (AzaToth)', |
13 | | - 'description' => 'A collection of mathematical and statistical functions', |
14 | | - 'descriptionmsg' => 'msfunc_desc', |
15 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:MathStatFunctions', |
| 10 | + 'name' => 'MathStatFunctions', |
| 11 | + 'version' => '1.1', |
| 12 | + 'author' => 'Carl Fürstenberg (AzaToth)', |
| 13 | + 'description' => 'A collection of mathematical and statistical functions', |
| 14 | + 'descriptionmsg' => 'msfunc_desc', |
| 15 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:MathStatFunctions', |
16 | 16 | ); |
17 | 17 | |
18 | | -$wgExtensionMessagesFiles['MathStatFunctions'] = dirname(__FILE__) . '/MathStatFunctions.i18n.php'; |
| 18 | +$wgExtensionMessagesFiles['MathStatFunctions'] = dirname( __FILE__ ) . '/MathStatFunctions.i18n.php'; |
19 | 19 | $wgExtensionFunctions[] = 'wfSetupMathStatFunctions'; |
20 | 20 | $wgHooks['LanguageGetMagic'][] = 'wfMathStatFunctionsLanguageGetMagic'; |
21 | 21 | |
— | — | @@ -22,416 +22,446 @@ |
23 | 23 | * \brief Exception class identifying that ParserFunctions is not available |
24 | 24 | */ |
25 | 25 | class ParserFunctionsNotFoundException extends Exception { |
26 | | - public function __construct(){ |
27 | | - $this->message = "<span style=\"color: red; font-size: large;\">ERROR: ParserFunctions was not found</span>"; |
28 | | - } |
| 26 | + public function __construct() { |
| 27 | + $this->message = "<span style=\"color: red; font-size: large;\">ERROR: ParserFunctions was not found</span>"; |
| 28 | + } |
29 | 29 | } |
30 | 30 | |
31 | 31 | class ExtMathStatFunctions { |
32 | 32 | |
33 | | - public function __construct() { |
34 | | - if(!class_exists('ExtParserFunctions')) |
35 | | - throw new ParserFunctionsNotFoundException; |
| 33 | + public function __construct() { |
| 34 | + if ( !class_exists( 'ExtParserFunctions' ) ) |
| 35 | + throw new ParserFunctionsNotFoundException; |
36 | 36 | # FIXME: Strict Standards: Non-static method ExtParserFunctions::getExprParser() should not be called statically, assuming $this from incompatible context in MathStatFunctions.php on line 34 |
37 | | - $this->exprParser = ExtParserFunctions::getExprParser(); |
38 | | - } |
| 37 | + $this->exprParser = ExtParserFunctions::getExprParser(); |
| 38 | + } |
39 | 39 | |
40 | | - public function constHook(&$parser, $key=''){ |
41 | | - switch($key){ |
42 | | - case 'pi': |
43 | | - return '3.14159265358979323846'; |
44 | | - break; |
45 | | - case 'pi/2': |
46 | | - return '1.57079632679489661923'; |
47 | | - break; |
48 | | - case 'pi/4': |
49 | | - return '0.78539816339744830962'; |
50 | | - break; |
51 | | - case '1/pi': |
52 | | - return '0.31830988618379067154'; |
53 | | - break; |
54 | | - case '2/pi': |
55 | | - return '0.63661977236758134308'; |
56 | | - break; |
57 | | - case 'sqrt(pi)': |
58 | | - return '1.77245385090551602729'; |
59 | | - break; |
60 | | - case '2/sqrt(pi)': |
61 | | - return '1.12837916709551257390'; |
62 | | - break; |
63 | | - case 'e': |
64 | | - return '2.7182818284590452354'; |
65 | | - break; |
66 | | - case 'log_2(e)': |
67 | | - return '1.4426950408889634074'; |
68 | | - break; |
69 | | - case 'log_10(e)': |
70 | | - return '0.43429448190325182765'; |
71 | | - break; |
72 | | - case 'ln(2)': |
73 | | - return '0.69314718055994530942'; |
74 | | - break; |
75 | | - case 'ln(10)': |
76 | | - return '2.30258509299404568402'; |
77 | | - break; |
78 | | - case 'sqrt(2)': |
79 | | - return '1.41421356237309504880'; |
80 | | - break; |
81 | | - case 'sqrt(3)': |
82 | | - return '1.73205080756887729352'; |
83 | | - break; |
84 | | - case '1/sqrt(2)': |
85 | | - case 'sqrt(1/2)': |
86 | | - return '0.70710678118654752440'; |
87 | | - break; |
88 | | - case 'ln(pi)': |
89 | | - return '1.14472988584940017414'; |
90 | | - break; |
91 | | - case 'euler': |
92 | | - return '0.57721566490153286061'; |
93 | | - break; |
94 | | - case 'brion': |
95 | | - return '6'; //Brions constant |
96 | | - break; |
97 | | - default: |
98 | | - return ''; |
99 | | - } |
100 | | - } |
| 40 | + public function constHook( &$parser, $key = '' ) { |
| 41 | + switch( $key ) { |
| 42 | + case 'pi': |
| 43 | + return '3.14159265358979323846'; |
| 44 | + break; |
| 45 | + case 'pi/2': |
| 46 | + return '1.57079632679489661923'; |
| 47 | + break; |
| 48 | + case 'pi/4': |
| 49 | + return '0.78539816339744830962'; |
| 50 | + break; |
| 51 | + case '1/pi': |
| 52 | + return '0.31830988618379067154'; |
| 53 | + break; |
| 54 | + case '2/pi': |
| 55 | + return '0.63661977236758134308'; |
| 56 | + break; |
| 57 | + case 'sqrt(pi)': |
| 58 | + return '1.77245385090551602729'; |
| 59 | + break; |
| 60 | + case '2/sqrt(pi)': |
| 61 | + return '1.12837916709551257390'; |
| 62 | + break; |
| 63 | + case 'e': |
| 64 | + return '2.7182818284590452354'; |
| 65 | + break; |
| 66 | + case 'log_2(e)': |
| 67 | + return '1.4426950408889634074'; |
| 68 | + break; |
| 69 | + case 'log_10(e)': |
| 70 | + return '0.43429448190325182765'; |
| 71 | + break; |
| 72 | + case 'ln(2)': |
| 73 | + return '0.69314718055994530942'; |
| 74 | + break; |
| 75 | + case 'ln(10)': |
| 76 | + return '2.30258509299404568402'; |
| 77 | + break; |
| 78 | + case 'sqrt(2)': |
| 79 | + return '1.41421356237309504880'; |
| 80 | + break; |
| 81 | + case 'sqrt(3)': |
| 82 | + return '1.73205080756887729352'; |
| 83 | + break; |
| 84 | + case '1/sqrt(2)': |
| 85 | + case 'sqrt(1/2)': |
| 86 | + return '0.70710678118654752440'; |
| 87 | + break; |
| 88 | + case 'ln(pi)': |
| 89 | + return '1.14472988584940017414'; |
| 90 | + break; |
| 91 | + case 'euler': |
| 92 | + return '0.57721566490153286061'; |
| 93 | + break; |
| 94 | + case 'brion': |
| 95 | + return '6'; // Brions constant |
| 96 | + break; |
| 97 | + default: |
| 98 | + return ''; |
| 99 | + } |
| 100 | + } |
101 | 101 | |
102 | | - public function medianHook(&$parser) { |
103 | | - $args = func_get_args(); |
104 | | - array_shift( $args ); |
| 102 | + public function medianHook( &$parser ) { |
| 103 | + $args = func_get_args(); |
| 104 | + array_shift( $args ); |
105 | 105 | |
106 | | - try{ |
107 | | - foreach($args as $expr){ |
108 | | - $res = $this->exprParser->doExpression($expr); |
109 | | - $values[] = $res; |
110 | | - } |
111 | | - } catch (ExprError $e){ |
112 | | - return $e->getMessage(); |
113 | | - } |
114 | | - sort($values); |
115 | | - $nbr_values = count($values); |
116 | | - if($nbr_values % 2 == 1){ // odd number of values |
117 | | - return $values[$nbr_values / 2]; |
118 | | - } else { // even number of values |
119 | | - return ($values[$nbr_values / 2 -1] + $values[$nbr_values / 2]) / 2; |
120 | | - } |
121 | | - } |
| 106 | + try { |
| 107 | + foreach ( $args as $expr ) { |
| 108 | + $res = $this->exprParser->doExpression( $expr ); |
| 109 | + $values[] = $res; |
| 110 | + } |
| 111 | + } |
| 112 | + catch ( ExprError $e ) { |
| 113 | + return $e->getMessage(); |
| 114 | + } |
| 115 | + sort( $values ); |
| 116 | + $nbr_values = count( $values ); |
| 117 | + if ( $nbr_values % 2 == 1 ) { // odd number of values |
| 118 | + return $values[$nbr_values / 2]; |
| 119 | + } |
| 120 | + else { // even number of values |
| 121 | + return ( $values[$nbr_values / 2 - 1] + $values[$nbr_values / 2] ) / 2; |
| 122 | + } |
| 123 | + } |
122 | 124 | |
123 | | - public function meanHook(&$parser) { |
124 | | - $args = func_get_args(); |
125 | | - array_shift( $args ); |
126 | | - try{ |
127 | | - foreach($args as $expr){ |
128 | | - $res = $this->exprParser->doExpression($expr); |
129 | | - $values[] = $res; |
130 | | - } |
131 | | - } catch (ExprError $e){ |
132 | | - return $e->getMessage(); |
133 | | - } |
134 | | - return array_sum($values)/count($values); |
135 | | - } |
| 125 | + public function meanHook( &$parser ) { |
| 126 | + $args = func_get_args(); |
| 127 | + array_shift( $args ); |
| 128 | + try { |
| 129 | + foreach ( $args as $expr ) { |
| 130 | + $res = $this->exprParser->doExpression( $expr ); |
| 131 | + $values[] = $res; |
| 132 | + } |
| 133 | + } |
| 134 | + catch ( ExprError $e ) { |
| 135 | + return $e->getMessage(); |
| 136 | + } |
| 137 | + return array_sum( $values ) / count( $values ); |
| 138 | + } |
136 | 139 | |
137 | | - public function expHook(&$parser, $expr = '') { |
138 | | - try{ |
139 | | - $res = $this->exprParser->doExpression($expr); |
140 | | - } catch (ExprError $e){ |
141 | | - return $e->getMessage(); |
142 | | - } |
143 | | - $result = exp($res); |
144 | | - return $this->check($result); |
145 | | - } |
| 140 | + public function expHook( &$parser, $expr = '' ) { |
| 141 | + try { |
| 142 | + $res = $this->exprParser->doExpression( $expr ); |
| 143 | + } |
| 144 | + catch ( ExprError $e ) { |
| 145 | + return $e->getMessage(); |
| 146 | + } |
| 147 | + $result = exp( $res ); |
| 148 | + return $this->check( $result ); |
| 149 | + } |
146 | 150 | |
147 | | - public function lnHook(&$parser, $expr = '') { |
148 | | - try{ |
149 | | - $res = $this->exprParser->doExpression($expr); |
150 | | - } catch (ExprError $e){ |
151 | | - return $e->getMessage(); |
152 | | - } |
153 | | - $result = log($res); |
| 151 | + public function lnHook( &$parser, $expr = '' ) { |
| 152 | + try { |
| 153 | + $res = $this->exprParser->doExpression( $expr ); |
| 154 | + } |
| 155 | + catch ( ExprError $e ) { |
| 156 | + return $e->getMessage(); |
| 157 | + } |
| 158 | + $result = log( $res ); |
154 | 159 | |
155 | | - return $this->check($result); |
156 | | - } |
| 160 | + return $this->check( $result ); |
| 161 | + } |
157 | 162 | |
158 | | - public function logHook(&$parser, $expr = '' , $base = 10) { |
159 | | - try{ |
160 | | - $res = $this->exprParser->doExpression($expr); |
161 | | - } catch (ExprError $e){ |
162 | | - return $e->getMessage(); |
163 | | - } |
164 | | - $result = log($res,$base); |
165 | | - return $this->check(log($res,$base)); |
166 | | - } |
| 163 | + public function logHook( &$parser, $expr = '' , $base = 10 ) { |
| 164 | + try { |
| 165 | + $res = $this->exprParser->doExpression( $expr ); |
| 166 | + } |
| 167 | + catch ( ExprError $e ) { |
| 168 | + return $e->getMessage(); |
| 169 | + } |
| 170 | + $result = log( $res, $base ); |
| 171 | + return $this->check( log( $res, $base ) ); |
| 172 | + } |
167 | 173 | |
168 | | - public function tanHook(&$parser, $expr = '') { |
169 | | - try{ |
170 | | - $res = $this->exprParser->doExpression($expr); |
171 | | - } catch (ExprError $e){ |
172 | | - return $e->getMessage(); |
173 | | - } |
174 | | - $result = tan($res); |
175 | | - return $this->check($result); |
176 | | - } |
| 174 | + public function tanHook( &$parser, $expr = '' ) { |
| 175 | + try { |
| 176 | + $res = $this->exprParser->doExpression( $expr ); |
| 177 | + } |
| 178 | + catch ( ExprError $e ) { |
| 179 | + return $e->getMessage(); |
| 180 | + } |
| 181 | + $result = tan( $res ); |
| 182 | + return $this->check( $result ); |
| 183 | + } |
177 | 184 | |
178 | | - public function atanHook(&$parser, $expr = '') { |
179 | | - try{ |
180 | | - $res = $this->exprParser->doExpression($expr); |
181 | | - } catch (ExprError $e){ |
182 | | - return $e->getMessage(); |
183 | | - } |
184 | | - $result = atan($res); |
185 | | - return $this->check($result); |
186 | | - } |
| 185 | + public function atanHook( &$parser, $expr = '' ) { |
| 186 | + try { |
| 187 | + $res = $this->exprParser->doExpression( $expr ); |
| 188 | + } |
| 189 | + catch ( ExprError $e ) { |
| 190 | + return $e->getMessage(); |
| 191 | + } |
| 192 | + $result = atan( $res ); |
| 193 | + return $this->check( $result ); |
| 194 | + } |
187 | 195 | |
188 | | - public function tanhHook(&$parser, $expr = '') { |
189 | | - try{ |
190 | | - $res = $this->exprParser->doExpression($expr); |
191 | | - } catch (ExprError $e){ |
192 | | - return $e->getMessage(); |
193 | | - } |
194 | | - $result = tanh($res); |
195 | | - return $this->check($result); |
196 | | - } |
| 196 | + public function tanhHook( &$parser, $expr = '' ) { |
| 197 | + try { |
| 198 | + $res = $this->exprParser->doExpression( $expr ); |
| 199 | + } |
| 200 | + catch ( ExprError $e ) { |
| 201 | + return $e->getMessage(); |
| 202 | + } |
| 203 | + $result = tanh( $res ); |
| 204 | + return $this->check( $result ); |
| 205 | + } |
197 | 206 | |
198 | | - public function cosHook(&$parser, $expr = '') { |
199 | | - try{ |
200 | | - $res = $this->exprParser->doExpression($expr); |
201 | | - } catch (ExprError $e){ |
202 | | - return $e->getMessage(); |
203 | | - } |
204 | | - $result = cos($res); |
205 | | - return $this->check($result); |
206 | | - } |
| 207 | + public function cosHook( &$parser, $expr = '' ) { |
| 208 | + try { |
| 209 | + $res = $this->exprParser->doExpression( $expr ); |
| 210 | + } |
| 211 | + catch ( ExprError $e ) { |
| 212 | + return $e->getMessage(); |
| 213 | + } |
| 214 | + $result = cos( $res ); |
| 215 | + return $this->check( $result ); |
| 216 | + } |
207 | 217 | |
208 | | - public function acosHook(&$parser, $expr = '') { |
209 | | - try{ |
210 | | - $res = $this->exprParser->doExpression($expr); |
211 | | - } catch (ExprError $e){ |
212 | | - return $e->getMessage(); |
213 | | - } |
214 | | - $result = acos($res); |
215 | | - return $this->check($result); |
216 | | - } |
| 218 | + public function acosHook( &$parser, $expr = '' ) { |
| 219 | + try { |
| 220 | + $res = $this->exprParser->doExpression( $expr ); |
| 221 | + } |
| 222 | + catch ( ExprError $e ) { |
| 223 | + return $e->getMessage(); |
| 224 | + } |
| 225 | + $result = acos( $res ); |
| 226 | + return $this->check( $result ); |
| 227 | + } |
217 | 228 | |
218 | | - public function coshHook(&$parser, $expr = '') { |
219 | | - try{ |
220 | | - $res = $this->exprParser->doExpression($expr); |
221 | | - } catch (ExprError $e){ |
222 | | - return $e->getMessage(); |
223 | | - } |
224 | | - $result = cosh($res); |
225 | | - return $this->check($result); |
226 | | - } |
| 229 | + public function coshHook( &$parser, $expr = '' ) { |
| 230 | + try { |
| 231 | + $res = $this->exprParser->doExpression( $expr ); |
| 232 | + } |
| 233 | + catch ( ExprError $e ) { |
| 234 | + return $e->getMessage(); |
| 235 | + } |
| 236 | + $result = cosh( $res ); |
| 237 | + return $this->check( $result ); |
| 238 | + } |
227 | 239 | |
228 | | - public function sinHook(&$parser, $expr = '') { |
229 | | - try{ |
230 | | - $res = $this->exprParser->doExpression($expr); |
231 | | - } catch (ExprError $e){ |
232 | | - return $e->getMessage(); |
233 | | - } |
234 | | - $result = sin($res); |
235 | | - return $this->check($result); |
236 | | - } |
| 240 | + public function sinHook( &$parser, $expr = '' ) { |
| 241 | + try { |
| 242 | + $res = $this->exprParser->doExpression( $expr ); |
| 243 | + } |
| 244 | + catch ( ExprError $e ) { |
| 245 | + return $e->getMessage(); |
| 246 | + } |
| 247 | + $result = sin( $res ); |
| 248 | + return $this->check( $result ); |
| 249 | + } |
237 | 250 | |
238 | | - public function asinHook(&$parser, $expr = '') { |
239 | | - try{ |
240 | | - $res = $this->exprParser->doExpression($expr); |
241 | | - } catch (ExprError $e){ |
242 | | - return $e->getMessage(); |
243 | | - } |
244 | | - $result = asin($res); |
245 | | - return $this->check($result); |
246 | | - } |
| 251 | + public function asinHook( &$parser, $expr = '' ) { |
| 252 | + try { |
| 253 | + $res = $this->exprParser->doExpression( $expr ); |
| 254 | + } |
| 255 | + catch ( ExprError $e ) { |
| 256 | + return $e->getMessage(); |
| 257 | + } |
| 258 | + $result = asin( $res ); |
| 259 | + return $this->check( $result ); |
| 260 | + } |
247 | 261 | |
248 | | - public function sinhHook(&$parser, $expr = '') { |
249 | | - try{ |
250 | | - $res = $this->exprParser->doExpression($expr); |
251 | | - } catch (ExprError $e){ |
252 | | - return $e->getMessage(); |
253 | | - } |
254 | | - $result = sinh($res); |
255 | | - return $this->check($result); |
256 | | - } |
| 262 | + public function sinhHook( &$parser, $expr = '' ) { |
| 263 | + try { |
| 264 | + $res = $this->exprParser->doExpression( $expr ); |
| 265 | + } |
| 266 | + catch ( ExprError $e ) { |
| 267 | + return $e->getMessage(); |
| 268 | + } |
| 269 | + $result = sinh( $res ); |
| 270 | + return $this->check( $result ); |
| 271 | + } |
257 | 272 | |
258 | | - public function atanhHook(&$parser, $expr = '') { |
259 | | - try{ |
260 | | - $res = $this->exprParser->doExpression($expr); |
261 | | - } catch (ExprError $e){ |
262 | | - return $e->getMessage(); |
263 | | - } |
264 | | - if(function_exists('atanh')){ |
265 | | - $result = atanh($res); |
266 | | - } else { |
267 | | - $result = log(sqrt(1-$res^2)/(1-$res)); |
268 | | - } |
269 | | - return $this->check($result); |
270 | | - } |
| 273 | + public function atanhHook( &$parser, $expr = '' ) { |
| 274 | + try { |
| 275 | + $res = $this->exprParser->doExpression( $expr ); |
| 276 | + } |
| 277 | + catch ( ExprError $e ) { |
| 278 | + return $e->getMessage(); |
| 279 | + } |
| 280 | + if ( function_exists( 'atanh' ) ) { |
| 281 | + $result = atanh( $res ); |
| 282 | + } |
| 283 | + else { |
| 284 | + $result = log( sqrt( 1 - $res ^ 2 ) / ( 1 - $res ) ); |
| 285 | + } |
| 286 | + return $this->check( $result ); |
| 287 | + } |
271 | 288 | |
272 | | - public function acoshHook(&$parser, $expr = '') { |
273 | | - try{ |
274 | | - $res = $this->exprParser->doExpression($expr); |
275 | | - } catch (ExprError $e){ |
276 | | - return $e->getMessage(); |
277 | | - } |
278 | | - if(function_exists('acosh')){ |
279 | | - $result = acosh($res); |
280 | | - } else { |
281 | | - $result = log($res + abs(sqrt($res^2+1))); //may be wrong |
282 | | - } |
283 | | - return $this->check($result); |
284 | | - } |
| 289 | + public function acoshHook( &$parser, $expr = '' ) { |
| 290 | + try { |
| 291 | + $res = $this->exprParser->doExpression( $expr ); |
| 292 | + } |
| 293 | + catch ( ExprError $e ) { |
| 294 | + return $e->getMessage(); |
| 295 | + } |
| 296 | + if ( function_exists( 'acosh' ) ) { |
| 297 | + $result = acosh( $res ); |
| 298 | + } |
| 299 | + else { |
| 300 | + $result = log( $res + abs( sqrt( $res ^ 2 + 1 ) ) ); // may be wrong |
| 301 | + } |
| 302 | + return $this->check( $result ); |
| 303 | + } |
285 | 304 | |
286 | | - public function asinhHook(&$parser, $expr = '') { |
287 | | - try{ |
288 | | - $res = $this->exprParser->doExpression($expr); |
289 | | - } catch (ExprError $e){ |
290 | | - return $e->getMessage(); |
291 | | - } |
292 | | - if(function_exists('asinh')){ |
293 | | - $result = asinh($res); |
294 | | - } else { |
295 | | - $result = log($res + sqrt($res^2+1)); |
296 | | - } |
297 | | - $result = asinh($res); |
298 | | - return $this->check($result); |
299 | | - } |
| 305 | + public function asinhHook( &$parser, $expr = '' ) { |
| 306 | + try { |
| 307 | + $res = $this->exprParser->doExpression( $expr ); |
| 308 | + } |
| 309 | + catch ( ExprError $e ) { |
| 310 | + return $e->getMessage(); |
| 311 | + } |
| 312 | + if ( function_exists( 'asinh' ) ) { |
| 313 | + $result = asinh( $res ); |
| 314 | + } |
| 315 | + else { |
| 316 | + $result = log( $res + sqrt( $res ^ 2 + 1 ) ); |
| 317 | + } |
| 318 | + $result = asinh( $res ); |
| 319 | + return $this->check( $result ); |
| 320 | + } |
300 | 321 | |
301 | | - public function cotHook(&$parser, $expr = '') { |
302 | | - try{ |
303 | | - $res = $this->exprParser->doExpression($expr); |
304 | | - } catch (ExprError $e){ |
305 | | - return $e->getMessage(); |
306 | | - } |
307 | | - $tmp = tan($res); |
308 | | - if($tmp == 0){ |
| 322 | + public function cotHook( &$parser, $expr = '' ) { |
| 323 | + try { |
| 324 | + $res = $this->exprParser->doExpression( $expr ); |
| 325 | + } |
| 326 | + catch ( ExprError $e ) { |
| 327 | + return $e->getMessage(); |
| 328 | + } |
| 329 | + $tmp = tan( $res ); |
| 330 | + if ( $tmp == 0 ) { |
309 | 331 | wfLoadExtensionMessages( 'MathStatFunctions' ); |
310 | | - return wfMsg('msfunc_div_zero'); |
311 | | - } |
312 | | - $result = 1/$tmp; |
313 | | - return $this->check($result); |
314 | | - } |
| 332 | + return wfMsg( 'msfunc_div_zero' ); |
| 333 | + } |
| 334 | + $result = 1 / $tmp; |
| 335 | + return $this->check( $result ); |
| 336 | + } |
315 | 337 | |
316 | | - public function secHook(&$parser, $expr = '') { |
317 | | - try{ |
318 | | - $res = $this->exprParser->doExpression($expr); |
319 | | - } catch (ExprError $e){ |
320 | | - return $e->getMessage(); |
321 | | - } |
322 | | - $tmp = cos($res); |
323 | | - if($tmp == 0){ |
| 338 | + public function secHook( &$parser, $expr = '' ) { |
| 339 | + try { |
| 340 | + $res = $this->exprParser->doExpression( $expr ); |
| 341 | + } |
| 342 | + catch ( ExprError $e ) { |
| 343 | + return $e->getMessage(); |
| 344 | + } |
| 345 | + $tmp = cos( $res ); |
| 346 | + if ( $tmp == 0 ) { |
324 | 347 | wfLoadExtensionMessages( 'MathStatFunctions' ); |
325 | | - return wfMsg('msfunc_div_zero'); |
326 | | - } |
| 348 | + return wfMsg( 'msfunc_div_zero' ); |
| 349 | + } |
327 | 350 | |
328 | | - $result = 1/$tmp; |
329 | | - return $this->check($result); |
330 | | - } |
| 351 | + $result = 1 / $tmp; |
| 352 | + return $this->check( $result ); |
| 353 | + } |
331 | 354 | |
332 | | - public function cscHook(&$parser, $expr = '') { |
333 | | - try{ |
334 | | - $res = $this->exprParser->doExpression($expr); |
335 | | - } catch (ExprError $e){ |
336 | | - return $e->getMessage(); |
337 | | - } |
338 | | - $tmp = sin($res); |
339 | | - if($tmp == 0){ |
| 355 | + public function cscHook( &$parser, $expr = '' ) { |
| 356 | + try { |
| 357 | + $res = $this->exprParser->doExpression( $expr ); |
| 358 | + } |
| 359 | + catch ( ExprError $e ) { |
| 360 | + return $e->getMessage(); |
| 361 | + } |
| 362 | + $tmp = sin( $res ); |
| 363 | + if ( $tmp == 0 ) { |
340 | 364 | wfLoadExtensionMessages( 'MathStatFunctions' ); |
341 | | - return wfMsg('msfunc_div_zero'); |
342 | | - } |
343 | | - $result = 1/$tmp; |
344 | | - return $this->check($result); |
345 | | - } |
| 365 | + return wfMsg( 'msfunc_div_zero' ); |
| 366 | + } |
| 367 | + $result = 1 / $tmp; |
| 368 | + return $this->check( $result ); |
| 369 | + } |
346 | 370 | |
347 | | - public function acscHook(&$parser, $expr = '') { |
348 | | - try{ |
349 | | - $res = $this->exprParser->doExpression($expr); |
350 | | - } catch (ExprError $e){ |
351 | | - return $e->getMessage(); |
352 | | - } |
353 | | - $result = asin(pow($res,-1)); |
354 | | - return $this->check($result); |
355 | | - } |
| 371 | + public function acscHook( &$parser, $expr = '' ) { |
| 372 | + try { |
| 373 | + $res = $this->exprParser->doExpression( $expr ); |
| 374 | + } |
| 375 | + catch ( ExprError $e ) { |
| 376 | + return $e->getMessage(); |
| 377 | + } |
| 378 | + $result = asin( pow( $res, - 1 ) ); |
| 379 | + return $this->check( $result ); |
| 380 | + } |
356 | 381 | |
357 | | - public function asecHook(&$parser, $expr = '') { |
358 | | - try{ |
359 | | - $res = $this->exprParser->doExpression($expr); |
360 | | - } catch (ExprError $e){ |
361 | | - return $e->getMessage(); |
362 | | - } |
363 | | - $result = acos(pow($res,-1)); |
364 | | - return $this->check($result); |
365 | | - } |
| 382 | + public function asecHook( &$parser, $expr = '' ) { |
| 383 | + try { |
| 384 | + $res = $this->exprParser->doExpression( $expr ); |
| 385 | + } |
| 386 | + catch ( ExprError $e ) { |
| 387 | + return $e->getMessage(); |
| 388 | + } |
| 389 | + $result = acos( pow( $res, - 1 ) ); |
| 390 | + return $this->check( $result ); |
| 391 | + } |
366 | 392 | |
367 | | - public function acotHook(&$parser, $expr = '') { |
368 | | - try{ |
369 | | - $res = $this->exprParser->doExpression($expr); |
370 | | - } catch (ExprError $e){ |
371 | | - return $e->getMessage(); |
372 | | - } |
373 | | - $result = M_PI2 - atan($res); |
374 | | - return $this->check($result); |
375 | | - } |
| 393 | + public function acotHook( &$parser, $expr = '' ) { |
| 394 | + try { |
| 395 | + $res = $this->exprParser->doExpression( $expr ); |
| 396 | + } |
| 397 | + catch ( ExprError $e ) { |
| 398 | + return $e->getMessage(); |
| 399 | + } |
| 400 | + $result = M_PI2 - atan( $res ); |
| 401 | + return $this->check( $result ); |
| 402 | + } |
376 | 403 | |
377 | | - // Private |
| 404 | + // Private |
378 | 405 | |
379 | | - private $exprParser; |
| 406 | + private $exprParser; |
380 | 407 | |
381 | | - private function check($value) { |
382 | | - if(is_nan($value)){ |
| 408 | + private function check( $value ) { |
| 409 | + if ( is_nan( $value ) ) { |
383 | 410 | wfLoadExtensionMessages( 'MathStatFunctions' ); |
384 | | - return wfMsg('msfunc_nan'); |
385 | | - } elseif(is_infinite($value) and false){ |
| 411 | + return wfMsg( 'msfunc_nan' ); |
| 412 | + } |
| 413 | + elseif ( is_infinite( $value ) and false ) { |
386 | 414 | wfLoadExtensionMessages( 'MathStatFunctions' ); |
387 | | - return wfMsg('msfunc_inf').($value < 0 ? '-' : '+'); |
388 | | - } else { |
389 | | - return $value; |
390 | | - } |
391 | | - } |
| 415 | + return wfMsg( 'msfunc_inf' ) . ( $value < 0 ? '-' : '+' ); |
| 416 | + } |
| 417 | + else { |
| 418 | + return $value; |
| 419 | + } |
| 420 | + } |
392 | 421 | } |
393 | 422 | |
394 | 423 | function wfSetupMathStatFunctions() { |
395 | | - global $wgParser, $wgExtMathStatFunctions; |
| 424 | + global $wgParser, $wgExtMathStatFunctions; |
396 | 425 | |
397 | | - try { |
398 | | - $wgExtMathStatFunctions = new ExtMathStatFunctions; |
399 | | - } catch (ParserFunctionsNotFoundException $e) { |
400 | | - throw new FatalError('in '.$e->getFile().' on line '.$e->getLine().': '.$e->getMessage()); |
401 | | - } |
| 426 | + try { |
| 427 | + $wgExtMathStatFunctions = new ExtMathStatFunctions; |
| 428 | + } |
| 429 | + catch ( ParserFunctionsNotFoundException $e ) { |
| 430 | + throw new FatalError( 'in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage() ); |
| 431 | + } |
402 | 432 | |
403 | | - $wgParser->setFunctionHook( 'const', array( &$wgExtMathStatFunctions, 'constHook' ) ); |
404 | | - $wgParser->setFunctionHook( 'median', array( &$wgExtMathStatFunctions, 'medianHook' ) ); |
405 | | - $wgParser->setFunctionHook( 'mean', array( &$wgExtMathStatFunctions, 'meanHook' ) ); |
406 | | - $wgParser->setFunctionHook( 'exp', array( &$wgExtMathStatFunctions, 'expHook' ) ); |
407 | | - $wgParser->setFunctionHook( 'log', array( &$wgExtMathStatFunctions, 'logHook' ) ); |
408 | | - $wgParser->setFunctionHook( 'ln', array( &$wgExtMathStatFunctions, 'lnHook' ) ); |
409 | | - $wgParser->setFunctionHook( 'tan', array( &$wgExtMathStatFunctions, 'tanHook' ) ); |
410 | | - $wgParser->setFunctionHook( 'atan', array( &$wgExtMathStatFunctions, 'atanHook' ) ); |
411 | | - $wgParser->setFunctionHook( 'tanh', array( &$wgExtMathStatFunctions, 'tanhHook' ) ); |
412 | | - $wgParser->setFunctionHook( 'atanh', array( &$wgExtMathStatFunctions, 'atanhHook' ) ); |
413 | | - $wgParser->setFunctionHook( 'cot', array( &$wgExtMathStatFunctions, 'cotHook' ) ); |
414 | | - $wgParser->setFunctionHook( 'acot', array( &$wgExtMathStatFunctions, 'acotHook' ) ); |
415 | | - $wgParser->setFunctionHook( 'cos', array( &$wgExtMathStatFunctions, 'cosHook' ) ); |
416 | | - $wgParser->setFunctionHook( 'acos', array( &$wgExtMathStatFunctions, 'acosHook' ) ); |
417 | | - $wgParser->setFunctionHook( 'cosh', array( &$wgExtMathStatFunctions, 'coshHook' ) ); |
418 | | - $wgParser->setFunctionHook( 'acosh', array( &$wgExtMathStatFunctions, 'acoshHook' ) ); |
419 | | - $wgParser->setFunctionHook( 'sec', array( &$wgExtMathStatFunctions, 'secHook' ) ); |
420 | | - $wgParser->setFunctionHook( 'asec', array( &$wgExtMathStatFunctions, 'asecHook' ) ); |
421 | | - $wgParser->setFunctionHook( 'sin', array( &$wgExtMathStatFunctions, 'sinHook' ) ); |
422 | | - $wgParser->setFunctionHook( 'asin', array( &$wgExtMathStatFunctions, 'asinHook' ) ); |
423 | | - $wgParser->setFunctionHook( 'sinh', array( &$wgExtMathStatFunctions, 'sinhHook' ) ); |
424 | | - $wgParser->setFunctionHook( 'asinh', array( &$wgExtMathStatFunctions, 'asinhHook' ) ); |
425 | | - $wgParser->setFunctionHook( 'csc', array( &$wgExtMathStatFunctions, 'cscHook' ) ); |
426 | | - $wgParser->setFunctionHook( 'acsc', array( &$wgExtMathStatFunctions, 'acscHook' ) ); |
| 433 | + $wgParser->setFunctionHook( 'const', array( &$wgExtMathStatFunctions, 'constHook' ) ); |
| 434 | + $wgParser->setFunctionHook( 'median', array( &$wgExtMathStatFunctions, 'medianHook' ) ); |
| 435 | + $wgParser->setFunctionHook( 'mean', array( &$wgExtMathStatFunctions, 'meanHook' ) ); |
| 436 | + $wgParser->setFunctionHook( 'exp', array( &$wgExtMathStatFunctions, 'expHook' ) ); |
| 437 | + $wgParser->setFunctionHook( 'log', array( &$wgExtMathStatFunctions, 'logHook' ) ); |
| 438 | + $wgParser->setFunctionHook( 'ln', array( &$wgExtMathStatFunctions, 'lnHook' ) ); |
| 439 | + $wgParser->setFunctionHook( 'tan', array( &$wgExtMathStatFunctions, 'tanHook' ) ); |
| 440 | + $wgParser->setFunctionHook( 'atan', array( &$wgExtMathStatFunctions, 'atanHook' ) ); |
| 441 | + $wgParser->setFunctionHook( 'tanh', array( &$wgExtMathStatFunctions, 'tanhHook' ) ); |
| 442 | + $wgParser->setFunctionHook( 'atanh', array( &$wgExtMathStatFunctions, 'atanhHook' ) ); |
| 443 | + $wgParser->setFunctionHook( 'cot', array( &$wgExtMathStatFunctions, 'cotHook' ) ); |
| 444 | + $wgParser->setFunctionHook( 'acot', array( &$wgExtMathStatFunctions, 'acotHook' ) ); |
| 445 | + $wgParser->setFunctionHook( 'cos', array( &$wgExtMathStatFunctions, 'cosHook' ) ); |
| 446 | + $wgParser->setFunctionHook( 'acos', array( &$wgExtMathStatFunctions, 'acosHook' ) ); |
| 447 | + $wgParser->setFunctionHook( 'cosh', array( &$wgExtMathStatFunctions, 'coshHook' ) ); |
| 448 | + $wgParser->setFunctionHook( 'acosh', array( &$wgExtMathStatFunctions, 'acoshHook' ) ); |
| 449 | + $wgParser->setFunctionHook( 'sec', array( &$wgExtMathStatFunctions, 'secHook' ) ); |
| 450 | + $wgParser->setFunctionHook( 'asec', array( &$wgExtMathStatFunctions, 'asecHook' ) ); |
| 451 | + $wgParser->setFunctionHook( 'sin', array( &$wgExtMathStatFunctions, 'sinHook' ) ); |
| 452 | + $wgParser->setFunctionHook( 'asin', array( &$wgExtMathStatFunctions, 'asinHook' ) ); |
| 453 | + $wgParser->setFunctionHook( 'sinh', array( &$wgExtMathStatFunctions, 'sinhHook' ) ); |
| 454 | + $wgParser->setFunctionHook( 'asinh', array( &$wgExtMathStatFunctions, 'asinhHook' ) ); |
| 455 | + $wgParser->setFunctionHook( 'csc', array( &$wgExtMathStatFunctions, 'cscHook' ) ); |
| 456 | + $wgParser->setFunctionHook( 'acsc', array( &$wgExtMathStatFunctions, 'acscHook' ) ); |
427 | 457 | |
428 | | - return true; |
| 458 | + return true; |
429 | 459 | } |
430 | 460 | |
431 | 461 | function wfMathStatFunctionsLanguageGetMagic( &$magicWords, $langCode ) { |
432 | | - global $wgMathStatFunctionsMagic; |
| 462 | + global $wgMathStatFunctionsMagic; |
433 | 463 | require_once( dirname(__FILE__) . '/MathStatFunctions.i18n.magic.php' ); |
434 | 464 | |
435 | | - if(!in_array($langCode,$wgMathStatFunctionsMagic)) $langCode = 'en'; |
436 | | - $magicWords = array_merge($magicWords, $wgMathStatFunctionsMagic[$langCode]); |
437 | | - return true; |
| 465 | + if ( !in_array( $langCode, $wgMathStatFunctionsMagic ) ) $langCode = 'en'; |
| 466 | + $magicWords = array_merge( $magicWords, $wgMathStatFunctionsMagic[$langCode] ); |
| 467 | + return true; |
438 | 468 | } |