Pastakhov has submitted this change and it was merged.
Change subject: Update to master version 3.8 (v 3.8.0.27) requere PhpTags >= 5.9
......................................................................
Update to master version 3.8 (v 3.8.0.27) requere PhpTags >= 5.9
* Fix dump functions (v 3.8) requere PhpTags >= 5.9
* Add extension.json file and move setup instructions to it (v 3.7.1)
Change-Id: I0190262085b32a51c08d044cb4cbaab2625003af
---
M PhpTagsFunctions.hooks.php
M PhpTagsFunctions.json
M PhpTagsFunctions.php
A extension.json
M i18n/ko.json
M includes/PhpTagsFunc.php
M includes/PhpTagsFuncUseful.php
M tests/phpunit/PhpTagsFunctions_DateTime_Test.php
M tests/phpunit/PhpTagsFunctions_Useful_Test.php
M tests/phpunit/PhpTagsFunctions_Var_Test.php
10 files changed, 110 insertions(+), 75 deletions(-)
Approvals:
Pastakhov: Verified; Looks good to me, approved
diff --git a/PhpTagsFunctions.hooks.php b/PhpTagsFunctions.hooks.php
index c927053..3214585 100644
--- a/PhpTagsFunctions.hooks.php
+++ b/PhpTagsFunctions.hooks.php
@@ -12,18 +12,24 @@
class PhpTagsFunctionsHooks {
/**
- *
+ * Check on version compatibility
* @return boolean
*/
public static function onParserFirstCallInit() {
- if ( !defined( 'PHPTAGS_VERSION' ) ) {
+ $extRegistry = ExtensionRegistry::getInstance();
+ $phpTagsLoaded = $extRegistry->isLoaded( 'PhpTags' );
+ //if ( !$extRegistry->isLoaded( 'PhpTags' ) ) { use
PHPTAGS_VERSION for backward compatibility
+ if ( !($phpTagsLoaded || defined( 'PHPTAGS_VERSION' )) ) {
throw new MWException( "\n\nYou need to have the
PhpTags extension installed in order to use the PhpTags Functions extension." );
}
- $needVersion = '5.6.0';
- if ( version_compare( PHPTAGS_VERSION, $needVersion, '<' ) ) {
- throw new MWException( "\n\nThis version of the PhpTags
Functions extension requires the PhpTags extension $needVersion or above.\n You
have " . PHPTAGS_VERSION . ". Please update it." );
+ if ( $phpTagsLoaded ) {
+ $neededVersion = '5.9';
+ $phpTagsVersion =
$extRegistry->getAllThings()['PhpTags']['version'];
+ if ( version_compare( $phpTagsVersion, $neededVersion,
'<' ) ) {
+ throw new MWException( "\n\nThis version of the
PhpTags Functions extension requires the PhpTags extension $neededVersion or
above.\n You have $phpTagsVersion. Please update it." );
+ }
}
- if ( PHPTAGS_HOOK_RELEASE != 8 ) {
+ if ( !$phpTagsLoaded || PHPTAGS_HOOK_RELEASE != 8 ) {
throw new MWException( "\n\nThis version of the PhpTags
Functions extension is outdated and not compatible with current version of the
PhpTags extension.\n Please update it." );
}
return true;
@@ -34,7 +40,8 @@
* @return boolean
*/
public static function onPhpTagsRuntimeFirstInit() {
- \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsFunctions.json', PHPTAGS_FUNCTIONS_VERSION . PHP_VERSION );
+ $version =
ExtensionRegistry::getInstance()->getAllThings()['PhpTags
Functions']['version'];
+ \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsFunctions.json', $version . PHP_VERSION );
return true;
}
diff --git a/PhpTagsFunctions.json b/PhpTagsFunctions.json
index c367881..9747afd 100644
--- a/PhpTagsFunctions.json
+++ b/PhpTagsFunctions.json
@@ -2970,6 +2970,7 @@
"constants": {
"PHPTAGS_FUNCTIONS_VERSION": {
"desc": "The current version of the PhpTags Functions
extension as a string",
+ "class": "PhpTagsFuncUseful",
"type": "string",
"link": "mw://Extension:PhpTags_Functions"
},
diff --git a/PhpTagsFunctions.php b/PhpTagsFunctions.php
index 048ab6e..86f0a29 100644
--- a/PhpTagsFunctions.php
+++ b/PhpTagsFunctions.php
@@ -1,47 +1,14 @@
<?php
-/**
- * Main entry point for the PhpTags Functions extension.
- *
- * @link https://www.mediawiki.org/wiki/Extension:PhpTags_Functions
Documentation
- * @file PhpTagsFunctions.php
- * @defgroup PhpTags
- * @ingroup Extensions
- * @author Pavel Astakhov <[email protected]>
- * @licence GNU General Public Licence 2.0 or later
- */
-
-// Check to see if we are being called as an extension or directly
-if ( !defined('MEDIAWIKI') ) {
- die( 'This file is an extension to MediaWiki and thus not a valid entry
point.' );
+if ( function_exists( 'wfLoadExtension' ) ) {
+ wfLoadExtension( 'PhpTagsFunctions' );
+ // Keep i18n globals so mergeMessageFileList.php doesn't break
+ $wgMessagesDirs['PhpTagsFunctions'] = __DIR__ . '/i18n';
+// wfWarn(
+// 'Deprecated PHP entry point used for PhpTags Functions
extension. ' .
+// 'Please use wfLoadExtension instead, ' .
+// 'see https://www.mediawiki.org/wiki/Extension_registration for
more details.'
+// );
+ return;
+} else {
+ die( 'This version of the PhpTags Functions extension requires
MediaWiki 1.25+' );
}
-
-const PHPTAGS_FUNCTIONS_VERSION = '3.7.0';
-
-// Register this extension on Special:Version
-$wgExtensionCredits['phptags'][] = array(
- 'path' => __FILE__,
- 'name' => 'PhpTags Functions',
- 'version' => PHPTAGS_FUNCTIONS_VERSION,
- 'url' =>
'https://www.mediawiki.org/wiki/Extension:PhpTags_Functions',
- 'author' =>
'[https://www.mediawiki.org/wiki/User:Pastakhov Pavel Astakhov]',
- 'descriptionmsg' => 'phptagsfunctions-desc'
-);
-
-// Allow translations for this extension
-$wgMessagesDirs['PhpTagsFunctions'] = __DIR__ . '/i18n';
-
-//
-$wgHooks['ParserFirstCallInit'][] =
'PhpTagsFunctionsHooks::onParserFirstCallInit';
-$wgHooks['PhpTagsRuntimeFirstInit'][] =
'PhpTagsFunctionsHooks::onPhpTagsRuntimeFirstInit';
-$wgHooks['UnitTestsList'][] = 'PhpTagsFunctionsHooks::onUnitTestsList';
-
-// Preparing classes for autoloading
-$wgAutoloadClasses['PhpTagsFunctionsHooks'] = __DIR__ .
'/PhpTagsFunctions.hooks.php';
-$wgAutoloadClasses['PhpTagsObjects\\PhpTagsFunc'] = __DIR__ .
'/includes/PhpTagsFunc.php';
-$wgAutoloadClasses['PhpTagsObjects\\PhpTagsFuncUseful'] = __DIR__ .
'/includes/PhpTagsFuncUseful.php';
-$wgAutoloadClasses['PhpTagsObjects\\PhpTagsFuncNativeObject'] = __DIR__ .
'/includes/PhpTagsFuncNativeObject.php';
-$wgAutoloadClasses['PhpTagsObjects\\PhpTagsFuncDatePeriod'] = __DIR__ .
'/includes/PhpTagsFuncDatePeriod.php';
-$wgAutoloadClasses['PhpTagsObjects\\PhpTagsWebRequest'] = __DIR__ .
'/includes/PhpTagsWebRequest.php';
-
-// add parser tests
-$wgParserTestFiles[] = __DIR__ . '/tests/parser/PhpTagsFunctionsTests.txt';
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..d7abb2c
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,31 @@
+{
+ "name": "PhpTags Functions",
+ "version": "3.8.0.27",
+ "author": "[https://www.mediawiki.org/wiki/User:Pastakhov Pavel
Astakhov]",
+ "url": "https://www.mediawiki.org/wiki/Extension:PhpTags_Functions",
+ "descriptionmsg": "phptagsfunctions-desc",
+ "license-name": "GPL-2.0+",
+ "type": "phptags",
+ "MessagesDirs": {
+ "PhpTagsFunctions": [
+ "i18n"
+ ]
+ },
+ "AutoloadClasses": {
+ "PhpTagsFunctionsHooks": "PhpTagsFunctions.hooks.php",
+ "PhpTagsObjects\\PhpTagsFunc": "includes/PhpTagsFunc.php",
+ "PhpTagsObjects\\PhpTagsFuncUseful":
"includes/PhpTagsFuncUseful.php",
+ "PhpTagsObjects\\PhpTagsFuncNativeObject":
"includes/PhpTagsFuncNativeObject.php",
+ "PhpTagsObjects\\PhpTagsFuncDatePeriod":
"includes/PhpTagsFuncDatePeriod.php",
+ "PhpTagsObjects\\PhpTagsWebRequest":
"includes/PhpTagsWebRequest.php"
+ },
+ "Hooks": {
+ "ParserFirstCallInit":
"PhpTagsFunctionsHooks::onParserFirstCallInit",
+ "PhpTagsRuntimeFirstInit":
"PhpTagsFunctionsHooks::onPhpTagsRuntimeFirstInit",
+ "UnitTestsList": "PhpTagsFunctionsHooks::onUnitTestsList"
+ },
+ "ParserTestFiles": [
+ "tests/parser/PhpTagsFunctionsTests.txt"
+ ],
+ "manifest_version": 1
+}
diff --git a/i18n/ko.json b/i18n/ko.json
index 1be3b82..802ccab 100644
--- a/i18n/ko.json
+++ b/i18n/ko.json
@@ -1,11 +1,12 @@
{
"@metadata": {
"authors": [
- "Priviet"
+ "Priviet",
+ "Ykhwong"
]
},
"phptagsfunctions-desc": "확장 PhpTags를 위한 native PHP 내부 함수를 구현",
- "phptagsfunctions-preg-bad-delimiter": "구분 기호는 알파벳, 숫자, 백슬래시가 아니여야 합니다",
+ "phptagsfunctions-preg-bad-delimiter": "구분 기호는 영숫자나 백슬래시가 아니어야 합니다",
"phptagsfunctions-preg-no-ending-delimiter": "\"$1\" 끝 구분 기호를 찾을 수
없습니다",
"phptagsfunctions-preg-unknown-modifier": "알 수 없는 수식어 \"$1\""
}
diff --git a/includes/PhpTagsFunc.php b/includes/PhpTagsFunc.php
index 6a6b7cd..83478ef 100644
--- a/includes/PhpTagsFunc.php
+++ b/includes/PhpTagsFunc.php
@@ -96,45 +96,59 @@
}
public static function f_printf() {
- $arguments = func_get_args();
- $ret = call_user_func_array( 'sprintf', $arguments );
+ $args = func_get_args();
+ $v = array();
+ foreach ( $args as $value => $key ) {
+ $v[$key] = self::getValidDumpValue( $value );
+ }
+ $ret = call_user_func_array( 'sprintf', $v );
return new \PhpTags\outPrint( strlen($ret), $ret, false, false
);
}
public static function f_vprintf() {
- $arguments = func_get_args();
- $ret = call_user_func_array( 'vsprintf', $arguments );
+ $args = func_get_args();
+ $v = array();
+ foreach ( $args as $value => $key ) {
+ $v[$key] = self::getValidDumpValue( $value );
+ }
+ $ret = call_user_func_array( 'vsprintf', $v );
return new \PhpTags\outPrint( strlen($ret), $ret, false, false
);
}
public static function f_var_export( $expression, $return = false ) {
- if ( $expression instanceof \PhpTags\GenericObject ) {
- $expression = $expression->getValue();
- }
- $ret = var_export( $expression, true );
+ $v = self::getValidDumpValue( $expression );
+ $ret = var_export( $v, true );
return $return ? $ret : new \PhpTags\outPrint( null, $ret );
}
public static function f_var_dump() {
$args = func_get_args();
- foreach ( $args as &$value ) {
- if ( $value instanceof \PhpTags\GenericObject ) {
- $value = $value->getValue();
- }
+ $v = array();
+ foreach ( $args as $value => $key ) {
+ $v[$key] = self::getValidDumpValue( $value );
}
ob_start();
- call_user_func_array( 'var_dump', $args );
+ call_user_func_array( 'var_dump', $v );
return new \PhpTags\outPrint( null, ob_get_clean() );
}
public static function f_print_r( $expression, $return = false ) {
- if ( $expression instanceof \PhpTags\GenericObject ) {
- $expression = $expression->getValue();
- }
- $ret = print_r( $expression, true );
+ $v = self::getValidDumpValue( $expression );
+ $ret = print_r( $v, true );
return $return ? $ret : new \PhpTags\outPrint( true, $ret );
}
+ private static function getValidDumpValue( $expression ) {
+ if ( is_object( $expression ) ) {
+ if ( $expression instanceof \PhpTags\GenericObject ) {
+ return (array)$expression->getDumpValue();
+ } else {
+ throw new PhpTagsException(
PhpTagsException::FATAL_INTERNAL_ERROR );
+ }
+ }
+ return $expression;
+ }
+
/**
* @todo remove it for PHP >= 5.4.0
*/
diff --git a/includes/PhpTagsFuncUseful.php b/includes/PhpTagsFuncUseful.php
index 075090d..3171590 100644
--- a/includes/PhpTagsFuncUseful.php
+++ b/includes/PhpTagsFuncUseful.php
@@ -15,6 +15,8 @@
switch ( $constantName ) {
case 'UUID':
return self::f_uuid_create();
+ case 'PHPTAGS_FUNCTIONS_VERSION':
+ return
\ExtensionRegistry::getInstance()->getAllThings()['PhpTags
Functions']['version'];
}
parent::getConstantValue( $constantName );
}
diff --git a/tests/phpunit/PhpTagsFunctions_DateTime_Test.php
b/tests/phpunit/PhpTagsFunctions_DateTime_Test.php
index 2ed3ece..ddada37 100644
--- a/tests/phpunit/PhpTagsFunctions_DateTime_Test.php
+++ b/tests/phpunit/PhpTagsFunctions_DateTime_Test.php
@@ -93,21 +93,20 @@
public function testRun_DateTime_exception_9() {
$this->assertEquals(
Runtime::runSource('new DateTime() . 5;',
array('Page') ),
- array( (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateTime',
'string'), 1, 'Page' ) )
+ array( (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED,
array('DateTime', 'string'), 1, 'Page' ) )
);
}
public function testRun_DateTime_exception_10() {
$this->assertEquals(
Runtime::runSource('5 . new
DateInterval("P2Y4DT6H8M");', array('Page') ),
- array( (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateInterval',
'string'), 1, 'Page' ) )
+ array( (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED,
array('DateInterval', 'string'), 1, 'Page' ) )
);
}
public function testRun_DateTime_exception_11() {
$this->assertEquals(
Runtime::runSource('new DateTime() . new
DateInterval("P2Y4DT6H8M");', array('Page') ),
array(
- (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateTime',
'string'), 1, 'Page' ),
- (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateInterval',
'string'), 1, 'Page' )
+ (string) new \PhpTags\PhpTagsException(
\PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED,
array('DateTime', 'string'), 1, 'Page' ),
)
);
}
diff --git a/tests/phpunit/PhpTagsFunctions_Useful_Test.php
b/tests/phpunit/PhpTagsFunctions_Useful_Test.php
index 3c65efd..71f68bd 100644
--- a/tests/phpunit/PhpTagsFunctions_Useful_Test.php
+++ b/tests/phpunit/PhpTagsFunctions_Useful_Test.php
@@ -10,6 +10,13 @@
);
}
+ public function testRun_constant_2() {
+ $this->assertEquals(
+ Runtime::runSource('echo
PHPTAGS_FUNCTIONS_VERSION;'),
+ array(
\ExtensionRegistry::getInstance()->getAllThings()['PhpTags
Functions']['version'] )
+ );
+ }
+
public function testRun_uuid_create_1() {
$this->assertEquals(
Runtime::runSource('echo strlen( uuid_create()
);'),
diff --git a/tests/phpunit/PhpTagsFunctions_Var_Test.php
b/tests/phpunit/PhpTagsFunctions_Var_Test.php
index 0b22a66..c63a589 100644
--- a/tests/phpunit/PhpTagsFunctions_Var_Test.php
+++ b/tests/phpunit/PhpTagsFunctions_Var_Test.php
@@ -167,6 +167,12 @@
array('34')
);
}
+ public function testRun_intval_6_1() {
+ $this->assertEquals(
+ Runtime::runSource('echo intval(-042);'),
+ array('-34')
+ );
+ }
public function testRun_intval_7() {
$this->assertEquals(
Runtime::runSource('echo intval("042");'),
--
To view, visit https://gerrit.wikimedia.org/r/304441
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0190262085b32a51c08d044cb4cbaab2625003af
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PhpTagsFunctions
Gerrit-Branch: REL1_27
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits