Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/325120
Change subject: WIP: registration: Add possibility to set CONTENT_MODEL_ and CONTENT_FORMAT_ constants ...................................................................... WIP: registration: Add possibility to set CONTENT_MODEL_ and CONTENT_FORMAT_ constants Bug: T108285 Change-Id: Icee5004a64d50b1cc54ad376b599184111609685 --- M docs/extension.schema.json M includes/registration/ExtensionProcessor.php 2 files changed, 66 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/20/325120/1 diff --git a/docs/extension.schema.json b/docs/extension.schema.json index 30feaef..57949db 100644 --- a/docs/extension.schema.json +++ b/docs/extension.schema.json @@ -527,7 +527,26 @@ "description": "Mapping of model ID to class name", "patternProperties": { "^[A-Za-z]+$": { - "type": "string" + "type": [ "string", "object" ], + "properties": { + "handler": { + "type": "string", + "description": "The full qualified class name, which handles the content model." + }, + "model_constant": { + "type": "string", + "description": "The name of the content model constant (without CONTENT_MODEL_).", + "default": "Defaults to a computation of \"CONTENT_MODEL_\" and the key of this object in uppercase letters. E.g. if the key of this object is \"Test\", the constant name would be \"CONTENT_MODEL_TEST\"." + }, + "format_constant": { + "type": "string", + "description": "The name of the content format constant (withhout CONTENT_FORMAT_). If not set, the constant will not be set!" + }, + "format": { + "type": "string", + "description": "The name of the format of the content handler, will be the value of the CONTENT_FORMAT_ constant. If not set, the constant CONTENT_FORMAT_ will not be set!" + } + } } } }, diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index 207f884..d227a80 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -2,6 +2,8 @@ class ExtensionProcessor implements Processor { + const CONTENT_MODEL_CONSTANT_PREFIX = 'CONTENT_MODEL_'; + const CONTENT_FORMAT_CONSTANT_PREFIX = 'CONTENT_FORMAT_'; /** * Keys that should be set to $GLOBALS * @@ -21,7 +23,6 @@ 'CentralIdLookupProviders', 'ChangeCredentialsBlacklist', 'ConfigRegistry', - 'ContentHandlers', 'DefaultUserOptions', 'ExtensionEntryPointListFiles', 'ExtensionFunctions', @@ -177,6 +178,7 @@ $this->extractExtensionMessagesFiles( $dir, $info ); $this->extractMessagesDirs( $dir, $info ); $this->extractNamespaces( $info ); + $this->extractContentHandlers( $info ); $this->extractResourceLoaderModules( $dir, $info ); $this->extractServiceWiringFiles( $dir, $info ); $this->extractParserTestFiles( $dir, $info ); @@ -274,6 +276,49 @@ } } + /** + * Register ContentHandlers with the appropriate global settings + * @param array $info + * @throws MWException If one ContentHandler is already registered or the format of the + * ContentHandler definition is invalid. + */ + protected function extractContentHandlers( array $info ) { + if ( !isset( $info['ContentHandlers'] ) ) { + return; + } + + foreach ( $info['ContentHandlers'] as $chName => $chData ) { + $chConstant = self::CONTENT_MODEL_CONSTANT_PREFIX; + if ( isset( $chData['model_constant'] ) ) { + $chConstant .= $chData['model_constant']; + } else { + $chConstant .= strtoupper( $chName ); + } + // check, if constant is already in use + if ( defined( $chConstant ) || isset( $this->defines[$chConstant] ) ) { + throw new MWException( $info['name'] . ' tried to register the ContentHandler ' . + $chName . ', which is already in use.' ); + } + + define( $chConstant, $chName ); + if ( is_array( $chData ) && isset( $chData['handler'] ) ) { + $this->globals['wgContentHandlers'][$chName] = $chData['handler']; + } elseif ( !is_array( $chData ) ) { + $this->globals['wgContentHandlers'][$chName] = $chData; + } else { + throw new MWException( 'Invalid format for ContentHandlers provided by ' . + $info['name'] ); + } + + if ( isset( $chData['format_constant'] ) && isset( $chData['format'] ) ) { + define( + self::CONTENT_FORMAT_CONSTANT_PREFIX . strtoupper( $chData['format_constant'] ), + $chData['format'] + ); + } + } + } + protected function extractResourceLoaderModules( $dir, array $info ) { $defaultPaths = isset( $info['ResourceFileModulePaths'] ) ? $info['ResourceFileModulePaths'] -- To view, visit https://gerrit.wikimedia.org/r/325120 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icee5004a64d50b1cc54ad376b599184111609685 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits