Page MenuHomePhabricator

ifnumber.patch

Authored By
bzimport
Nov 21 2014, 10:10 PM
Size
2 KB
Referenced Files
None
Subscribers
None

ifnumber.patch

Index: ParserFunctions.i18n.magic.php
===================================================================
--- ParserFunctions.i18n.magic.php (Revision 34765)
+++ ParserFunctions.i18n.magic.php (Arbeitskopie)
@@ -18,6 +18,7 @@
'ifeq' => array( 0, 'ifeq' ),
'ifexpr' => array( 0, 'ifexpr' ),
'iferror' => array( 0, 'iferror' ),
+ 'ifnumber' => array( 0, 'ifnumber' ),
'switch' => array( 0, 'switch' ),
'default' => array( 0, '#default' ),
'ifexist' => array( 0, 'ifexist' ),
Index: ParserFunctions.php
===================================================================
--- ParserFunctions.php (Revision 34765)
+++ ParserFunctions.php (Arbeitskopie)
@@ -32,6 +32,7 @@
$parser->setFunctionHook( 'ifexist', array( &$this, 'ifexistObj' ), SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'ifexpr', array( &$this, 'ifexprObj' ), SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'iferror', array( &$this, 'iferrorObj' ), SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'ifnumber', array( &$this, 'ifNumberObj' ), SFH_OBJECT_ARGS );
} else {
$parser->setFunctionHook( 'if', array( &$this, 'ifHook' ) );
$parser->setFunctionHook( 'ifeq', array( &$this, 'ifeq' ) );
@@ -39,6 +40,7 @@
$parser->setFunctionHook( 'ifexist', array( &$this, 'ifexist' ) );
$parser->setFunctionHook( 'ifexpr', array( &$this, 'ifexpr' ) );
$parser->setFunctionHook( 'iferror', array( &$this, 'iferror' ) );
+ $parser->setFunctionHook( 'ifnumber', array( &$this, 'ifnumber' ) );
}
$parser->setFunctionHook( 'expr', array( &$this, 'expr' ) );
@@ -154,6 +156,23 @@
}
}
+ function ifNumber( &$parser, $test = '', $then = '', $else = '' ) {
+ if ( is_numeric( $test )) {
+ return $then;
+ } else {
+ return $else;
+ }
+ }
+
+ function ifNumberObj( &$parser, $frame, $args ) {
+ $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
+ if ( is_numeric( $test )) {
+ return isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
+ } else {
+ return isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : '';
+ }
+ }
+
function switchHook( &$parser /*,...*/ ) {
$args = func_get_args();
array_shift( $args );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4451
Default Alt Text
ifnumber.patch (2 KB)

Event Timeline