Skip to content

Commit

Permalink
Support extension.json, SBL 2.0.0 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Sep 30, 2018
1 parent 28790ce commit 69b7b6b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Assigns a styling class to the breadcrumb trail
*/
$GLOBALS['egSBLBreadcrumbTrailStyleClass'] = 'sbl-breadcrumb-trail-light';
$GLOBALS['sblgBreadcrumbTrailStyleClass'] = 'sbl-breadcrumb-trail-light';

/**
* Assigns a divider styling class
Expand Down
59 changes: 22 additions & 37 deletions SemanticBreadcrumbLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,17 @@ public static function load() {

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

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

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

/**
* @since 1.3
*/
public static function initExtension() {
public static function initExtension( $credits = [] ) {

define( 'SBL_VERSION', '1.5.0' );
// See https://phabricator.wikimedia.org/T151136
define( 'SBL_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
define( 'SBL_PROP_PARENTPAGE', 'Has parent page' );

// Register the extension
$GLOBALS['wgExtensionCredits']['semantic'][ ] = [
'path' => __FILE__,
'name' => 'Semantic Breadcrumb Links',
'author' => [ 'James Hong Kong' ],
'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/',
'descriptionmsg' => 'sbl-desc',
'version' => SBL_VERSION,
'license-name' => 'GPL-2.0-or-later',
];

// Register message files
$GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticBreadcrumbLinksMagic'] = __DIR__ . '/i18n/SemanticBreadcrumbLinks.magic.php';
Expand Down Expand Up @@ -102,24 +84,15 @@ public static function initExtension() {
/**
* @since 1.3
*/
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/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> is only compatible with MediaWiki 1.27 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/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>. Please enable or install the extension first.' );
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
die( "\nThe 'Semantic Breadcrumb Links' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
} else {
die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
}
}
}

/**
* @since 1.3
*/
public static function onExtensionFunction() {

// Check requirements after LocalSetting.php has been processed
self::checkRequirements();

// Default values are defined at this point to ensure
// NS contants are specified prior
Expand All @@ -146,9 +119,21 @@ public static function onExtensionFunction() {
]
];

// Cover legacy settings
$deprecationNotices = [];

if ( isset( $GLOBALS['egSBLBreadcrumbTrailStyleClass'] ) ) {
$GLOBALS['sblgBreadcrumbTrailStyleClass'] = $GLOBALS['egSBLBreadcrumbTrailStyleClass'];
$deprecationNotices['replacement']['egSBLBreadcrumbTrailStyleClass'] = 'sblgBreadcrumbTrailStyleClass';
}

if ( $deprecationNotices !== [] && !isset( $GLOBALS['smwgDeprecationNotices']['sbl'] ) ) {
$GLOBALS['smwgDeprecationNotices']['sbl'] = [ 'replacement' => $deprecationNotices['replacement'] ];
}

$configuration = [
'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'],
'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'],
'breadcrumbTrailStyleClass' => $GLOBALS['sblgBreadcrumbTrailStyleClass'],
'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'],
'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'],
'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'],
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"require": {
"php": ">=5.6",
"composer/installers": "1.*,>=1.0.12",
"mediawiki/semantic-media-wiki": "~2.4|~3.0",
"mediawiki/semantic-media-wiki": "~2.5|~3.0",
"onoi/shared-resources":"~0.2"
},
"require-dev": {
"mediawiki/semantic-media-wiki": "@dev"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.0.x-dev"
}
},
"autoload": {
Expand All @@ -51,6 +51,7 @@
"process-timeout": 0
},
"scripts":{
"test": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
}
}
27 changes: 27 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "SemanticBreadcrumbLinks",
"version": "2.0.0-alpha",
"author": [
"James Hong Kong",
"..."
],
"url": "https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/",
"descriptionmsg": "sbl-desc",
"namemsg": "sbl-name",
"license-name": "GPL-2.0-or-later",
"type": "semantic",
"requires": {
"MediaWiki": ">= 1.27"
},
"MessagesDirs": {
"SemanticBreadcrumbLinks": [
"i18n"
]
},
"callback": "SemanticBreadcrumbLinks::initExtension",
"ExtensionFunctions": [
"SemanticBreadcrumbLinks::onExtensionFunction"
],
"load_composer_autoloader":true,
"manifest_version": 1
}
11 changes: 8 additions & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
]
},
"sbl-desc": "A [https://www.semantic-mediawiki.org Semantic MediaWiki] extension to build breadcrumb links from an attributive property filter",
"smw-pa-property-predefined__sbl_parentpage": "\"$1\" is a predefined property that can describe a relationship between a parent and a child entity and is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Breadcrumb_Links Semantic Breadcrumb Links] extension.",
"smw-pa-property-predefined-long__sbl_parentpage": "By identifying the location of an entity relative to its parent it can be used to generate a navigational help in form of a breadcrumb trail.",
"sbl-property-alias-parentpage": "Has parent page"
"sbl-name": "Semantic Breadcrumb Links",
"smw-pa-property-predefined-sbl-parentpage": "\"$1\" is a predefined property that can describe a relationship between a parent and a child entity and is provided by the [https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Breadcrumb_Links Semantic Breadcrumb Links] extension.",
"smw-pa-property-predefined-long-sbl-parentpage": "By identifying the location of an entity relative to its parent it can be used to generate a navigational help in form of a breadcrumb trail.",
"sbl-property-alias-parentpage": "Has parent page",
"sbl-admin-deprecation-notice-section": "Semantic Breadcrumb Links extension",
"sbl-admin-deprecation-notice-title-replacement": "Replaced or renamed settings",
"sbl-admin-deprecation-notice-title-replacement-explanation": "The following section contains settings that were renamed or otherwise modified and it is recommended to forthwith update their name or format.",
"sbl-admin-deprecation-notice-config-replacement": "<code>[https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Breadcrumb_Links/$1 $1]</code> was replaced by <code>[https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Breadcrumb_Links/$2 $2]</code>"
}
3 changes: 2 additions & 1 deletion tests/travis/install-semantic-breadcrumb-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ function updateConfiguration {
echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php
echo "putenv( 'MW_INSTALL_PATH=$(pwd)' );" >> LocalSettings.php

# SMW#1732
echo 'wfLoadExtension( "SemanticMediaWiki" );' >> LocalSettings.php
echo 'wfLoadExtension( "SemanticBreadcrumbLinks" );' >> LocalSettings.php

php maintenance/update.php --quick
}
Expand Down

0 comments on commit 69b7b6b

Please sign in to comment.