jenkins-bot has submitted this change and it was merged.
Change subject: Add extension.json file and move setup instructions to it (v
1.5.2)
......................................................................
Add extension.json file and move setup instructions to it (v 1.5.2)
Change-Id: Ie21213ab75284e446e0b5b11c87ba76d58e1a99f
---
M PhpTagsSMW.hooks.php
M PhpTagsSMW.non-smw.json
M PhpTagsSMW.php
A extension.json
M includes/SMWExtSQI.php
A tests/phpunit/PhpTagsSMW_Test.php
6 files changed, 104 insertions(+), 84 deletions(-)
Approvals:
Pastakhov: Looks good to me, approved
jenkins-bot: Verified
diff --git a/PhpTagsSMW.hooks.php b/PhpTagsSMW.hooks.php
index 50f9482..7a70aa8 100644
--- a/PhpTagsSMW.hooks.php
+++ b/PhpTagsSMW.hooks.php
@@ -11,17 +11,53 @@
final class PhpTagsSMWHooks {
/**
+ * Check on version compatibility
+ * @return boolean
+ */
+ public static function onParserFirstCallInit() {
+ $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 SMW extension." );
+ }
+ if ( $phpTagsLoaded ) {
+ $neededVersion = '5.8.0';
+ $phpTagsVersion =
$extRegistry->getAllThings()['PhpTags']['version'];
+ if ( version_compare( $phpTagsVersion, $neededVersion,
'<' ) ) {
+ throw new MWException( "\n\nThis version of the
PhpTags SMW extension requires the PhpTags extension $neededVersion or above.\n
You have $phpTagsVersion. Please update it." );
+ }
+ }
+ if ( !$phpTagsLoaded || PHPTAGS_HOOK_RELEASE != 8 ) {
+ throw new MWException( "\n\nThis version of the PhpTags
SMW extension is outdated and not compatible with current version of the
PhpTags extension.\n Please update it." );
+ }
+ return true;
+ }
+
+ /**
* Called when the PhpTags runtime initializes for the first time.
*
* Used for initialization of things that are only used when
* PhpTags is.
*/
public static function onPhpTagsRuntimeFirstInit() {
- \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsSMW.non-smw.json' );
+ $version =
ExtensionRegistry::getInstance()->getAllThings()['PhpTags SMW']['version'];
+ \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsSMW.non-smw.json', $version );
if ( defined( 'SMW_VERSION' ) ) {
- \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsSMW.json' );
+ \PhpTags\Hooks::addJsonFile( __DIR__ .
'/PhpTagsSMW.json', $version . SMW_VERSION );
}
return true;
}
+ /**
+ *
+ * @param array $files
+ * @return boolean
+ */
+ public static function onUnitTestsList( &$files ) {
+ $testDir = __DIR__ . '/tests/phpunit';
+ $files = array_merge( $files, glob( "$testDir/*Test.php" ) );
+ return true;
+ }
+
}
diff --git a/PhpTagsSMW.non-smw.json b/PhpTagsSMW.non-smw.json
index 22c32ac..0751638 100644
--- a/PhpTagsSMW.non-smw.json
+++ b/PhpTagsSMW.non-smw.json
@@ -33,6 +33,7 @@
"constants": {
"PHPTAGS_SMW_VERSION": {
"desc": "The current version of the PhpTags SMW
extension as a string",
+ "class": "SMWExtSQI",
"type": "string",
"example": "1.4.0",
"link":
"https://www.mediawiki.org/wiki/Extension:PhpTags_SMW"
diff --git a/PhpTagsSMW.php b/PhpTagsSMW.php
index 6e6ae3b..299f8f1 100644
--- a/PhpTagsSMW.php
+++ b/PhpTagsSMW.php
@@ -1,84 +1,14 @@
<?php
-/**
- * Main entry point for the PhpTags SMW extension.
- *
- * @link https://www.mediawiki.org/wiki/Extension:PhpTags_SMW Documentation
- * @file PhpTagsSMW.php
- * @defgroup PhpTags
- * @ingroup Extensions
- * @author Pavel Astakhov <[email protected]>
- * @author Joel K. Pettersson <[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( 'PhpTagsSMW' );
+ // Keep i18n globals so mergeMessageFileList.php doesn't break
+ $wgMessagesDirs['PhpTagsSMW'] = __DIR__ . '/i18n';
+// wfWarn(
+// 'Deprecated PHP entry point used for PhpTags SMW extension. ' .
+// 'Please use wfLoadExtension instead, ' .
+// 'see https://www.mediawiki.org/wiki/Extension_registration for
more details.'
+// );
+ return;
+} else {
+ die( 'This version of the PhpTags SMW extension requires MediaWiki
1.25+' );
}
-
-const PHPTAGS_SMW_VERSION = '1.5.1';
-
-// Register this extension on Special:Version
-$wgExtensionCredits['phptags'][] = array(
- 'path' => __FILE__,
- 'name' => 'PhpTags SMW',
- 'version' => PHPTAGS_SMW_VERSION,
- 'url' =>
'https://www.mediawiki.org/wiki/Extension:PhpTags_SMW',
- 'author' => array(
'[https://www.mediawiki.org/wiki/User:Pastakhov Pavel Astakhov]',
'[https://www.mediawiki.org/wiki/User:JoelKP Joel K. Pettersson]' ),
- 'descriptionmsg' => 'phptagssmw-desc',
- 'license-name' => 'GPL-2.0+',
-);
-
-// Register message files
-$wgMessagesDirs['PhpTagsSMW'] = __DIR__ . '/i18n';
-
-// Register hooks
-
-/**
- * @codeCoverageIgnore
- */
-$wgHooks['ParserFirstCallInit'][] = function() {
- if ( !defined( 'PHPTAGS_VERSION' ) ) {
- throw new MWException( "\n\nYou need to have the PhpTags extension
installed in order to use the PhpTags SMW extension." );
- }
- $needVersion = '5.1.0';
- if ( version_compare( PHPTAGS_VERSION, $needVersion, '<' ) ) {
- throw new MWException( "\n\nThis version of the PhpTags SMW
extension requires the PhpTags extension $needVersion or above.\n You have " .
PHPTAGS_VERSION . ". Please update it." );
- }
- if ( PHPTAGS_HOOK_RELEASE != 8 ) {
- throw new MWException( "\n\nThis version of the PhpTags SMW
extension is outdated and not compatible with current version of the PhpTags
extension.\n Please update it." );
- }
- return true;
-};
-
-/**
- * @codeCoverageIgnore
- */
-$wgHooks['PhpTagsRuntimeFirstInit'][] =
'PhpTagsSMWHooks::onPhpTagsRuntimeFirstInit';
-
-// Register classes for autoloading
-$wgAutoloadClasses['PhpTagsSMWHooks'] = __DIR__ . '/PhpTagsSMW.hooks.php';
-$wgAutoloadClasses['PhpTagsSMW\\InputConverter'] = __DIR__ .
'/includes/InputConverter.php';
-
-$wgAutoloadClasses['PhpTagsObjects\\SMWExtArrays'] =
- __DIR__ . '/includes/SMWExtArrays.php';
-$wgAutoloadClasses['PhpTagsObjects\\SMWExtSQI'] =
- __DIR__ . '/includes/SMWExtSQI.php';
-$wgAutoloadClasses['PhpTagsObjects\\SMWWSemanticData'] =
- __DIR__ . '/includes/SMWWSemanticData.php';
-$wgAutoloadClasses['PhpTagsObjects\\SMWWSemanticProperty'] =
- __DIR__ . '/includes/SMWWSemanticProperty.php';
-$wgAutoloadClasses['PhpTagsObjects\\SMWWSemanticStats'] =
- __DIR__ . '/includes/SMWWSemanticStats.php';
-
-/**
- * Add files to phpunit test
- * @codeCoverageIgnore
- */
-//$wgHooks['UnitTestsList'][] = function ( &$files ) {
-// $testDir = __DIR__ . '/tests/phpunit';
-// $files = array_merge( $files, glob( "$testDir/*Test.php" ) );
-// return true;
-//};
-//
-//$wgParserTestFiles[] = __DIR__ . '/tests/parser/PhpTagsSMWTests.txt';
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..94b5071
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,32 @@
+{
+ "name": "PhpTags SMW",
+ "version": "1.5.2",
+ "author": [
+ "[https://www.mediawiki.org/wiki/User:Pastakhov Pavel
Astakhov]",
+ "[https://www.mediawiki.org/wiki/User:JoelKP Joel K.
Pettersson]"
+ ],
+ "url": "https://www.mediawiki.org/wiki/Extension:PhpTags_SMW",
+ "descriptionmsg": "phptagssmw-desc",
+ "license-name": "GPL-2.0+",
+ "type": "phptags",
+ "MessagesDirs": {
+ "PhpTagsSMW": [
+ "i18n"
+ ]
+ },
+ "AutoloadClasses": {
+ "PhpTagsSMWHooks": "PhpTagsSMW.hooks.php",
+ "PhpTagsSMW\\InputConverter": "includes/InputConverter.php",
+ "PhpTagsObjects\\SMWExtArrays": "includes/SMWExtArrays.php",
+ "PhpTagsObjects\\SMWExtSQI": "includes/SMWExtSQI.php",
+ "PhpTagsObjects\\SMWWSemanticData":
"includes/SMWWSemanticData.php",
+ "PhpTagsObjects\\SMWWSemanticProperty":
"includes/SMWWSemanticProperty.php",
+ "PhpTagsObjects\\SMWWSemanticStats":
"includes/SMWWSemanticStats.php"
+ },
+ "Hooks": {
+ "ParserFirstCallInit": "PhpTagsSMWHooks::onParserFirstCallInit",
+ "PhpTagsRuntimeFirstInit":
"PhpTagsSMWHooks::onPhpTagsRuntimeFirstInit",
+ "UnitTestsList": "PhpTagsSMWHooks::onUnitTestsList"
+ },
+ "manifest_version": 1
+}
diff --git a/includes/SMWExtSQI.php b/includes/SMWExtSQI.php
index a8450a6..3c7a35b 100644
--- a/includes/SMWExtSQI.php
+++ b/includes/SMWExtSQI.php
@@ -10,6 +10,14 @@
*/
class SMWExtSQI extends \PhpTags\GenericObject {
+ public static function getConstantValue( $constantName ) {
+ switch ( $constantName ) {
+ case 'PHPTAGS_SMW_VERSION':
+ return
\ExtensionRegistry::getInstance()->getAllThings()['PhpTags SMW']['version'];
+ }
+ parent::getConstantValue( $constantName );
+ }
+
public function m___construct( $config = null ) {
if ( false === class_exists( '\\SQI\\SemanticQueryInterface' )
) {
throw new HookException( wfMessage(
'phptagssmw-ext-sqi-not-installed' )->inContentLanguage()->text(),
HookException::EXCEPTION_FATAL );
diff --git a/tests/phpunit/PhpTagsSMW_Test.php
b/tests/phpunit/PhpTagsSMW_Test.php
new file mode 100644
index 0000000..e096dc6
--- /dev/null
+++ b/tests/phpunit/PhpTagsSMW_Test.php
@@ -0,0 +1,13 @@
+<?php
+namespace PhpTags;
+
+class PhpTagsSMW_Test extends \PHPUnit_Framework_TestCase {
+
+ public function testRun_constant_1() {
+ $this->assertEquals(
+ Runtime::runSource('echo PHPTAGS_SMW_VERSION;'),
+ array(
\ExtensionRegistry::getInstance()->getAllThings()['PhpTags SMW']['version'] )
+ );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/301801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie21213ab75284e446e0b5b11c87ba76d58e1a99f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/PhpTagsSMW
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: MtDu <[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