Skip to content

Commit

Permalink
Switch to extension registration mechanism (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghbln authored and mwjames committed Jan 26, 2019
1 parent 78608af commit 88ccec7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
20 changes: 14 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
77 changes: 16 additions & 61 deletions SemanticCompoundQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' );
}
public static function onExtensionFunction() {

if ( !defined( 'SMW_VERSION' ) ) {
die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticCompoundQueries/">Semantic Compound Queries</a> requires the <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> 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(
'<b>Error:</b> The <a href="https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Compound_Queries">Semantic Compound Queries</a> ' .
'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' .
'installed and enabled.<br />'
);
}
}

// wgAPIModules
$GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery';

// wgHooks
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$parser->setFunctionHook( 'compound_query', [ '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ] );

Expand Down
28 changes: 28 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 4 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 3 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
5 changes: 5 additions & 0 deletions tests/travis/install-semantic-compound-queries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88ccec7

Please sign in to comment.