From ace2aa84544f16de0007e2b3a6359ff9fa479ddf Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 4 Jun 2026 14:35:00 -0400 Subject: [PATCH] Move extension registration into extension.json Replace the procedural registration in the root SemanticMetaTags.php entry point with native extension.json declarations: - Move the five smtg* settings defaults from DefaultSettings.php into the extension.json `config` section with `config_prefix: smtg`; the global names and default values are unchanged. Delete DefaultSettings.php. - Move the extension function into a namespaced SMT\Setup class and point ExtensionFunctions at SMT\Setup::onExtensionFunction. Drop the !defined( 'SMW_VERSION' ) die guard, which is unreachable now that requires.extensions.SemanticMediaWiki gates loading. - Remove the callback, AutoloadClasses, the dead doCheckRequirements() method, and the SMT_VERSION constant. The messages directory is already declared via MessagesDirs. - Read the version from extension.json in tests/bootstrap.php instead of the removed SMT_VERSION constant. - Guard I18nJsonFileIntegrityTest against wgMessagesDirs now resolving to an array (the manifest value) rather than the string the removed procedural assignment used to set. Delete the root SemanticMetaTags.php entry-point class. --- DefaultSettings.php | 46 --------- RELEASE-NOTES.md | 1 + SemanticMetaTags.php | 93 ------------------- extension.json | 34 ++++++- src/Setup.php | 35 +++++++ tests/bootstrap.php | 8 +- .../Integration/I18nJsonFileIntegrityTest.php | 4 + 7 files changed, 72 insertions(+), 149 deletions(-) delete mode 100644 DefaultSettings.php delete mode 100644 SemanticMetaTags.php create mode 100644 src/Setup.php diff --git a/DefaultSettings.php b/DefaultSettings.php deleted file mode 100644 index 7cd9466..0000000 --- a/DefaultSettings.php +++ /dev/null @@ -1,46 +0,0 @@ - array( 'Has keywords', ... ) - */ -$GLOBALS['smtgTagsProperties'] = $GLOBALS['smtgTagsProperties'] ?? []; - -/** - * Describes static content for an assigned `` tag - * - * 'some:tag' => 'Content that is static' - */ -$GLOBALS['smtgTagsStrings'] = $GLOBALS['smtgTagsStrings'] ?? []; - -/** - * Listed tags are generally assumed to be reserved or excluded for free use - */ -$GLOBALS['smtgTagsBlacklist'] = $GLOBALS['smtgTagsBlacklist'] ?? [ - 'generator', - 'robots' -]; - -/** - * In case it is set `true` then the first property that returns a valid content - * for an assigned tag will be used exclusively. - */ -$GLOBALS['smtgTagsPropertyFallbackUsage'] = $GLOBALS['smtgTagsPropertyFallbackUsage'] ?? false; - -/** - * Identifies prefixes that require `meta:property:...` - */ -$GLOBALS['smtgMetaPropertyPrefixes'] = $GLOBALS['smtgMetaPropertyPrefixes'] ?? [ 'og:' ]; diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 41e5358..769e104 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -7,6 +7,7 @@ This file contains the RELEASE-NOTES of the **Semantic Meta Tags** (a.k.a. SMT) * Semantic MediaWiki to version 7.0 and later * MediaWiki to version 1.43 and later * Updated to Semantic MediaWiki 7.0's namespaced data-item classes +* Moved the extension registration and settings defaults into `extension.json` (the `$smtg…` configuration variable names are unchanged) * The major version jumps from 4.x to 7.0 to track the Semantic MediaWiki release it supports ### 4.1.1 diff --git a/SemanticMetaTags.php b/SemanticMetaTags.php deleted file mode 100644 index d230559..0000000 --- a/SemanticMetaTags.php +++ /dev/null @@ -1,93 +0,0 @@ -Error: This version of SemanticMetaTags is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); - } - } - - /** - * @since 1.0 - */ - public static function onExtensionFunction() { - if ( !defined( 'SMW_VERSION' ) ) { - - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { - die( "\nThe 'Semantic Meta Tags' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); - } else { - die( - 'Error: The Semantic Meta Tags ' . - 'extension requires Semantic MediaWiki to be ' . - 'installed and enabled.
' - ); - } - } - - $configuration = [ - 'metaTagsContentPropertySelector' => $GLOBALS['smtgTagsProperties'], - 'metaTagsStaticContentDescriptor' => $GLOBALS['smtgTagsStrings'], - 'metaTagsBlacklist' => $GLOBALS['smtgTagsBlacklist'], - 'metaTagsFallbackUseForMultipleProperties' => $GLOBALS['smtgTagsPropertyFallbackUsage'], - 'metaTagsMetaPropertyPrefixes' => $GLOBALS['smtgMetaPropertyPrefixes'] - ]; - - $hookRegistry = new HookRegistry( - ApplicationFactory::getInstance()->getStore(), - new Options( $configuration ) - ); - - $hookRegistry->register(); - } - -} diff --git a/extension.json b/extension.json index a6d3fcc..2d3a94c 100644 --- a/extension.json +++ b/extension.json @@ -20,19 +20,43 @@ "i18n" ] }, - "callback": "SemanticMetaTags::initExtension", "ExtensionFunctions": [ - "SemanticMetaTags::onExtensionFunction" + "SMT\\Setup::onExtensionFunction" ], - "AutoloadClasses": { - "SemanticMetaTags": "SemanticMetaTags.php" - }, "AutoloadNamespaces": { "SMT\\": "src/" }, "TestAutoloadNamespaces": { "SMT\\Tests\\": "tests/phpunit/" }, + "config_prefix": "smtg", + "config": { + "TagsProperties": { + "value": [], + "description": "An array of tags that assigns related properties such as `'keywords' => [ 'Has keywords', ... ]`." + }, + "TagsStrings": { + "value": [], + "description": "Describes static content for an assigned `` tag such as `'some:tag' => 'Content that is static'`." + }, + "TagsBlacklist": { + "value": [ + "generator", + "robots" + ], + "description": "Listed tags are generally assumed to be reserved or excluded for free use." + }, + "TagsPropertyFallbackUsage": { + "value": false, + "description": "In case it is set `true` then the first property that returns a valid content for an assigned tag will be used exclusively." + }, + "MetaPropertyPrefixes": { + "value": [ + "og:" + ], + "description": "Identifies prefixes that require `meta:property:...`." + } + }, "load_composer_autoloader": true, "manifest_version": 2 } diff --git a/src/Setup.php b/src/Setup.php new file mode 100644 index 0000000..8d71961 --- /dev/null +++ b/src/Setup.php @@ -0,0 +1,35 @@ + $GLOBALS['smtgTagsProperties'], + 'metaTagsStaticContentDescriptor' => $GLOBALS['smtgTagsStrings'], + 'metaTagsBlacklist' => $GLOBALS['smtgTagsBlacklist'], + 'metaTagsFallbackUseForMultipleProperties' => $GLOBALS['smtgTagsPropertyFallbackUsage'], + 'metaTagsMetaPropertyPrefixes' => $GLOBALS['smtgMetaPropertyPrefixes'] + ]; + + $hookRegistry = new HookRegistry( + ApplicationFactory::getInstance()->getStore(), + new Options( $configuration ) + ); + + $hookRegistry->register(); + } + +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ba7aa74..b85d848 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,17 +12,15 @@ die( "\nThe Semantic MediaWiki test autoloader is not available" ); } -if ( !defined( 'SMT_VERSION' ) ) { - die( "\nSemantic Meta Tags is not available, please check your Composer or LocalSettings.php.\n" ); -} - $width = 20; if ( !defined( 'SMW_PHPUNIT_FIRST_COLUMN_WIDTH' ) ) { define( 'SMW_PHPUNIT_FIRST_COLUMN_WIDTH', $width ); } -print sprintf( "\n%-{$width}s%s\n", "Semantic Meta Tags: ", SMT_VERSION ); +$extensionInfo = json_decode( file_get_contents( __DIR__ . '/../extension.json' ), true ); + +print sprintf( "\n%-{$width}s%s\n", "Semantic Meta Tags: ", $extensionInfo['version'] ?? 'UNKNOWN' ); $autoLoader = require SMW_PHPUNIT_AUTOLOADER_FILE; $autoloader->addPsr4( 'SMT\\Tests\\', __DIR__ . '/phpunit/Unit' ); diff --git a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php index fc9c175..6bf0dfd 100644 --- a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php +++ b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php @@ -38,6 +38,10 @@ public function i18nFileProvider() { $provider = []; $location = $GLOBALS['wgMessagesDirs']['SemanticMetaTags']; + if ( is_array( $location ) ) { + $location = $location[0]; + } + $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location ); $bulkFileProvider->searchByFileExtension( 'json' );