From 88ccec70fea516b2dd3bc4f3b5b91c614c2ccec2 Mon Sep 17 00:00:00 2001 From: Karsten Hoffmeyer Date: Sat, 26 Jan 2019 20:28:30 +0100 Subject: [PATCH] Switch to extension registration mechanism (#39) --- .travis.yml | 20 +++-- SemanticCompoundQueries.php | 77 ++++--------------- extension.json | 28 +++++++ i18n/en.json | 6 +- i18n/qqq.json | 4 +- .../install-semantic-compound-queries.sh | 5 ++ 6 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 extension.json diff --git a/.travis.yml b/.travis.yml index f7fbda6..144d7d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,22 @@ -# http://docs.travis-ci.com/user/workers/container-based-infrastructure/ -sudo: false - language: php matrix: + fast_finish: true include: - - env: DB=mysql; MW=master; SMW=2.5.2 - php: 7 - - env: DB=mysql; MW=REL1_27; + - env: DB=mysql; MW=master; SMW=~3.1@dev + php: 7.3 + - env: DB=mysql; MW=REL1_31; SMW=~3.0@dev; PHPUNIT=5.7.* + php: 7.0 + - env: DB=mysql; MW=REL1_27; SMW=~3.0@dev; PHPUNIT=4.8.* php: 5.6 + - env: DB=mysql; MW=REL1_28; SMW=~3.0@dev; TYPE=coverage + php: 7.0 + - env: DB=sqlite; MW=REL1_29; SMW=~3.0@dev; PHPUNIT=4.8.* + php: 7.1 + - env: DB=postgres; MW=REL1_30; SMW=~3.0@dev; PHPUNIT=5.7.* + php: 7.2 + allow_failures: + - env: DB=mysql; MW=master; SMW=~3.1@dev install: - travis_retry composer self-update diff --git a/SemanticCompoundQueries.php b/SemanticCompoundQueries.php index cc999c8..78e2624 100644 --- a/SemanticCompoundQueries.php +++ b/SemanticCompoundQueries.php @@ -5,14 +5,6 @@ * * @defgroup SemanticCompoundQueries SemanticCompoundQueries */ -if ( !defined( 'MEDIAWIKI' ) ) { - die( 'This file is part of the Semantic Compound Queries extension, it is not a valid entry point.' ); -} - -if ( defined( 'SCQ_VERSION' ) ) { - // Do not initialize more than once. - return 1; -} SemanticCompoundQueries::load(); @@ -33,81 +25,44 @@ public static function load() { if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { include_once __DIR__ . '/vendor/autoload.php'; } - - /** - * In case extension.json is being used, the succeeding steps are - * expected to be handled by the ExtensionRegistry aka extension.json - * ... - * - * "callback": "SemanticCompoundQueries::initExtension", - * "ExtensionFunctions": [ - * "SemanticCompoundQueries::onExtensionFunction" - * ], - */ - self::initExtension(); - - $GLOBALS['wgExtensionFunctions'][] = function() { - self::onExtensionFunction(); - }; } /** * @since 1.1 */ - public static function initExtension() { - - define( 'SCQ_VERSION', '2.0.0-alpha' ); - - // Register the extension - $GLOBALS['wgExtensionCredits']['semantic'][] = [ - 'path' => __FILE__, - 'name' => 'Semantic Compound Queries', - 'version' => SCQ_VERSION, - 'author' => [ - '[https://www.semantic-mediawiki.org/ Semantic MediaWiki project]', - 'Yaron Koren' - ], - 'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries', - 'descriptionmsg' => 'semanticcompoundqueries-desc', - 'license-name' => 'GPL-2.0-or-later' - ]; + public static function initExtension( $credits = [] ) { + + // See https://phabricator.wikimedia.org/T151136 + define( 'SCQ_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' ); // Register message files $GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n'; $GLOBALS['wgExtensionMessagesFiles']['SemanticCompoundQueriesMagic'] = __DIR__ . '/i18n/SemanticCompoundQueries.i18n.magic.php'; - //$GLOBALS['wgAutoloadClasses']['SCQQueryProcessor'] = __DIR__ . '/SCQ_QueryProcessor.php'; - //$GLOBALS['wgAutoloadClasses']['SCQQueryResult'] = __DIR__ . '/SCQ_QueryResult.php'; - //$GLOBALS['wgAutoloadClasses']['SCQCompoundQueryApi'] = __DIR__ . '/SCQ_CompoundQueryApi.php'; } /** * @since 1.1 */ - public static function checkRequirements() { - - if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { - die( 'Error: This version of Semantic Compound Queries is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); - } + public static function onExtensionFunction() { if ( !defined( 'SMW_VERSION' ) ) { - die( 'Error: Semantic Compound Queries requires the Semantic MediaWiki extension. Please enable or install the extension first.' ); - } - } - - /** - * @since 1.1 - */ - public static function onExtensionFunction() { - // Check requirements after LocalSetting.php has been processed, thid has - // be done here to ensure SMW is loaded in case - // wfLoadExtension( 'SemanticMediaWiki' ) is used - self::checkRequirements(); + if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { + die( "\nThe 'Semantic Compound Queries' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); + } else { + die( + 'Error: The Semantic Compound Queries ' . + 'extension requires Semantic MediaWiki to be ' . + 'installed and enabled.
' + ); + } + } // wgAPIModules $GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery'; + // wgHooks $GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) { $parser->setFunctionHook( 'compound_query', [ '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ] ); diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..c40f349 --- /dev/null +++ b/extension.json @@ -0,0 +1,28 @@ +{ + "name": "SemanticCompoundQueries", + "version": "2.0.0-alpha", + "author": [ + "James Hong Kong", + "Yaron Koren", + "..." + ], + "url": "https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Compound_Queries", + "descriptionmsg": "semanticcompoundqueries-desc", + "namemsg": "semanticcompoundqueries-name", + "license-name": "GPL-2.0-or-later", + "type": "semantic", + "requires": { + "MediaWiki": ">= 1.27" + }, + "MessagesDirs": { + "SemanticCompoundQueries": [ + "i18n" + ] + }, + "callback": "SemanticCompoundQueries::initExtension", + "ExtensionFunctions": [ + "SemanticCompoundQueries::onExtensionFunction" + ], + "load_composer_autoloader":true, + "manifest_version": 1 +} diff --git a/i18n/en.json b/i18n/en.json index 9998d3e..65ed35e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1,8 +1,10 @@ { "@metadata": { "authors": [ - "Yaron Koren" + "Yaron Koren", + "Karsten Hoffmeyer" ] }, - "semanticcompoundqueries-desc": "A parser function that displays multiple semantic queries at the same time" + "semanticcompoundqueries-desc": "A parser function that displays multiple semantic queries at the same time", + "semanticcompoundqueries-name": "Semantic Compound Queries" } diff --git a/i18n/qqq.json b/i18n/qqq.json index b9a7535..d334388 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -2,10 +2,12 @@ "@metadata": { "authors": [ "Fryed-peach", + "Kghbln", "Purodha", "Shirayuki", "Umherirrender" ] }, - "semanticcompoundqueries-desc": "{{desc|name=Semantic Compound Queries|url=https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries}}" + "semanticcompoundqueries-desc": "{{desc|name=Semantic Compound Queries|url=https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries}}", + "semanticcompoundqueries-name": "Name of the extension. {{Notranslate}}" } diff --git a/tests/travis/install-semantic-compound-queries.sh b/tests/travis/install-semantic-compound-queries.sh index b8e10b1..0fdcd90 100644 --- a/tests/travis/install-semantic-compound-queries.sh +++ b/tests/travis/install-semantic-compound-queries.sh @@ -56,6 +56,11 @@ function updateConfiguration { cd $MW_INSTALL_PATH + # SMW#1732 + echo 'wfLoadExtension( "SemanticMediaWiki" );' >> LocalSettings.php + + echo 'wfLoadExtension( "SemanticCompoundQueries" );' >> LocalSettings.php + # Site language if [ "$SITELANG" != "" ] then