Pastakhov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/69627
Change subject: Add Mathematical Functions (version 0.4.4)
......................................................................
Add Mathematical Functions (version 0.4.4)
Change-Id: Ib236faccc0cb1fdd6c44f4938108056451727acf
---
M Foxway.php
M Settings.php
A includes/functions/FMath.php
3 files changed, 163 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway
refs/changes/27/69627/1
diff --git a/Foxway.php b/Foxway.php
index 5809ac9..4295eb8 100644
--- a/Foxway.php
+++ b/Foxway.php
@@ -15,7 +15,7 @@
die( 'This file is an extension to MediaWiki and thus not a valid entry
point.' );
}
-define( 'Foxway_VERSION' , '0.4.3' );
+define( 'Foxway_VERSION' , '0.4.4' );
// Register this extension on Special:Version
$wgExtensionCredits['parserhook'][] = array(
@@ -64,6 +64,7 @@
$wgAutoloadClasses['Foxway\\BaseFunction'] = $dir .
'/includes/functions/BaseFunction.php';
$wgAutoloadClasses['Foxway\\FArray'] = $dir .
'/includes/functions/FArray.php';
+$wgAutoloadClasses['Foxway\\FMath'] = $dir .
'/includes/functions/FMath.php';
$wgAutoloadClasses['Foxway\\Fpcre'] = $dir .
'/includes/functions/Fpcre.php';
$wgAutoloadClasses['Foxway\\FString'] = $dir .
'/includes/functions/FString.php';
$wgAutoloadClasses['Foxway\\FVariable'] = $dir .
'/includes/functions/FVariable.php';
diff --git a/Settings.php b/Settings.php
index d5fbd49..69ba5ca 100644
--- a/Settings.php
+++ b/Settings.php
@@ -224,6 +224,56 @@
//'preg_replace', not tested
'preg_split',
),
+ 'FMath' => array( // Math Functions @see
http://www.php.net/manual/en/ref.math.php
+ 'abs',
+ 'acos',
+ 'acosh',
+ 'asin',
+ 'asinh',
+ 'atan2',
+ 'atan',
+ 'atanh',
+ 'base_convert',
+ 'bindec',
+ 'ceil',
+ 'cos',
+ 'cosh',
+ 'decbin',
+ 'dechex',
+ 'decoct',
+ 'deg2rad',
+ 'exp',
+ 'expm1',
+ 'floor',
+ 'fmod',
+ 'getrandmax',
+ 'hexdec',
+ 'hypot',
+ 'is_finite',
+ 'is_infinite',
+ 'is_nan',
+ 'lcg_value',
+ 'log10',
+ 'log1p',
+ 'log',
+ 'max',
+ 'min',
+ 'mt_getrandmax',
+ 'mt_rand',
+ 'mt_srand',
+ 'octdec',
+ 'pi',
+ 'pow',
+ 'rad2deg',
+ 'rand',
+ 'round',
+ 'sin',
+ 'sinh',
+ 'sqrt',
+ 'srand',
+ 'tan',
+ 'tanh',
+ ),
);
$wgFoxwayAllowedPHPConstants = array(
@@ -347,4 +397,30 @@
'PREG_BAD_UTF8_OFFSET_ERROR',
'PCRE_VERSION',
'PREG_GREP_INVERT',
-);
\ No newline at end of file
+ // @see http://www.php.net/manual/en/math.constants.php
+ 'M_PI',
+ 'M_E',
+ 'M_LOG2E',
+ 'M_LOG10E',
+ 'M_LN2',
+ 'M_LN10',
+ 'M_PI_2',
+ 'M_PI_4',
+ 'M_1_PI',
+ 'M_2_PI',
+ 'M_SQRTPI',
+ 'M_2_SQRTPI',
+ 'M_SQRT2',
+ 'M_SQRT3',
+ 'M_SQRT1_2',
+ 'M_LNPI',
+ 'M_EULER',
+ 'PHP_ROUND_HALF_UP',
+ 'PHP_ROUND_HALF_DOWN',
+ 'PHP_ROUND_HALF_EVEN',
+ 'PHP_ROUND_HALF_ODD',
+ 'NAN',
+ 'INF',
+ 'PHP_INT_MAX',
+ 'PHP_INT_SIZE',
+);
diff --git a/includes/functions/FMath.php b/includes/functions/FMath.php
new file mode 100644
index 0000000..9c95833
--- /dev/null
+++ b/includes/functions/FMath.php
@@ -0,0 +1,84 @@
+<?php
+namespace Foxway;
+/**
+ * FMaths class implements Mathematical Functions for Foxway extension.
+ *
+ * @file FMath.php
+ * @ingroup Foxway
+ * @author Pavel Astakhov <[email protected]>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+class FMath extends BaseFunction {
+ protected static $listFunction = array(
+ 'f_abs' => array('abs', 1, 1),
+ 'f_acos' => array('acos', 1, 1),
+ 'f_acosh' => array('acosh', 1, 1),
+ 'f_asin' => array('asin', 1, 1),
+ 'f_asinh' => array('asinh', 1, 1),
+ 'f_atan2' => array('atan2', 2, 2),
+ 'f_atan' => array('atan', 1, 1),
+ 'f_atanh' => array('atanh', 1, 1),
+ 'f_base_convert' => array('base_convert', 3, 3),
+ 'f_bindec' => array('bindec', 1, 1),
+ 'f_ceil' => array('ceil', 1, 1),
+ 'f_cos' => array('cos', 1, 1),
+ 'f_cosh' => array('cosh', 1, 1),
+ 'f_decbin' => array('decbin', 1, 1),
+ 'f_dechex' => array('dechex', 1, 1),
+ 'f_decoct' => array('decoct', 1, 1),
+ 'f_deg2rad' => array('deg2rad', 1, 1),
+ 'f_exp' => array('exp', 1, 1),
+ 'f_expm1' => array('expm1', 1, 1),
+ 'f_floor' => array('floor', 1, 1),
+ 'f_fmod' => array('fmod', 2, 2),
+ 'f_getrandmax' => array('getrandmax', 0, 0),
+ 'f_hexdec' => array('hexdec', 1, 1),
+ 'f_hypot' => array('hypot', 2, 2),
+ 'f_is_finite' => array('is_finite', 1, 1),
+ 'f_is_infinite' => array('is_infinite', 1, 1),
+ 'f_is_nan' => array('is_nan', 1, 1),
+ 'f_lcg_value' => array('lcg_value', 0, 0),
+ 'f_log10' => array('log10', 1, 1),
+ 'f_log1p' => array('log1p', 1, 1),
+ 'f_log' => array('log', 1, 2),
+ 'f_max' => array('max', 1, FOXWAY_MAX_PAST_PARAM),
+ 'f_min' => array('min', 1, FOXWAY_MAX_PAST_PARAM),
+ 'f_mt_getrandmax' => array('mt_getrandmax', 0, 0),
+ 'f_mt_rand' => array('mt_rand', 0, 2),
+ 'f_mt_srand' => array('mt_srand', 0, 1),
+ 'f_octdec' => array('octdec', 1, 1),
+ 'f_pi' => array('pi', 0, 0),
+ 'f_pow' => array('pow', 2, 2),
+ 'f_rad2deg' => array('rad2deg', 1, 1),
+ 'f_rand' => array('rand', 0, 2),
+ 'f_round' => array('round', 1, 3),
+ 'f_sin' => array('sin', 1, 1),
+ 'f_sinh' => array('sinh', 1, 1),
+ 'f_sqrt' => array('sqrt', 1, 1),
+ 'f_srand' => array('srand', 0, 1),
+ 'f_tan' => array('tan', 1, 1),
+ 'f_tanh' => array('tanh', 1, 1),
+ );
+
+ public static function __callStatic($name, $arguments) {
+ if( isset(self::$listFunction[$name]) ) {
+ $funcData = &self::$listFunction[$name];
+ if( isset($arguments[0]) ) {
+ $refarg = &$arguments[0];
+ }else{
+ $refarg = array();
+ }
+ $c = count($refarg);
+ if( $c >= $funcData[1] && $c <= $funcData[2] ) {
+ wfSuppressWarnings();
+ $return = call_user_func_array($funcData[0],
$refarg);
+ wfRestoreWarnings();
+ return new RValue( $return );
+ }else{
+ return self::wrongParameterCount($name,
__LINE__);
+ }
+ } else {
+ return self::callUnknownMethod($name, __LINE__);
+ }
+ }
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/69627
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib236faccc0cb1fdd6c44f4938108056451727acf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits