Skip to content

Commit

Permalink
Switch to extension registration mechanism (#438)
Browse files Browse the repository at this point in the history
* Update SemanticResultFormats.php
* Update install-semantic-result-formats.sh
* Create extension.json
  • Loading branch information
kghbln committed Oct 10, 2018
1 parent 9772726 commit 11f4a67
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 56 deletions.
68 changes: 13 additions & 55 deletions SemanticResultFormats.php
Expand Up @@ -5,14 +5,6 @@
*
* @defgroup SRF Semantic Result Formats
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is part of the Semantic Result Formats extension, it is not a valid entry point.' );
}

if ( defined( 'SRF_VERSION' ) ) {
// Do not initialize more than once.
return 1;
}

SemanticResultFormats::load();

Expand All @@ -36,43 +28,15 @@ public static function load() {

// Load DefaultSettings
require_once __DIR__ . '/DefaultSettings.php';

// In case extension.json is being used, the succeeding steps are
// expected to be handled by the ExtensionRegistry aka extension.json
self::initExtension();

$GLOBALS['wgExtensionFunctions'][] = function() {
self::onExtensionFunction();
};
}

/**
* @since 2.5
*/
public static function initExtension() {

define( 'SRF_VERSION', '3.0.0-alpha' );

// Register the extension
$GLOBALS['wgExtensionCredits']['semantic'][] = [
'path' => __FILE__,
'name' => 'Semantic Result Formats',
'version' => SRF_VERSION,
// At least 14 people have contributed formats to this extension, so
// it would be prohibitive to list them all in the credits. Instead,
// the current rule is to list anyone who has created, or contributed
// significantly to, at least three formats, or the overall extension.
'author' => [
'James Hong Kong',
'Stephan Gambke',
'Jeroen De Dauw',
'Yaron Koren',
'...'
],
'url' => 'https://www.semantic-mediawiki.org/wiki/Semantic_Result_Formats',
'descriptionmsg' => 'srf-desc',
'license-name' => 'GPL-2.0-or-later'
];
// See https://phabricator.wikimedia.org/T151136
define( 'SRF_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );

// Register message files
$GLOBALS['wgMessagesDirs']['SemanticResultFormats'] = __DIR__ . '/i18n';
Expand Down Expand Up @@ -116,26 +80,20 @@ public static function registerHooks() {
/**
* @since 2.5
*/
public static function doCheckRequirements() {

if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) {
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticResultFormats/">Semantic Result Formats</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/SemanticResultFormats/">Semantic Result Formats</a> requires the <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> extension. Please enable or install the extension first.' );
}
}

/**
* @since 2.5
*/
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::doCheckRequirements();
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
die( "\nThe 'Semantic Result Formats' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
} else {
die(
'<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticResultFormats/">Semantic Result Formats</a> ' .
'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' .
'installed and enabled.<br />'
);
}
}

// Admin Links hook needs to be called in a delayed way so that it
// will always be called after SMW's Admin Links addition; as of
Expand Down
2 changes: 1 addition & 1 deletion build/travis/install-semantic-result-formats.sh
Expand Up @@ -57,7 +57,7 @@ function updateConfiguration {
# SMW#1732
echo 'wfLoadExtension( "SemanticMediaWiki" );' >> LocalSettings.php

echo 'require_once( __DIR__ . "/extensions/SemanticResultFormats/SemanticResultFormats.php" );' >> LocalSettings.php
echo 'wfLoadExtension( "SemanticResultFormats" );' >> LocalSettings.php

echo 'error_reporting(E_ALL| E_STRICT);' >> LocalSettings.php
echo 'ini_set("display_errors", 1);' >> LocalSettings.php
Expand Down
30 changes: 30 additions & 0 deletions extension.json
@@ -0,0 +1,30 @@
{
"name": "SemanticResultFormats",
"version": "3.0.0-alpha",
"author": [
"James Hong Kong",
"Stephan Gambke",
"Jeroen De Dauw",
"Yaron Koren",
"..."
],
"url": "https://www.semantic-mediawiki.org/wiki/Semantic_Result_Formats",
"descriptionmsg": "srf-desc",
"namemsg": "srf-name",
"license-name": "GPL-2.0-or-later",
"type": "semantic",
"requires": {
"MediaWiki": ">= 1.27"
},
"MessagesDirs": {
"SemanticResultFormats": [
"i18n"
]
},
"callback": "SemanticResultFormats::initExtension",
"ExtensionFunctions": [
"SemanticResultFormats::onExtensionFunction"
],
"load_composer_autoloader":true,
"manifest_version": 1
}

0 comments on commit 11f4a67

Please sign in to comment.