Pastakhov has submitted this change and it was merged.
Change subject: add functions get_arg, get_args, num_args (v 3.4.3)
......................................................................
add functions get_arg, get_args, num_args (v 3.4.3)
Change-Id: I448836d35711cb68f435ab0a95aafbeaad6a3ee1
---
M PhpTagsFunctions.json
M PhpTagsFunctions.php
M includes/PhpTagsFuncUseful.php
M tests/phpunit/PhpTagsFunctions_Useful_Test.php
4 files changed, 70 insertions(+), 1 deletion(-)
Approvals:
Pastakhov: Verified; Looks good to me, approved
diff --git a/PhpTagsFunctions.json b/PhpTagsFunctions.json
index 93606d0..9e74fbe 100644
--- a/PhpTagsFunctions.json
+++ b/PhpTagsFunctions.json
@@ -2931,6 +2931,29 @@
"onfailure": "false",
"return": "string",
"desc": "Returns the JSON representation of a value"
+ },
+ "get_arg": {
+ "class": "PhpTagsFuncUseful",
+ "parameters": [
+ { "type": "nonobject", "name": "index" },
+ { "type": "mixed", "name": "default",
"default": "NULL" }
+ ],
+ "return": "mixed",
+ "desc": "Return an item from the argument list"
+ },
+ "get_args": {
+ "class": "PhpTagsFuncUseful",
+ "parameters": [],
+ "onfailure": "false",
+ "return": "array",
+ "desc": "Returns an array comprising a template's
argument list"
+ },
+ "num_args": {
+ "class": "PhpTagsFuncUseful",
+ "parameters": [],
+ "onfailure": "false",
+ "return": "int",
+ "desc": "Returns the number of arguments passed to the
template"
}
},
"constants": {
diff --git a/PhpTagsFunctions.php b/PhpTagsFunctions.php
index c42a42f..8cf7d30 100644
--- a/PhpTagsFunctions.php
+++ b/PhpTagsFunctions.php
@@ -15,7 +15,7 @@
die( 'This file is an extension to MediaWiki and thus not a valid entry
point.' );
}
-const PHPTAGS_FUNCTIONS_VERSION = '3.4.2';
+const PHPTAGS_FUNCTIONS_VERSION = '3.4.3';
// Register this extension on Special:Version
$wgExtensionCredits['phptags'][] = array(
diff --git a/includes/PhpTagsFuncUseful.php b/includes/PhpTagsFuncUseful.php
index 5626cf5..4bd3e6d 100644
--- a/includes/PhpTagsFuncUseful.php
+++ b/includes/PhpTagsFuncUseful.php
@@ -41,4 +41,25 @@
public static function f_mw_json_encode( $value ) {
return \FormatJson::encode( $value, false, \FormatJson::UTF8_OK
);
}
+
+ public static function f_get_arg( $index, $default = null ) {
+ $args = self::f_get_args();
+ if ( isset( $args[$index] ) || key_exists( $index, $args )) {
+ return $args[$index];
+ }
+ return $default;
+ }
+
+ public static function f_get_args() {
+ $variables = \PhpTags\Runtime::getVariables();
+ $argv = $variables['argv'];
+ array_shift( $argv );
+ return $argv;
+ }
+
+ public static function f_num_args() {
+ $variables = \PhpTags\Runtime::getVariables();
+ return $variables['argc'] - 1;
+ }
+
}
diff --git a/tests/phpunit/PhpTagsFunctions_Useful_Test.php
b/tests/phpunit/PhpTagsFunctions_Useful_Test.php
index 3d690b6..bde3057 100644
--- a/tests/phpunit/PhpTagsFunctions_Useful_Test.php
+++ b/tests/phpunit/PhpTagsFunctions_Useful_Test.php
@@ -31,4 +31,29 @@
);
}
+ public function testRun_get_args_1() {
+ $this->assertEquals(
+ Runtime::runSource( '$tmp = get_args(); echo
$tmp[0], $tmp["foo"];', array( 'TestPage', 'one', 'foo'=>'bar' ) ),
+ array('one', 'bar')
+ );
+ }
+ public function testRun_get_args_2() {
+ $this->assertEquals(
+ Runtime::runSource( 'echo implode( ", ",
get_args() );', array( 'TestPage', 'one', 'foo'=>'bar' ) ),
+ array('one, bar')
+ );
+ }
+ public function testRun_get_arg_1() {
+ $this->assertEquals(
+ Runtime::runSource( 'echo get_arg( 0 ),
get_arg( "foo" ), get_arg( "bar", "not defined" );', array( 'TestPage', 'one',
'foo'=>'bar' ) ),
+ array('one', 'bar', 'not defined')
+ );
+ }
+ public function testRun_num_args_1() {
+ $this->assertEquals(
+ Runtime::runSource( 'echo num_args(), $argc;',
array( 'TestPage', 'one', 'foo'=>'bar' ) ),
+ array('2', '3')
+ );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/208613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I448836d35711cb68f435ab0a95aafbeaad6a3ee1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PhpTagsFunctions
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits