2008-08-31 05:56:49 +00:00
|
|
|
<?php
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
/**
|
|
|
|
Abuse filter parser.
|
2010-08-19 21:12:09 +00:00
|
|
|
Copyright © Victor Vasiliev, 2008. Based on ideas by Andrew Garrett Distributed under GNU GPL v2 terms.
|
2008-08-31 05:56:49 +00:00
|
|
|
|
|
|
|
Types of token:
|
|
|
|
* T_NONE - special-purpose token
|
|
|
|
* T_BRACE - ( or )
|
|
|
|
* T_COMMA - ,
|
|
|
|
* T_OP - operator like + or ^
|
|
|
|
* T_NUMBER - number
|
|
|
|
* T_STRING - string, in "" or ''
|
|
|
|
* T_KEYWORD - keyword
|
|
|
|
* T_ID - identifier
|
2009-04-05 17:11:17 +00:00
|
|
|
* T_STATEMENT_SEPARATOR - ;
|
|
|
|
* T_SQUARE_BRACKETS - [ or ]
|
2008-08-31 05:56:49 +00:00
|
|
|
|
|
|
|
Levels of parsing:
|
2009-04-05 17:11:17 +00:00
|
|
|
* Entry - catches unexpected characters
|
|
|
|
* Semicolon - ;
|
|
|
|
* Set - :=
|
2008-08-31 15:12:55 +00:00
|
|
|
* Conditionls (IF) - if-then-else-end, cond ? a :b
|
2008-08-31 05:56:49 +00:00
|
|
|
* BoolOps (BO) - &, |, ^
|
|
|
|
* CompOps (CO) - ==, !=, ===, !==, >, <, >=, <=
|
|
|
|
* SumRel (SR) - +, -
|
|
|
|
* MulRel (MR) - *, /, %
|
|
|
|
* Pow (P) - **
|
|
|
|
* BoolNeg (BN) - ! operation
|
|
|
|
* SpecialOperators (SO) - in and like
|
|
|
|
* Unarys (U) - plus and minus in cases like -5 or -(2 * +2)
|
2009-04-05 17:11:17 +00:00
|
|
|
* ListElement (LE) - list[number]
|
2008-08-31 05:56:49 +00:00
|
|
|
* Braces (B) - ( and )
|
|
|
|
* Functions (F)
|
|
|
|
* Atom (A) - return value
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AFPToken {
|
2009-10-07 13:57:06 +00:00
|
|
|
// Types of tken
|
2008-08-31 05:56:49 +00:00
|
|
|
const TNone = 'T_NONE';
|
|
|
|
const TID = 'T_ID';
|
|
|
|
const TKeyword = 'T_KEYWORD';
|
|
|
|
const TString = 'T_STRING';
|
|
|
|
const TInt = 'T_INT';
|
|
|
|
const TFloat = 'T_FLOAT';
|
|
|
|
const TOp = 'T_OP';
|
|
|
|
const TBrace = 'T_BRACE';
|
2009-04-05 17:11:17 +00:00
|
|
|
const TSquareBracket = 'T_SQUARE_BRACKET';
|
2008-08-31 05:56:49 +00:00
|
|
|
const TComma = 'T_COMMA';
|
2009-04-01 06:53:18 +00:00
|
|
|
const TStatementSeparator = 'T_STATEMENT_SEPARATOR';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
var $type;
|
|
|
|
var $value;
|
|
|
|
var $pos;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
public function __construct( $type = self::TNone, $value = null, $pos = 0 ) {
|
|
|
|
$this->type = $type;
|
|
|
|
$this->value = $value;
|
|
|
|
$this->pos = $pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AFPData {
|
2010-02-13 14:10:36 +00:00
|
|
|
// Datatypes
|
2008-08-31 05:56:49 +00:00
|
|
|
const DInt = 'int';
|
|
|
|
const DString = 'string';
|
|
|
|
const DNull = 'null';
|
|
|
|
const DBool = 'bool';
|
|
|
|
const DFloat = 'float';
|
2009-04-05 17:11:17 +00:00
|
|
|
const DList = 'list';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
var $type;
|
|
|
|
var $data;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 21:01:29 +00:00
|
|
|
/**
|
|
|
|
* @param string $type
|
|
|
|
* @param null $val
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function __construct( $type = self::DNull, $val = null ) {
|
|
|
|
$this->type = $type;
|
|
|
|
$this->data = $val;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $var
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function newFromPHPVar( $var ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( is_string( $var ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DString, $var );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( is_int( $var ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DInt, $var );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( is_float( $var ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DFloat, $var );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( is_bool( $var ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $var );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( is_array( $var ) ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$result = array();
|
2010-08-19 21:12:09 +00:00
|
|
|
foreach ( $var as $item ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$result[] = self::newFromPHPVar( $item );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DList, $result );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( is_null( $var ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData();
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-02-11 01:41:51 +00:00
|
|
|
throw new AFPException(
|
2010-08-19 21:12:09 +00:00
|
|
|
'Data type ' . gettype( $var ) . ' is not supported by AbuseFilter'
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function dup() {
|
|
|
|
return new AFPData( $this->type, $this->data );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $orig AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @param $target
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function castTypes( $orig, $target ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $orig->type == $target ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return $orig->dup();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DNull ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData();
|
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $orig->type == self::DList ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $target == self::DBool ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DBool, (bool)count( $orig->data ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DFloat ) {
|
2012-03-11 20:40:04 +00:00
|
|
|
return new AFPData( self::DFloat, floatval( count( $orig->data ) ) );
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DInt ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DInt, intval( count( $orig->data ) ) );
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DString ) {
|
2009-05-26 13:08:15 +00:00
|
|
|
$s = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
foreach ( $orig->data as $item ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$s .= $item->toString() . "\n";
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-05-26 13:08:15 +00:00
|
|
|
return new AFPData( self::DString, $s );
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DBool ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, (bool)$orig->data );
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DFloat ) {
|
2012-03-11 20:40:04 +00:00
|
|
|
return new AFPData( self::DFloat, floatval( $orig->data ) );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DInt ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DInt, intval( $orig->data ) );
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DString ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DString, strval( $orig->data ) );
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $target == self::DList ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DList, array( $orig ) );
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $value AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function boolInvert( $value ) {
|
|
|
|
return new AFPData( self::DBool, !$value->toBool() );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $base AFPData
|
|
|
|
* @param $exponent AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function pow( $base, $exponent ) {
|
|
|
|
return new AFPData( self::DFloat, pow( $base->toFloat(), $exponent->toFloat() ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function keywordIn( $a, $b ) {
|
|
|
|
$a = $a->toString();
|
|
|
|
$b = $b->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $a == '' || $b == '' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, false );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, in_string( $a, $b ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function keywordContains( $a, $b ) {
|
|
|
|
$a = $a->toString();
|
|
|
|
$b = $b->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $a == '' || $b == '' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, false );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, in_string( $b, $a ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
* @param $list
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-04-05 17:11:17 +00:00
|
|
|
public static function listContains( $value, $list ) {
|
|
|
|
// Should use built-in PHP function somehow
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $list->data as $item ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( self::equals( $value, $item ) ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return true;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $d1 AFPData
|
|
|
|
* @param $d2 AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2009-04-05 17:11:17 +00:00
|
|
|
public static function equals( $d1, $d2 ) {
|
|
|
|
return $d1->type != self::DList && $d2->type != self::DList &&
|
|
|
|
$d1->toString() === $d2->toString();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $str AFPData
|
|
|
|
* @param $pattern AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function keywordLike( $str, $pattern ) {
|
|
|
|
$str = $str->toString();
|
|
|
|
$pattern = $pattern->toString();
|
|
|
|
wfSuppressWarnings();
|
|
|
|
$result = fnmatch( $pattern, $str );
|
|
|
|
wfRestoreWarnings();
|
|
|
|
return new AFPData( self::DBool, (bool)$result );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $str AFPData
|
|
|
|
* @param $regex AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @param $pos
|
|
|
|
* @param $insensitive bool
|
|
|
|
* @return AFPData
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2010-03-28 00:50:51 +00:00
|
|
|
public static function keywordRegex( $str, $regex, $pos, $insensitive = false ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$str = $str->toString();
|
2011-02-10 17:25:25 +00:00
|
|
|
$pattern = $regex->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 12:43:53 +00:00
|
|
|
$pattern = preg_replace( '!(\\\\\\\\)*(\\\\)?/!', '$1\/', $pattern );
|
2009-03-22 10:34:54 +00:00
|
|
|
$pattern = "/$pattern/u";
|
2010-08-19 21:12:09 +00:00
|
|
|
|
|
|
|
if( $insensitive ) {
|
|
|
|
$pattern .= 'i';
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler = new AFPRegexErrorHandler( $pattern, $pos );
|
2009-06-18 20:13:52 +00:00
|
|
|
try {
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->install();
|
2009-06-18 20:13:52 +00:00
|
|
|
$result = preg_match( $pattern, $str );
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->restore();
|
2010-02-13 14:10:36 +00:00
|
|
|
} catch ( Exception $e ) {
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->restore();
|
2009-06-18 20:13:52 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, (bool)$result );
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $str
|
|
|
|
* @param $regex
|
|
|
|
* @param $pos
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2010-03-28 00:50:51 +00:00
|
|
|
public static function keywordRegexInsensitive( $str, $regex, $pos ) {
|
|
|
|
return self::keywordRegex( $str, $regex, $pos, true );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $data AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function unaryMinus( $data ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $data->type == self::DInt ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
return new AFPData( $data->type, - $data->toInt() );
|
2008-08-31 05:56:49 +00:00
|
|
|
} else {
|
2010-02-13 14:10:36 +00:00
|
|
|
return new AFPData( $data->type, - $data->toFloat() );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
|
|
|
* @param $op string
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function boolOp( $a, $b, $op ) {
|
|
|
|
$a = $a->toBool();
|
|
|
|
$b = $b->toBool();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $op == '|' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a || $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '&' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a && $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '^' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a xor $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-26 23:32:46 +00:00
|
|
|
throw new AFPException( "Invalid boolean operation: {$op}" ); // Should never happen.
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
|
|
|
* @param $op string
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function compareOp( $a, $b, $op ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $op == '==' || $op == '=' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DBool, self::equals( $a, $b ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '!=' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DBool, !self::equals( $a, $b ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '===' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DBool, $a->type == $b->type && self::equals( $a, $b ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '!==' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DBool, $a->type != $b->type || !self::equals( $a, $b ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$a = $a->toString();
|
|
|
|
$b = $b->toString();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $op == '>' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a > $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '<' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a < $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '>=' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a >= $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '<=' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DBool, $a <= $b );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-26 23:32:46 +00:00
|
|
|
throw new AFPException( "Invalid comparison operation: {$op}" ); // Should never happen
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
|
|
|
* @param $op string
|
2012-03-11 20:40:04 +00:00
|
|
|
* @param $pos
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2010-02-13 14:10:36 +00:00
|
|
|
public static function mulRel( $a, $b, $op, $pos ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
// Figure out the type.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $a->type == self::DFloat || $b->type == self::DFloat ||
|
2008-08-31 05:56:49 +00:00
|
|
|
$a->toFloat() != $a->toString() || $b->toFloat() != $b->toString() ) {
|
|
|
|
$type = self::DFloat;
|
|
|
|
$a = $a->toFloat();
|
|
|
|
$b = $b->toFloat();
|
|
|
|
} else {
|
|
|
|
$type = self::DInt;
|
|
|
|
$a = $a->toInt();
|
|
|
|
$b = $b->toInt();
|
|
|
|
}
|
2009-01-25 05:25:33 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $op != '*' && $b == 0 ) {
|
|
|
|
throw new AFPUserVisibleException( 'dividebyzero', $pos, array( $a ) );
|
2009-01-25 05:54:49 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $op == '*' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$data = $a * $b;
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $op == '/' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$data = $a / $b;
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $op == '%' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$data = $a % $b;
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-01-26 23:32:46 +00:00
|
|
|
throw new AFPException( "Invalid multiplication-related operation: {$op}" ); // Should never happen
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $type == self::DInt ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$data = intval( $data );
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2012-03-11 20:40:04 +00:00
|
|
|
$data = floatval( $data );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( $type, $data );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function sum( $a, $b ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $a->type == self::DString || $b->type == self::DString ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DString, $a->toString() . $b->toString() );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $a->type == self::DList && $b->type == self::DList ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( self::DList, array_merge( $a->toList(), $b->toList() ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( self::DFloat, $a->toFloat() + $b->toFloat() );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $a AFPData
|
|
|
|
* @param $b AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public static function sub( $a, $b ) {
|
|
|
|
return new AFPData( self::DFloat, $a->toFloat() - $b->toFloat() );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
/** Convert shorteners */
|
2011-08-24 22:11:52 +00:00
|
|
|
|
2012-02-10 23:41:05 +00:00
|
|
|
/**
|
2012-09-02 11:07:02 +00:00
|
|
|
* @throws MWException
|
2012-02-10 23:41:05 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function toNative() {
|
|
|
|
switch( $this->type ) {
|
|
|
|
case self::DBool:
|
|
|
|
return $this->toBool();
|
|
|
|
case self::DString:
|
|
|
|
return $this->toString();
|
|
|
|
case self::DFloat:
|
|
|
|
return $this->toFloat();
|
|
|
|
case self::DInt:
|
|
|
|
return $this->toInt();
|
|
|
|
case self::DList:
|
|
|
|
$input = $this->toList();
|
|
|
|
$output = array();
|
|
|
|
foreach( $input as $item ) {
|
|
|
|
$output[] = $item->toNative();
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
case self::DNull:
|
|
|
|
return null;
|
|
|
|
default:
|
|
|
|
throw new MWException( "Unknown type" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function toBool() {
|
|
|
|
return self::castTypes( $this, self::DBool )->data;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function toString() {
|
|
|
|
return self::castTypes( $this, self::DString )->data;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* @return float
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function toFloat() {
|
|
|
|
return self::castTypes( $this, self::DFloat )->data;
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function toInt() {
|
|
|
|
return self::castTypes( $this, self::DInt )->data;
|
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
|
|
|
|
public function toList() {
|
|
|
|
return self::castTypes( $this, self::DList )->data;
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 11:47:42 +00:00
|
|
|
class AFPParserState {
|
|
|
|
var $pos, $token, $lastInput;
|
|
|
|
|
|
|
|
public function __construct( $token, $pos ) {
|
|
|
|
$this->token = $token;
|
|
|
|
$this->pos = $pos;
|
|
|
|
$this->lastInput = AbuseFilterParser::$lastHandledToken;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
class AFPException extends MWException { }
|
2009-01-26 23:32:46 +00:00
|
|
|
|
|
|
|
// Exceptions that we might conceivably want to report to ordinary users
|
|
|
|
// (i.e. exceptions that don't represent bugs in the extension itself)
|
|
|
|
class AFPUserVisibleException extends AFPException {
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
|
|
|
* @param string $exception_id
|
|
|
|
* @param int $position
|
|
|
|
* @param array $params
|
|
|
|
*/
|
2009-10-07 13:57:06 +00:00
|
|
|
function __construct( $exception_id, $position, $params ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$msg = wfMessage(
|
|
|
|
'abusefilter-exception-' . $exception_id,
|
|
|
|
array_merge( array( $position ), $params )
|
|
|
|
)->text();
|
2009-01-26 23:32:46 +00:00
|
|
|
parent::__construct( $msg );
|
|
|
|
|
|
|
|
$this->mExceptionID = $exception_id;
|
|
|
|
$this->mPosition = $position;
|
|
|
|
$this->mParams = $params;
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-10-05 23:31:34 +00:00
|
|
|
class AFPRegexErrorHandler {
|
|
|
|
function __construct( $regex, $pos ) {
|
|
|
|
$this->regex = $regex;
|
|
|
|
$this->pos = $pos;
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $errno
|
|
|
|
* @param $errstr
|
|
|
|
* @param $errfile
|
|
|
|
* @param $errline
|
|
|
|
* @param $context
|
|
|
|
* @return bool
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2011-10-05 23:31:34 +00:00
|
|
|
function handleError( $errno, $errstr, $errfile, $errline, $context ) {
|
|
|
|
if ( error_reporting() == 0 ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'regexfailure',
|
|
|
|
$this->pos,
|
|
|
|
array( $errstr, $this->regex )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function install() {
|
|
|
|
set_error_handler( array( $this, 'handleError' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore() {
|
|
|
|
restore_error_handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
class AbuseFilterParser {
|
2012-03-11 20:40:04 +00:00
|
|
|
var $mParams, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort, $mLen;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AbuseFilterVariableHolder
|
|
|
|
*/
|
|
|
|
var $mVars;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
// length,lcase,ccnorm,rmdoubles,specialratio,rmspecials,norm,count
|
|
|
|
static $mFunctions = array(
|
2009-03-07 01:26:42 +00:00
|
|
|
'lcase' => 'funcLc',
|
|
|
|
'length' => 'funcLen',
|
|
|
|
'string' => 'castString',
|
|
|
|
'int' => 'castInt',
|
|
|
|
'float' => 'castFloat',
|
|
|
|
'bool' => 'castBool',
|
|
|
|
'norm' => 'funcNorm',
|
|
|
|
'ccnorm' => 'funcCCNorm',
|
|
|
|
'specialratio' => 'funcSpecialRatio',
|
|
|
|
'rmspecials' => 'funcRMSpecials',
|
|
|
|
'rmdoubles' => 'funcRMDoubles',
|
|
|
|
'rmwhitespace' => 'funcRMWhitespace',
|
|
|
|
'count' => 'funcCount',
|
|
|
|
'rcount' => 'funcRCount',
|
2009-03-09 12:39:52 +00:00
|
|
|
'ip_in_range' => 'funcIPInRange',
|
2009-03-26 02:03:32 +00:00
|
|
|
'contains_any' => 'funcContainsAny',
|
2009-04-01 05:05:23 +00:00
|
|
|
'substr' => 'funcSubstr',
|
|
|
|
'strlen' => 'funcLen',
|
|
|
|
'strpos' => 'funcStrPos',
|
|
|
|
'str_replace' => 'funcStrReplace',
|
2011-10-18 17:57:33 +00:00
|
|
|
'rescape' => 'funcStrRegexEscape',
|
2009-04-01 06:53:18 +00:00
|
|
|
'set' => 'funcSetVar',
|
|
|
|
'set_var' => 'funcSetVar',
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 06:53:18 +00:00
|
|
|
// Functions that affect parser state, and shouldn't be cached.
|
|
|
|
static $ActiveFunctions = array(
|
|
|
|
'funcSetVar',
|
2008-08-31 05:56:49 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
// Order is important. The punctuation-matching regex requires that
|
|
|
|
// ** comes before *, etc. They are sorted to make it easy to spot
|
|
|
|
// such errors.
|
2008-08-31 05:56:49 +00:00
|
|
|
static $mOps = array(
|
2010-08-19 21:12:09 +00:00
|
|
|
'!==', '!=', '!', // Inequality
|
|
|
|
'**', '*', // Multiplication/exponentiation
|
|
|
|
'/', '+', '-', '%', // Other arithmetic
|
|
|
|
'&', '|', '^', // Logic
|
|
|
|
':=', // Setting
|
|
|
|
'?', ':', // Ternery
|
|
|
|
'<=', '<', // Less than
|
|
|
|
'>=', '>', // Greater than
|
|
|
|
'===', '==', '=', // Equality
|
2008-08-31 05:56:49 +00:00
|
|
|
);
|
2010-08-19 21:12:09 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
static $mKeywords = array(
|
2010-08-19 21:12:09 +00:00
|
|
|
'in', 'like', 'true', 'false', 'null', 'contains', 'matches',
|
|
|
|
'rlike', 'irlike', 'regex', 'if', 'then', 'else', 'end',
|
2008-08-31 05:56:49 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
static $parserCache = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
static $funcCache = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 11:47:42 +00:00
|
|
|
static $lastHandledToken = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
public function __construct() {
|
|
|
|
$this->resetState();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
public function resetState() {
|
|
|
|
$this->mParams = array();
|
|
|
|
$this->mCode = '';
|
|
|
|
$this->mTokens = array();
|
2009-02-26 12:15:14 +00:00
|
|
|
$this->mVars = new AbuseFilterVariableHolder;
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->mPos = 0;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = false;
|
|
|
|
$this->mAllowShort = true;
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $filter
|
|
|
|
* @return array|bool
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function checkSyntax( $filter ) {
|
|
|
|
try {
|
2009-03-25 11:48:33 +00:00
|
|
|
$origAS = $this->mAllowShort;
|
|
|
|
$this->mAllowShort = false;
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->parse( $filter );
|
|
|
|
} catch ( AFPUserVisibleException $excep ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mAllowShort = $origAS;
|
2009-10-07 13:57:06 +00:00
|
|
|
return array( $excep->getMessage(), $excep->mPosition );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mAllowShort = $origAS;
|
2008-08-31 05:56:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
* @param $value
|
|
|
|
*/
|
2009-02-26 12:15:14 +00:00
|
|
|
public function setVar( $name, $value ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$name = strtolower( $name );
|
2009-02-26 12:15:14 +00:00
|
|
|
$this->mVars->setVar( $name, $value );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $vars
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function setVars( $vars ) {
|
2009-02-26 12:15:14 +00:00
|
|
|
if ( is_array( $vars ) ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $vars as $name => $var ) {
|
2009-02-26 12:15:14 +00:00
|
|
|
$this->setVar( $name, $var );
|
|
|
|
}
|
|
|
|
} elseif ( $vars instanceof AbuseFilterVariableHolder ) {
|
|
|
|
$this->mVars->addHolder( $vars );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @return AFPToken
|
|
|
|
*/
|
2009-02-11 20:00:33 +00:00
|
|
|
protected function move( ) {
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
list( $val, $type, $code, $offset ) =
|
|
|
|
self::nextToken( $this->mCode, $this->mPos );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:00:33 +00:00
|
|
|
$token = new AFPToken( $type, $val, $this->mPos );
|
|
|
|
$this->mPos = $offset;
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
return $this->mCur = $token;
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-04-05 11:47:42 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* getState() function allows parser state to be rollbacked to several tokens back
|
|
|
|
* @return AFPParserState
|
|
|
|
*/
|
2009-04-05 11:47:42 +00:00
|
|
|
protected function getState() {
|
|
|
|
return new AFPParserState( $this->mCur, $this->mPos );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* setState() function allows parser state to be rollbacked to several tokens back
|
|
|
|
* @param AFPParserState $state
|
|
|
|
*/
|
2009-04-05 11:47:42 +00:00
|
|
|
protected function setState( AFPParserState $state ) {
|
|
|
|
$this->mCur = $state->token;
|
|
|
|
$this->mPos = $state->pos;
|
|
|
|
self::$lastHandledToken = $state->lastInput;
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-03-25 11:48:33 +00:00
|
|
|
protected function skipOverBraces() {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) || !$this->mShortCircuit ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$braces = 1;
|
|
|
|
wfProfileIn( __METHOD__ );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type != AFPToken::TNone && $braces > 0 ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->move();
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TBrace ) {
|
|
|
|
if ( $this->mCur->value == '(' ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$braces++;
|
2010-02-13 14:10:36 +00:00
|
|
|
} elseif ( $this->mCur->value == ')' ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$braces--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wfProfileOut( __METHOD__ );
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == ')' ) )
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, array( ')' ) );
|
2009-03-25 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $code
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function parse( $code ) {
|
|
|
|
return $this->intEval( $code )->toBool();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $filter
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
public function evaluateExpression( $filter ) {
|
|
|
|
return $this->intEval( $filter )->toString();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $code
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
function intEval( $code ) {
|
2009-02-11 20:00:33 +00:00
|
|
|
// Setup, resetting
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->mCode = $code;
|
|
|
|
$this->mPos = 0;
|
2009-02-11 20:00:33 +00:00
|
|
|
$this->mLen = strlen( $code );
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = false;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = new AFPData();
|
|
|
|
$this->doLevelEntry( $result );
|
|
|
|
return $result;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $a
|
|
|
|
* @param $b
|
|
|
|
* @return int
|
|
|
|
*/
|
2009-02-11 01:41:51 +00:00
|
|
|
static function lengthCompare( $a, $b ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( strlen( $a ) == strlen( $b ) ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
return ( strlen( $a ) < strlen( $b ) ) ? - 1 : 1;
|
2009-02-11 01:41:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
/* Levels */
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* Handles unexpected characters after the expression
|
|
|
|
*
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $result AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @throws AFPUserVisibleException
|
2011-08-24 22:11:52 +00:00
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelEntry( &$result ) {
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->doLevelSemicolon( $result );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type != AFPToken::TNone ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'unexpectedatend', $this->mCur->pos, array( $this->mCur->type ) );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* Handles multiple expressions
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $result AFPData
|
2011-08-24 22:11:52 +00:00
|
|
|
*/
|
2009-04-05 11:47:42 +00:00
|
|
|
protected function doLevelSemicolon( &$result ) {
|
2009-04-01 06:53:18 +00:00
|
|
|
do {
|
|
|
|
$this->move();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mCur->type != AFPToken::TStatementSeparator ) {
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->doLevelSet( $result );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
} while ( $this->mCur->type == AFPToken::TStatementSeparator );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* Handles multiple expressions
|
|
|
|
*
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $result AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @throws AFPUserVisibleException
|
2011-08-24 22:11:52 +00:00
|
|
|
*/
|
2009-04-05 11:47:42 +00:00
|
|
|
protected function doLevelSet( &$result ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TID ) {
|
2009-04-05 11:47:42 +00:00
|
|
|
$varname = $this->mCur->value;
|
|
|
|
$prev = $this->getState();
|
|
|
|
$this->move();
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == ':=' ) {
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->move();
|
|
|
|
$this->doLevelSet( $result );
|
|
|
|
$this->setUserVariable( $varname, $result );
|
|
|
|
return;
|
2010-02-13 14:10:36 +00:00
|
|
|
} elseif ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == '[' ) {
|
|
|
|
if ( !$this->mVars->varIsSet( $varname ) ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
throw new AFPUserVisibleException( 'unrecognisedvar',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
2011-02-10 17:32:57 +00:00
|
|
|
array( $varname )
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
|
|
|
$list = $this->mVars->getVar( $varname );
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $list->type != AFPData::DList ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
throw new AFPUserVisibleException( 'notlist', $this->mCur->pos, array() );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
$list = $list->toList();
|
|
|
|
$this->move();
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$idx = 'new';
|
|
|
|
} else {
|
2009-05-22 06:42:10 +00:00
|
|
|
$this->setState( $prev );
|
|
|
|
$this->move();
|
2009-04-05 17:11:17 +00:00
|
|
|
$idx = new AFPData();
|
|
|
|
$this->doLevelSemicolon( $idx );
|
|
|
|
$idx = $idx->toInt();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos,
|
|
|
|
array( ']', $this->mCur->type, $this->mCur->value ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( count( $list ) <= $idx ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
throw new AFPUserVisibleException( 'outofbounds', $this->mCur->pos,
|
|
|
|
array( $idx, count( $result->data ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->move();
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == ':=' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->move();
|
|
|
|
$this->doLevelSet( $result );
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $idx === 'new' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$list[] = $result;
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-04-05 17:11:17 +00:00
|
|
|
$list[$idx] = $result;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->setUserVariable( $varname, new AFPData( AFPData::DList, $list ) );
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$this->setState( $prev );
|
|
|
|
}
|
2009-04-05 11:47:42 +00:00
|
|
|
} else {
|
|
|
|
$this->setState( $prev );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->doLevelConditions( $result );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param $result AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 15:12:55 +00:00
|
|
|
protected function doLevelConditions( &$result ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'if' ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->move();
|
|
|
|
$this->doLevelBoolOps( $result );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'then' ) )
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
'then',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->move();
|
2009-03-18 23:28:35 +00:00
|
|
|
|
2008-08-31 15:12:55 +00:00
|
|
|
$r1 = new AFPData();
|
|
|
|
$r2 = new AFPData();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-18 23:28:35 +00:00
|
|
|
$isTrue = $result->toBool();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$scOrig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelConditions( $r1 );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->mShortCircuit = $scOrig;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'else' ) )
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
'else',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->move();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !$isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$scOrig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelConditions( $r2 );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->mShortCircuit = $scOrig;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'end' ) )
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
'end',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->move();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $result->toBool() ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$result = $r1;
|
|
|
|
} else {
|
|
|
|
$result = $r2;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 15:12:55 +00:00
|
|
|
} else {
|
|
|
|
$this->doLevelBoolOps( $result );
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == '?' ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->move();
|
|
|
|
$r1 = new AFPData();
|
|
|
|
$r2 = new AFPData();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-18 23:28:35 +00:00
|
|
|
$isTrue = $result->toBool();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$scOrig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelConditions( $r1 );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->mShortCircuit = $scOrig;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TOp && $this->mCur->value == ':' ) )
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
':',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->move();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !$isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$scOrig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelConditions( $r2 );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$isTrue ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->mShortCircuit = $scOrig;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $isTrue ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$result = $r1;
|
|
|
|
} else {
|
|
|
|
$result = $r2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $result AFPData
|
2012-03-11 20:40:04 +00:00
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelBoolOps( &$result ) {
|
|
|
|
$this->doLevelCompares( $result );
|
|
|
|
$ops = array( '&', '|', '^' );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TOp && in_array( $this->mCur->value, $ops ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$op = $this->mCur->value;
|
|
|
|
$this->move();
|
|
|
|
$r2 = new AFPData();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-19 00:18:03 +00:00
|
|
|
if ( $op == '&' && !( $result->toBool() ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-shortcircuit' );
|
2009-03-18 23:28:35 +00:00
|
|
|
$orig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->doLevelCompares( $r2 );
|
2009-03-19 00:07:29 +00:00
|
|
|
$this->mShortCircuit = $orig;
|
2009-03-18 23:28:35 +00:00
|
|
|
$result = new AFPData( AFPData::DBool, false );
|
2009-10-07 13:57:06 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-shortcircuit' );
|
2009-03-19 00:18:03 +00:00
|
|
|
continue;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-19 00:18:03 +00:00
|
|
|
if ( $op == '|' && $result->toBool() ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-shortcircuit' );
|
2009-03-18 23:28:35 +00:00
|
|
|
$orig = $this->mShortCircuit;
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->mShortCircuit = $this->mAllowShort;
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->doLevelCompares( $r2 );
|
2009-03-19 00:07:29 +00:00
|
|
|
$this->mShortCircuit = $orig;
|
2009-03-18 23:28:35 +00:00
|
|
|
$result = new AFPData( AFPData::DBool, true );
|
2009-10-07 13:57:06 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-shortcircuit' );
|
2009-03-19 00:18:03 +00:00
|
|
|
continue;
|
2009-03-18 23:28:35 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->doLevelCompares( $r2 );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$result = AFPData::boolOp( $result, $r2, $op );
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelCompares( &$result ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
AbuseFilter::triggerLimiter();
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelSumRels( $result );
|
2008-08-31 05:56:49 +00:00
|
|
|
$ops = array( '==', '===', '!=', '!==', '<', '>', '<=', '>=', '=' );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TOp && in_array( $this->mCur->value, $ops ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$op = $this->mCur->value;
|
|
|
|
$this->move();
|
|
|
|
$r2 = new AFPData();
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelSumRels( $r2 );
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$result = AFPData::compareOp( $result, $r2, $op );
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 15:12:55 +00:00
|
|
|
protected function doLevelSumRels( &$result ) {
|
|
|
|
$this->doLevelMulRels( $result );
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-08-31 15:12:55 +00:00
|
|
|
$ops = array( '+', '-' );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TOp && in_array( $this->mCur->value, $ops ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$op = $this->mCur->value;
|
|
|
|
$this->move();
|
|
|
|
$r2 = new AFPData();
|
2008-08-31 15:12:55 +00:00
|
|
|
$this->doLevelMulRels( $r2 );
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $op == '+' ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$result = AFPData::sum( $result, $r2 );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $op == '-' ) {
|
2008-08-31 15:12:55 +00:00
|
|
|
$result = AFPData::sub( $result, $r2 );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 15:12:55 +00:00
|
|
|
protected function doLevelMulRels( &$result ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->doLevelPow( $result );
|
|
|
|
wfProfileIn( __METHOD__ );
|
2008-08-31 15:12:55 +00:00
|
|
|
$ops = array( '*', '/', '%' );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TOp && in_array( $this->mCur->value, $ops ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$op = $this->mCur->value;
|
|
|
|
$this->move();
|
|
|
|
$r2 = new AFPData();
|
|
|
|
$this->doLevelPow( $r2 );
|
2009-02-11 01:41:51 +00:00
|
|
|
$result = AFPData::mulRel( $result, $r2, $op, $this->mCur->pos );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
2008-08-31 15:12:55 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelPow( &$result ) {
|
|
|
|
$this->doLevelBoolInvert( $result );
|
|
|
|
wfProfileIn( __METHOD__ );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == '**' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->move();
|
|
|
|
$expanent = new AFPData();
|
|
|
|
$this->doLevelBoolInvert( $expanent );
|
|
|
|
$result = AFPData::pow( $result, $expanent );
|
|
|
|
}
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelBoolInvert( &$result ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == '!' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->move();
|
|
|
|
$this->doLevelSpecialWords( $result );
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$result = AFPData::boolInvert( $result );
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
} else {
|
|
|
|
$this->doLevelSpecialWords( $result );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelSpecialWords( &$result ) {
|
|
|
|
$this->doLevelUnarys( $result );
|
2009-10-07 13:57:06 +00:00
|
|
|
$keyword = strtolower( $this->mCur->value );
|
|
|
|
$specwords = array(
|
|
|
|
'in' => 'keywordIn',
|
|
|
|
'like' => 'keywordLike',
|
|
|
|
'matches' => 'keywordLike',
|
|
|
|
'contains' => 'keywordContains',
|
|
|
|
'rlike' => 'keywordRegex',
|
2010-03-28 00:50:51 +00:00
|
|
|
'irlike' => 'keywordRegexInsensitive',
|
2009-10-07 13:57:06 +00:00
|
|
|
'regex' => 'keywordRegex'
|
|
|
|
);
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TKeyword && in_array( $keyword, array_keys( $specwords ) ) ) {
|
2009-01-30 23:46:25 +00:00
|
|
|
$func = $specwords[$keyword];
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->move();
|
|
|
|
$r2 = new AFPData();
|
|
|
|
$this->doLevelUnarys( $r2 );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $this->mShortCircuit ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
return; // The result doesn't matter.
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ . "-$func" );
|
2009-04-01 05:56:24 +00:00
|
|
|
$result = AFPData::$func( $result, $r2, $this->mCur->pos );
|
2009-10-07 13:57:06 +00:00
|
|
|
wfProfileOut( __METHOD__ . "-$func" );
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelUnarys( &$result ) {
|
|
|
|
$op = $this->mCur->value;
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TOp && ( $op == "+" || $op == "-" ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->move();
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->doLevelListElements( $result );
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $op == '-' ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = AFPData::unaryMinus( $result );
|
|
|
|
}
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
} else {
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->doLevelListElements( $result );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-05 17:11:17 +00:00
|
|
|
protected function doLevelListElements( &$result ) {
|
|
|
|
$this->doLevelBraces( $result );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == '[' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$idx = new AFPData();
|
|
|
|
$this->doLevelSemicolon( $idx );
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos,
|
2010-02-13 14:10:36 +00:00
|
|
|
array( ']', $this->mCur->type, $this->mCur->value ) );
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
|
|
|
$idx = $idx->toInt();
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $result->type == AFPData::DList ) {
|
|
|
|
if ( count( $result->data ) <= $idx ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
throw new AFPUserVisibleException( 'outofbounds', $this->mCur->pos,
|
|
|
|
array( $idx, count( $result->data ) ) );
|
|
|
|
}
|
|
|
|
$result = $result->data[$idx];
|
|
|
|
} else {
|
|
|
|
throw new AFPUserVisibleException( 'notlist', $this->mCur->pos, array() );
|
|
|
|
}
|
|
|
|
$this->move();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelBraces( &$result ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) {
|
|
|
|
if ( $this->mShortCircuit ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->skipOverBraces();
|
|
|
|
} else {
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->doLevelSemicolon( $result );
|
2009-03-25 11:48:33 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == ')' ) )
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'expectednotfound',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( ')', $this->mCur->type, $this->mCur->value )
|
|
|
|
);
|
2008-08-31 05:56:49 +00:00
|
|
|
$this->move();
|
|
|
|
} else {
|
|
|
|
$this->doLevelFunction( $result );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelFunction( &$result ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TID && isset( self::$mFunctions[$this->mCur->value] ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$func = self::$mFunctions[$this->mCur->value];
|
|
|
|
$this->move();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mCur->type != AFPToken::TBrace || $this->mCur->value != '(' ) {
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
'(',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-03-25 11:48:33 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mShortCircuit ) {
|
2009-03-25 11:48:33 +00:00
|
|
|
$this->skipOverBraces();
|
|
|
|
$this->move();
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
return; // The result doesn't matter.
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ . '-loadargs' );
|
2008-08-31 05:56:49 +00:00
|
|
|
$args = array();
|
2009-01-23 19:23:19 +00:00
|
|
|
do {
|
|
|
|
$r = new AFPData();
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->doLevelSemicolon( $r );
|
2009-01-23 19:23:19 +00:00
|
|
|
$args[] = $r;
|
2010-02-13 14:10:36 +00:00
|
|
|
} while ( $this->mCur->type == AFPToken::TComma );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->type != AFPToken::TBrace || $this->mCur->value != ')' ) {
|
2009-03-25 11:36:38 +00:00
|
|
|
throw new AFPUserVisibleException( 'expectednotfound',
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
')',
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-03-18 23:28:35 +00:00
|
|
|
$this->move();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-loadargs' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ . "-$func" );
|
|
|
|
|
|
|
|
$funcHash = md5( $func . serialize( $args ) );
|
|
|
|
|
|
|
|
if ( isset( self::$funcCache[$funcHash] ) &&
|
2009-04-01 06:53:18 +00:00
|
|
|
!in_array( $func, self::$ActiveFunctions ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = self::$funcCache[$funcHash];
|
|
|
|
} else {
|
2009-01-23 19:23:19 +00:00
|
|
|
AbuseFilter::triggerLimiter();
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = self::$funcCache[$funcHash] = $this->$func( $args );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( count( self::$funcCache ) > 1000 ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
self::$funcCache = array();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ . "-$func" );
|
2008-08-31 05:56:49 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
} else {
|
|
|
|
$this->doLevelAtom( $result );
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $result
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function doLevelAtom( &$result ) {
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
$tok = $this->mCur->value;
|
|
|
|
switch( $this->mCur->type ) {
|
|
|
|
case AFPToken::TID:
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mShortCircuit ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
break;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$var = strtolower( $tok );
|
2009-02-26 12:15:14 +00:00
|
|
|
$result = $this->getVarValue( $var );
|
2008-08-31 05:56:49 +00:00
|
|
|
break;
|
|
|
|
case AFPToken::TString:
|
|
|
|
$result = new AFPData( AFPData::DString, $tok );
|
|
|
|
break;
|
|
|
|
case AFPToken::TFloat:
|
|
|
|
$result = new AFPData( AFPData::DFloat, $tok );
|
|
|
|
break;
|
|
|
|
case AFPToken::TInt:
|
|
|
|
$result = new AFPData( AFPData::DInt, $tok );
|
|
|
|
break;
|
|
|
|
case AFPToken::TKeyword:
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $tok == "true" ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = new AFPData( AFPData::DBool, true );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $tok == "false" ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = new AFPData( AFPData::DBool, false );
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $tok == "null" ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$result = new AFPData();
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'unrecognisedkeyword',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( $tok )
|
|
|
|
);
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
break;
|
2009-04-01 06:53:18 +00:00
|
|
|
case AFPToken::TNone:
|
|
|
|
return; // Handled at entry level
|
2009-04-05 17:11:17 +00:00
|
|
|
case AFPToken::TBrace:
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mCur->value == ')' ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
return; // Handled at the entry level
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
case AFPToken::TSquareBracket:
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $this->mCur->value == '[' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$list = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
for ( ; ; ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->move();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
break;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
$item = new AFPData();
|
|
|
|
$this->doLevelSet( $item );
|
|
|
|
$list[] = $item;
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
break;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $this->mCur->type != AFPToken::TComma ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'expectednotfound',
|
2009-04-05 17:11:17 +00:00
|
|
|
$this->mCur->pos,
|
2010-08-19 21:12:09 +00:00
|
|
|
array( ', or ]', $this->mCur->type, $this->mCur->value )
|
|
|
|
);
|
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
}
|
|
|
|
$result = new AFPData( AFPData::DList, $list );
|
|
|
|
break;
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
default:
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'unexpectedtoken',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array(
|
|
|
|
$this->mCur->type,
|
|
|
|
$this->mCur->value
|
|
|
|
)
|
|
|
|
);
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
$this->move();
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 11:47:42 +00:00
|
|
|
/* End of levels */
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $var
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-02-26 12:15:14 +00:00
|
|
|
protected function getVarValue( $var ) {
|
2009-03-18 23:28:35 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-02-13 14:10:36 +00:00
|
|
|
$var = strtolower( $var );
|
2009-03-05 02:43:05 +00:00
|
|
|
$builderValues = AbuseFilter::getBuilderValues();
|
2009-04-01 06:53:18 +00:00
|
|
|
if ( !( array_key_exists( $var, $builderValues['vars'] )
|
|
|
|
|| $this->mVars->varIsSet( $var ) ) ) {
|
2009-02-26 12:15:14 +00:00
|
|
|
// If the variable is invalid, throw an exception
|
2009-03-18 23:28:35 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'unrecognisedvar',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( $var )
|
|
|
|
);
|
2009-02-26 12:15:14 +00:00
|
|
|
} else {
|
2009-03-18 23:28:35 +00:00
|
|
|
$val = $this->mVars->getVar( $var );
|
2009-03-19 00:07:29 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-03-18 23:28:35 +00:00
|
|
|
return $val;
|
2009-02-26 12:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 11:47:42 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
* @param $value
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-05 11:47:42 +00:00
|
|
|
protected function setUserVariable( $name, $value ) {
|
|
|
|
$builderValues = AbuseFilter::getBuilderValues();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( array_key_exists( $name, $builderValues['vars'] ) ) {
|
2009-04-05 11:47:42 +00:00
|
|
|
throw new AFPUserVisibleException( 'overridebuiltin', $this->mCur->pos, array( $name ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->mVars->setVar( $name, $value );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $code
|
|
|
|
* @param $offset
|
|
|
|
* @return array
|
|
|
|
* @throws AFPException
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-02-11 01:41:51 +00:00
|
|
|
static function nextToken( $code, $offset ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$tok = '';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Check for infinite loops
|
2009-04-05 11:47:42 +00:00
|
|
|
if ( self::$lastHandledToken == array( $code, $offset ) ) {
|
2009-02-11 20:01:00 +00:00
|
|
|
// Should never happen
|
2009-02-11 20:00:33 +00:00
|
|
|
throw new AFPException( "Entered infinite loop. Offset $offset of $code" );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 11:47:42 +00:00
|
|
|
self::$lastHandledToken = array( $code, $offset );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Spaces
|
|
|
|
$matches = array();
|
2009-03-25 11:36:38 +00:00
|
|
|
if ( preg_match( '/\s+/uA', $code, $matches, 0, $offset ) ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
$offset += strlen( $matches[0] );
|
2009-02-11 20:01:00 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $offset >= strlen( $code ) ) {
|
|
|
|
return array( '', AFPToken::TNone, $code, $offset );
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Comments
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( substr( $code, $offset, 2 ) == '/*' ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$end = strpos( $code, '*/', $offset );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
return self::nextToken( $code, $end + 2 );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Commas
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $code[$offset] == ',' ) {
|
2009-04-01 06:53:18 +00:00
|
|
|
return array( ',', AFPToken::TComma, $code, $offset + 1 );
|
2009-02-11 01:41:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Braces
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $code[$offset] == '(' or $code[$offset] == ')' ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
return array( $code[$offset], AFPToken::TBrace, $code, $offset + 1 );
|
2009-02-11 20:01:00 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 17:11:17 +00:00
|
|
|
// Square brackets
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $code[$offset] == '[' or $code[$offset] == ']' ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return array( $code[$offset], AFPToken::TSquareBracket, $code, $offset + 1 );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 06:53:18 +00:00
|
|
|
// Semicolons
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $code[$offset] == ';' ) {
|
2009-04-01 06:53:18 +00:00
|
|
|
return array( ';', AFPToken::TStatementSeparator, $code, $offset + 1 );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Strings
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $code[$offset] == '"' || $code[$offset] == "'" ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$type = $code[$offset];
|
|
|
|
$offset++;
|
2009-10-07 13:57:06 +00:00
|
|
|
$strLen = strlen( $code );
|
2010-02-13 14:10:36 +00:00
|
|
|
while ( $offset < $strLen ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $code[$offset] == $type ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$offset++;
|
|
|
|
return array( $tok, AFPToken::TString, $code, $offset );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 18:23:21 +00:00
|
|
|
// Performance: Use a PHP function (implemented in C)
|
2009-10-07 13:57:06 +00:00
|
|
|
// to scan ahead.
|
|
|
|
$addLength = strcspn( $code, $type . "\\", $offset );
|
|
|
|
if ( $addLength ) {
|
2009-02-11 18:23:21 +00:00
|
|
|
$tok .= substr( $code, $offset, $addLength );
|
|
|
|
$offset += $addLength;
|
2010-02-13 14:10:36 +00:00
|
|
|
} elseif ( $code[$offset] == '\\' ) {
|
2009-03-25 11:36:38 +00:00
|
|
|
switch( $code[$offset + 1] ) {
|
|
|
|
case '\\':
|
|
|
|
$tok .= '\\';
|
|
|
|
break;
|
|
|
|
case $type:
|
|
|
|
$tok .= $type;
|
|
|
|
break;
|
|
|
|
case 'n';
|
|
|
|
$tok .= "\n";
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
$tok .= "\r";
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
$tok .= "\t";
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
$chr = substr( $code, $offset + 2, 2 );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 11:36:38 +00:00
|
|
|
if ( preg_match( '/^[0-9A-Fa-f]{2}$/', $chr ) ) {
|
|
|
|
$chr = base_convert( $chr, 16, 10 );
|
2009-10-07 13:57:06 +00:00
|
|
|
$tok .= chr( $chr );
|
2009-03-25 11:36:38 +00:00
|
|
|
$offset += 2; # \xXX -- 2 done later
|
|
|
|
} else {
|
|
|
|
$tok .= 'x';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$tok .= "\\" . $code[$offset + 1];
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$offset += 2;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
} else {
|
2009-02-11 01:41:51 +00:00
|
|
|
$tok .= $code[$offset];
|
|
|
|
$offset++;
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-29 15:14:44 +00:00
|
|
|
throw new AFPUserVisibleException( 'unclosedstring', $offset, array() );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Find operators
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
static $operator_regex = null;
|
|
|
|
// Match using a regex. Regexes are faster than PHP
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$operator_regex ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$quoted_operators = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
foreach ( self::$mOps as $op ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$quoted_operators[] = preg_quote( $op, '/' );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$operator_regex = '/(' . implode( '|', $quoted_operators ) . ')/A';
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
$matches = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 11:36:38 +00:00
|
|
|
preg_match( $operator_regex, $code, $matches, 0, $offset );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( count( $matches ) ) {
|
2009-03-25 11:36:38 +00:00
|
|
|
$tok = $matches[0];
|
2009-02-11 20:01:00 +00:00
|
|
|
$offset += strlen( $tok );
|
|
|
|
return array( $tok, AFPToken::TOp, $code, $offset );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Find bare numbers
|
2009-10-07 13:57:06 +00:00
|
|
|
$bases = array(
|
|
|
|
'b' => 2,
|
|
|
|
'x' => 16,
|
|
|
|
'o' => 8
|
|
|
|
);
|
2009-02-11 01:41:51 +00:00
|
|
|
$baseChars = array(
|
2009-10-07 13:57:06 +00:00
|
|
|
2 => '[01]',
|
|
|
|
16 => '[0-9A-Fa-f]',
|
|
|
|
8 => '[0-8]',
|
|
|
|
10 => '[0-9.]',
|
|
|
|
);
|
|
|
|
$baseClass = '[' . implode( '', array_keys( $bases ) ) . ']';
|
2009-03-26 01:30:05 +00:00
|
|
|
$radixRegex = "/([0-9A-Fa-f]+(?:\.\d*)?|\.\d+)($baseClass)?/Au";
|
2009-02-11 01:41:51 +00:00
|
|
|
$matches = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 11:36:38 +00:00
|
|
|
if ( preg_match( $radixRegex, $code, $matches, 0, $offset ) ) {
|
|
|
|
$input = $matches[1];
|
|
|
|
$baseChar = @$matches[2];
|
2009-02-11 01:41:51 +00:00
|
|
|
// Sometimes the base char gets mixed in with the rest of it because
|
2009-10-07 13:57:06 +00:00
|
|
|
// the regex targets hex, too.
|
|
|
|
// This mostly happens with binary
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !$baseChar && !empty( $bases[ substr( $input, - 1 ) ] ) ) {
|
|
|
|
$baseChar = substr( $input, - 1, 1 );
|
|
|
|
$input = substr( $input, 0, - 1 );
|
2009-02-11 01:41:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $baseChar ) {
|
2009-02-11 01:41:51 +00:00
|
|
|
$base = $bases[$baseChar];
|
|
|
|
} else {
|
|
|
|
$base = 10;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
// Check against the appropriate character class for input validation
|
2009-10-07 13:57:06 +00:00
|
|
|
$baseRegex = "/^" . $baseChars[$base] . "+$/";
|
2009-02-11 01:41:51 +00:00
|
|
|
|
|
|
|
if ( preg_match( $baseRegex, $input ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $base != 10 ) {
|
2009-02-11 20:01:00 +00:00
|
|
|
$num = base_convert( $input, $base, 10 );
|
2009-02-11 01:41:51 +00:00
|
|
|
} else {
|
|
|
|
$num = $input;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 11:36:38 +00:00
|
|
|
$offset += strlen( $matches[0] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
$float = in_string( '.', $input );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
return array(
|
|
|
|
$float
|
2012-03-11 20:40:04 +00:00
|
|
|
? floatval( $num )
|
2009-02-11 01:41:51 +00:00
|
|
|
: intval( $num ),
|
|
|
|
$float
|
|
|
|
? AFPToken::TFloat
|
|
|
|
: AFPToken::TInt,
|
|
|
|
$code,
|
|
|
|
$offset
|
|
|
|
);
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// The rest are considered IDs
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
// Regex match > PHP
|
2009-03-25 11:36:38 +00:00
|
|
|
$idSymbolRegex = '/[0-9A-Za-z_]+/A';
|
2009-02-11 20:01:00 +00:00
|
|
|
$matches = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-25 11:36:38 +00:00
|
|
|
if ( preg_match( $idSymbolRegex, $code, $matches, 0, $offset ) ) {
|
|
|
|
$tok = $matches[0];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 20:01:00 +00:00
|
|
|
$type = in_array( $tok, self::$mKeywords )
|
|
|
|
? AFPToken::TKeyword
|
|
|
|
: AFPToken::TID;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
return array( $tok, $type, $code, $offset + strlen( $tok ) );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'unrecognisedtoken', $offset, array( substr( $code, $offset ) ) );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
// Built-in functions
|
2012-03-11 20:40:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcLc( $args ) {
|
|
|
|
global $wgContLang;
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'lc', 2, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
|
|
|
return new AFPData( AFPData::DString, $wgContLang->lc( $s ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcLen( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'len', 2, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
|
|
|
return new AFPData( AFPData::DInt, mb_strlen( $s, 'utf-8' ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcSimpleNorm( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'simplenorm', 2, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = preg_replace( '/[\d\W]+/', '', $s );
|
2011-02-10 17:25:25 +00:00
|
|
|
$s = strtolower( $s );
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcSpecialRatio( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'specialratio', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !strlen( $s ) ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DFloat, 0 );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$nospecials = $this->rmspecials( $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$val = 1. - ( ( mb_strlen( $nospecials ) / mb_strlen( $s ) ) );
|
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DFloat, $val );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcCount( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'count', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $args[0]->type == AFPData::DList && count( $args ) == 1 ) {
|
2009-04-05 17:11:17 +00:00
|
|
|
return new AFPData( AFPData::DInt, count( $args[0]->data ) );
|
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$offset = - 1;
|
2009-04-05 17:11:17 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( count( $args ) == 1 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
$count = count( explode( ',', $args[0]->toString() ) );
|
2008-08-31 05:56:49 +00:00
|
|
|
} else {
|
|
|
|
$needle = $args[0]->toString();
|
|
|
|
$haystack = $args[1]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$count = 0;
|
2009-10-07 13:57:06 +00:00
|
|
|
while ( ( $offset = strpos( $haystack, $needle, $offset + 1 ) ) !== false ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DInt, $count );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2009-03-07 01:26:42 +00:00
|
|
|
protected function funcRCount( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'rcount', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( count( $args ) == 1 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
$count = count( explode( ',', $args[0]->toString() ) );
|
2009-03-07 01:26:42 +00:00
|
|
|
} else {
|
2011-02-10 17:25:25 +00:00
|
|
|
$needle = $args[0]->toString();
|
2009-03-07 01:26:42 +00:00
|
|
|
$haystack = $args[1]->toString();
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
# Munge the regex
|
2009-03-25 12:43:53 +00:00
|
|
|
$needle = preg_replace( '!(\\\\\\\\)*(\\\\)?/!', '$1\/', $needle );
|
2009-03-22 10:31:26 +00:00
|
|
|
$needle = "/$needle/u";
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-07 01:26:42 +00:00
|
|
|
$matches = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler = new AFPRegexErrorHandler( $needle, $this->mCur->pos );
|
2009-06-18 20:13:52 +00:00
|
|
|
try {
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->install();
|
2009-06-18 20:13:52 +00:00
|
|
|
$count = preg_match_all( $needle, $haystack, $matches );
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->restore();
|
2010-02-13 14:10:36 +00:00
|
|
|
} catch ( Exception $e ) {
|
2011-10-05 23:31:34 +00:00
|
|
|
$handler->restore();
|
2009-06-18 20:13:52 +00:00
|
|
|
throw $e;
|
|
|
|
}
|
2009-03-07 01:26:42 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-07 01:26:42 +00:00
|
|
|
return new AFPData( AFPData::DInt, $count );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-03-09 12:39:52 +00:00
|
|
|
protected function funcIPInRange( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 2 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'ip_in_range', 2, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-09 12:39:52 +00:00
|
|
|
$ip = $args[0]->toString();
|
|
|
|
$range = $args[1]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-09 12:39:52 +00:00
|
|
|
$result = IP::isInRange( $ip, $range );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-09 12:39:52 +00:00
|
|
|
return new AFPData( AFPData::DBool, $result );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcCCNorm( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'ccnorm', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$s = html_entity_decode( $s, ENT_QUOTES, 'UTF-8' );
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $this->ccnorm( $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
2012-03-11 21:01:29 +00:00
|
|
|
* @param $args array
|
2012-03-11 20:40:04 +00:00
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-03-26 02:03:32 +00:00
|
|
|
protected function funcContainsAny( $args ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $args ) < 2 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'contains_any', 2, count( $args ) )
|
|
|
|
);
|
2009-03-26 02:03:32 +00:00
|
|
|
}
|
2009-04-05 17:11:17 +00:00
|
|
|
|
2009-03-26 02:03:32 +00:00
|
|
|
$s = array_shift( $args );
|
|
|
|
$s = $s->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-26 02:03:32 +00:00
|
|
|
$searchStrings = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $args as $arg ) {
|
2009-03-26 02:03:32 +00:00
|
|
|
$searchStrings[] = $arg->toString();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-26 02:03:32 +00:00
|
|
|
if ( function_exists( 'fss_prep_search' ) ) {
|
|
|
|
$fss = fss_prep_search( $searchStrings );
|
|
|
|
$result = fss_exec_search( $fss, $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$ok = is_array( $result );
|
2009-03-26 02:03:32 +00:00
|
|
|
} else {
|
|
|
|
$ok = false;
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $searchStrings as $needle ) {
|
|
|
|
if ( in_string( $needle, $s ) ) {
|
2009-03-26 02:03:32 +00:00
|
|
|
$ok = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-26 02:03:32 +00:00
|
|
|
return new AFPData( AFPData::DBool, $ok );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $s
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function ccnorm( $s ) {
|
2009-04-23 03:37:51 +00:00
|
|
|
static $equivset = null;
|
2009-05-26 13:08:15 +00:00
|
|
|
static $replacementArray = null;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
if ( is_null( $equivset ) || is_null( $replacementArray ) ) {
|
2009-04-23 03:37:51 +00:00
|
|
|
global $IP;
|
2011-12-26 19:22:47 +00:00
|
|
|
require_once( "$IP/extensions/AntiSpoof/equivset.php" );
|
2009-05-26 13:08:15 +00:00
|
|
|
$replacementArray = new ReplacementArray( $equivset );
|
2009-04-23 03:37:51 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
return $replacementArray->replace( $s );
|
2010-02-13 14:10:36 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $s string
|
|
|
|
* @return array|string
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function rmspecials( $s ) {
|
2012-03-11 20:40:04 +00:00
|
|
|
return preg_replace( '/[^\p{L}\p{N}]/u', '', $s );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $s string
|
|
|
|
* @return array|string
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function rmdoubles( $s ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
return preg_replace( '/(.)\1+/us', '\1', $s );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $s string
|
|
|
|
* @return array|string
|
|
|
|
*/
|
2009-02-18 19:42:01 +00:00
|
|
|
protected function rmwhitespace( $s ) {
|
|
|
|
return preg_replace( '/\s+/u', '', $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcRMSpecials( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'rmspecials', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $this->rmspecials( $s );
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-02-18 19:42:01 +00:00
|
|
|
protected function funcRMWhitespace( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'rmwhitespace', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2009-02-18 19:42:01 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-18 19:42:01 +00:00
|
|
|
$s = $this->rmwhitespace( $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-18 19:42:01 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcRMDoubles( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'rmdoubles', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $this->rmdoubles( $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function funcNorm( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'norm', 1, count( $args ) )
|
|
|
|
);
|
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $args[0]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$s = $this->ccnorm( $s );
|
2008-08-31 05:56:49 +00:00
|
|
|
$s = $this->rmdoubles( $s );
|
2008-09-22 14:03:45 +00:00
|
|
|
$s = $this->rmspecials( $s );
|
2009-02-18 19:42:01 +00:00
|
|
|
$s = $this->rmwhitespace( $s );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
return new AFPData( AFPData::DString, $s );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-01 05:05:23 +00:00
|
|
|
protected function funcSubstr( $args ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $args ) < 2 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'substr', 2, count( $args ) )
|
|
|
|
);
|
2009-04-01 05:05:23 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
$s = $args[0]->toString();
|
|
|
|
$offset = $args[1]->toInt();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( isset( $args[2] ) ) {
|
2009-04-01 05:05:23 +00:00
|
|
|
$length = $args[2]->toInt();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-31 11:26:30 +00:00
|
|
|
$result = mb_substr( $s, $offset, $length );
|
2009-04-01 05:05:23 +00:00
|
|
|
} else {
|
2009-07-31 11:26:30 +00:00
|
|
|
$result = mb_substr( $s, $offset );
|
2009-04-01 05:05:23 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
return new AFPData( AFPData::DString, $result );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-01 05:05:23 +00:00
|
|
|
protected function funcStrPos( $args ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $args ) < 2 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'strpos', 2, count( $args ) )
|
|
|
|
);
|
2009-04-01 05:05:23 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
$haystack = $args[0]->toString();
|
|
|
|
$needle = $args[1]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( isset( $args[2] ) ) {
|
2009-04-01 05:05:23 +00:00
|
|
|
$offset = $args[2]->toInt();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-31 11:26:30 +00:00
|
|
|
$result = mb_strpos( $haystack, $needle, $offset );
|
2009-04-01 05:05:23 +00:00
|
|
|
} else {
|
2009-07-31 11:26:30 +00:00
|
|
|
$result = mb_strpos( $haystack, $needle );
|
2009-04-01 05:05:23 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $result === false )
|
2010-02-13 14:10:36 +00:00
|
|
|
$result = - 1;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
return new AFPData( AFPData::DInt, $result );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-01 05:05:23 +00:00
|
|
|
protected function funcStrReplace( $args ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $args ) < 3 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'str_replace', 3, count( $args ) )
|
|
|
|
);
|
2009-04-01 05:05:23 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
$subject = $args[0]->toString();
|
|
|
|
$search = $args[1]->toString();
|
|
|
|
$replace = $args[2]->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 05:05:23 +00:00
|
|
|
return new AFPData( AFPData::DString, str_replace( $search, $replace, $subject ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2011-10-18 17:57:33 +00:00
|
|
|
protected function funcStrRegexEscape( $args ) {
|
|
|
|
if ( count( $args ) < 1 ) {
|
|
|
|
throw new AFPUserVisibleException( 'notenoughargs', $this->mCur->pos,
|
|
|
|
array( 'rescape', 1, count( $args ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$string = $args[0]->toString();
|
|
|
|
|
2011-10-19 18:57:36 +00:00
|
|
|
// preg_quote does not need the second parameter, since rlike takes care of the delimiter symbol itself
|
2011-10-18 17:57:33 +00:00
|
|
|
return new AFPData( AFPData::DString, preg_quote( $string ) );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return mixed
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2009-04-01 06:53:18 +00:00
|
|
|
protected function funcSetVar( $args ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $args ) < 2 ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
throw new AFPUserVisibleException(
|
|
|
|
'notenoughargs',
|
|
|
|
$this->mCur->pos,
|
|
|
|
array( 'set_var', 2, count( $args ) )
|
|
|
|
);
|
2009-04-01 06:53:18 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 06:53:18 +00:00
|
|
|
$varName = $args[0]->toString();
|
|
|
|
$value = $args[1];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 11:47:42 +00:00
|
|
|
$this->setUserVariable( $varName, $value );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 06:53:18 +00:00
|
|
|
return $value;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function castString( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$val = $args[0];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 17:11:17 +00:00
|
|
|
return AFPData::castTypes( $val, AFPData::DString );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function castInt( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$val = $args[0];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 17:11:17 +00:00
|
|
|
return AFPData::castTypes( $val, AFPData::DInt );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function castFloat( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$val = $args[0];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 17:11:17 +00:00
|
|
|
return AFPData::castTypes( $val, AFPData::DFloat );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $args array
|
|
|
|
* @return AFPData
|
|
|
|
* @throws AFPUserVisibleException
|
|
|
|
*/
|
2008-08-31 05:56:49 +00:00
|
|
|
protected function castBool( $args ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( count( $args ) < 1 ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2008-08-31 05:56:49 +00:00
|
|
|
$val = $args[0];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 17:11:17 +00:00
|
|
|
return AFPData::castTypes( $val, AFPData::DBool );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|