Robert Vogel has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/396312 )
Change subject: BSFoundation: Reworked BsExtensionManager into registry / factory services ...................................................................... BSFoundation: Reworked BsExtensionManager into registry / factory services * Added ExtensinRegistry * Added ExtensionFactory * Removed deprecated SecureFileStore usage * Removed deprecated methods in BsExtensionManager * Marked the left over methods in BsExtensionManager as deprecated * Replaced usage of BsExtensionManager methods * Used ResouceLoader to set client configs: assets paths, version Beware, that all the workarounds for wrong BlueSpice extension registry is removed by this commit. Now it is made clear, when something is wrong Change-Id: I57ac9698b385c08e6dd087b85b0aa59697197392 --- M extension.json M includes/Core.class.php M includes/CoreHooks.php M includes/ExtensionManager.class.php M includes/ServiceWiring.php M includes/TemplateHelper.php M includes/api/BSApiFileBackendStore.php M includes/skins/BsBaseTemplate.php M includes/utility/FileSystemHelper.class.php A src/ExtensionFactory.php A src/ExtensionRegistry.php A src/Hook/ResourceLoaderGetConfigVars/AddAssetsPaths.php A src/Hook/ResourceLoaderGetConfigVars/AddVersion.php 13 files changed, 488 insertions(+), 378 deletions(-) Approvals: Robert Vogel: Verified; Looks good to me, approved diff --git a/extension.json b/extension.json index aca2f07..bc4ed39 100644 --- a/extension.json +++ b/extension.json @@ -12,6 +12,7 @@ "BlueSpiceFoundation": { "Extensions": { "BlueSpiceFoundation": { + "extPath": "/BlueSpiceFoundation", "configDefinitions": { "Logo": "\\BlueSpice\\ConfigDefinition\\Logo::getInstance", "FileExtensions": "\\BlueSpice\\ConfigDefinition\\FileExtensions::getInstance", @@ -456,8 +457,9 @@ ], "UnitTestsList": "BsCoreHooks::onUnitTestsList", "ResourceLoaderGetConfigVars": [ - "BsExtensionManager::onResourceLoaderGetConfigVars", - "BlueSpice\\Hook\\ResourceLoaderGetConfigVars\\AddBSGConfig::callback" + "\\BlueSpice\\Hook\\ResourceLoaderGetConfigVars\\AddVersion::callback", + "\\BlueSpice\\Hook\\ResourceLoaderGetConfigVars\\AddBSGConfig::callback", + "\\BlueSpice\\Hook\\ResourceLoaderGetConfigVars\\AddAssetsPaths::callback" ] }, "config_prefix": "bsg", diff --git a/includes/Core.class.php b/includes/Core.class.php index 5ede68b..37a61ba 100644 --- a/includes/Core.class.php +++ b/includes/Core.class.php @@ -30,6 +30,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v3 * @filesource */ +use MediaWiki\MediaWikiServices; /** * The BsCore @@ -300,7 +301,10 @@ BSNotifications::init(); wfProfileIn('Performance: ' . __METHOD__ . ' - Load and initialize all Extensions'); - BsExtensionManager::initialiseExtensions( self::$oInstance ); + $factory = MediaWikiServices::getInstance()->getService( + 'BSExtensionFactory' + ); + $factory->getExtensions(); wfProfileOut('Performance: ' . __METHOD__ . ' - Load and initialize all Extensions'); global $wgHooks; diff --git a/includes/CoreHooks.php b/includes/CoreHooks.php index 0a9489b..9aea743 100644 --- a/includes/CoreHooks.php +++ b/includes/CoreHooks.php @@ -1,4 +1,6 @@ <?php +use MediaWiki\MediaWikiServices; + class BsCoreHooks { protected static $bUserFetchRights = false; @@ -77,7 +79,7 @@ * @return boolean */ public static function onBeforePageDisplay( $out, $skin ) { - global $wgFavicon, $wgExtensionAssetsPath, $wgLogo; + global $wgFavicon, $wgLogo; $config = \MediaWiki\MediaWikiServices::getInstance() ->getConfigFactory()->makeConfig( 'bsg' ); @@ -112,15 +114,6 @@ $out->addJsConfigVars( 'bsImageExtensions', $aImageExtensions ); $out->addJsConfigVars( 'bsIsWindows', wfIsWindows() ); - $aExtensionConfs = BsExtensionManager::getRegisteredExtensions(); - $aAssetsPaths = array( - 'BlueSpiceFoundation' => $wgExtensionAssetsPath.'/BlueSpiceFoundation' - ); - - foreach( $aExtensionConfs as $sName => $aConf ) { - $aAssetsPaths[$sName] = $wgExtensionAssetsPath.$aConf['extPath']; - } - //provide task permission data for current user to be used in js ui elements, eg show / hide elements //get all registered api modules global $wgAPIModules; @@ -132,8 +125,6 @@ } } - //TODO: Implement as RL Module: see ResourceLoaderUserOptionsModule - $out->addJsConfigVars('bsExtensionManagerAssetsPaths', $aAssetsPaths); self::addTestSystem( $out ); return true; } @@ -591,8 +582,11 @@ * @return boolean Always true to keep hook running */ public static function onParserFirstCallInit( $parser ) { + $factory = MediaWikiServices::getInstance()->getService( + 'BSExtensionFactory' + ); BsGenericTagExtensionHandler::setupHandlers( - BsExtensionManager::getRunningExtensions(), + $factory->getExtensions(), $parser ); return true; diff --git a/includes/ExtensionManager.class.php b/includes/ExtensionManager.class.php index 253ffed..0aa6b16 100644 --- a/includes/ExtensionManager.class.php +++ b/includes/ExtensionManager.class.php @@ -10,366 +10,87 @@ * @author Stephan Muggli <mug...@hallowelt.com> */ // Last Review: MRG20100813 +use MediaWiki\MediaWikiServices; +use BlueSpice\Extension; +/** + * @deprecated since version 3.0.0 + */ class BsExtensionManager { - protected static $prRegisteredExtensions = array(); /** - * - * @var BsExtensionMW[] - */ - protected static $prRunningExtensions = array(); - protected static $aContexts = array(); - protected static $aActiveContexts = array(); - - /** - * @deprecated since version 2.27.0 - * @param string $sKey Context key - * @return string normalized key - */ - public static function addContext( $sKey ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - wfDeprecated( __METHOD__, '2.27.0' ); - $sKey = strtoupper( $sKey ); - if ( !array_key_exists( $sKey, self::$aContexts ) ) { - self::$aContexts[ $sKey ] = array( - 'scripts' => array( ), - 'styles' => array( ) - ); - } - wfProfileOut( 'Performance: ' . __METHOD__ ); - return $sKey; - } - - /** - * @deprecated since version 2.27.0 - * @param string $sKey Context key - */ - public static function setContext( $sKey ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - wfDeprecated( __METHOD__, '2.27.0' ); - $sKey = self::addContext( $sKey ); - if ( !array_key_exists( $sKey, self::$aActiveContexts ) ) { - self::$aActiveContexts[ $sKey ] = true; - } - wfProfileOut( 'Performance: ' . __METHOD__ ); - } - - /** - * @deprecated since version 2.27.0 - * @param string $sKey Context key - * @return bool - */ - public static function isContextActive( $sKey ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - wfDeprecated( __METHOD__, '2.27.0' ); - $bResult = array_key_exists( strtoupper( $sKey ), self::$aActiveContexts ); - wfProfileOut( 'Performance: ' . __METHOD__ ); - return $bResult; - } - - /** - * @deprecated since version 2.27.0 - * @param string $sKey Context key - */ - public static function removeContext( $sKey ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - wfDeprecated( __METHOD__, '2.27.0' ); - $sKey = strtoupper( $sKey ); - if ( array_key_exists( $sKey, self::$aContexts ) ) { - unset( self::$aContexts[ $sKey ] ); - self::$aActiveContexts[ $sKey ] = false; - } - wfProfileOut( 'Performance: ' . __METHOD__ ); - } - - /** - * DEPRECATED: Use global $bsgExtensions instead. - * Define $bsgExtensions in extension.json - * "bsgExtensions": { - * "ExtName": { - * "className": "ExtClass", - * "extPath": "/PackagePath/ExtDir", - * "status" => "stable", //optional - * "package" => "BlueSpice free", //optional - * } - * }, - * @deprecated since version 2.27.0 - * @param string $name - * @param integer $runlevel - * @param integer $action - * @param string $extPath - */ - public static function registerExtension( $name, $runlevel = BsRUNLEVEL::FULL, $action = BsACTION::NONE, $extPath = 'ext' ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - wfDeprecated( __METHOD__, '2.27.0' ); - - if( empty( $extPath ) || $extPath == 'ext' ) { - $extPath = "/BlueSpiceExtensions/$name"; - } - //HACKY: Old dir 2 ext path calculations can finally be removed with - //this method, yay! - global $IP; - $extPath = str_replace( '\\', '/', $extPath ); - $sIPPath = str_replace( '\\', '/', $IP ); - $extPath = str_replace( "$sIPPath/extensions", '', $extPath ); - - //Hacky, but the Preferences extension has the prefix Bs to not - //having the same name as the MW class. - $sClassName = $name; - if( $name == 'Preferences' ) { - $sClassName = "Bs$sClassName"; - } - - $GLOBALS['bsgExtensions'][$name] = array( - 'className' => $sClassName, - 'extPath' => $extPath, - 'deprecatedSince' => '2.27.0', - ); - wfProfileOut( 'Performance: ' . __METHOD__ ); - } - - /** - * + * @deprecated since version 3.0.0 - Use Service + * ('BSExtensionRegistry')->getExtensionDefinitions instead * @return array */ public static function getRegisteredExtensions() { - return self::$prRegisteredExtensions; + wfDeprecated( __METHOD__, '3.0.0' ); + $registry = MediaWikiServices::getInstance()->getService( + 'BSExtensionRegistry' + ); + return $registry->getExtensionDefinitions(); } /** - * - * @return BsExtensionMW[] + * @deprecated since version 3.0.0 - Use Service + * ('BSExtensionFactory')->getExtensions instead + * @return Extension[] */ public static function getRunningExtensions() { - return self::$prRunningExtensions; - } - - protected static function makeExtensionDefinition( $sExtName = "", $aDefinition = array() ) { - global $bsgBlueSpiceExtInfo; - $aExtensions = ExtensionRegistry::getInstance()->getAllThings(); - - //Some BlueSpice extensions have been registered wrong in the past. - //The the extension name used as key in bsgExtensions must be equal with - //the extensions name in the "name" attribute of the extension.json! - $aExtension = null; - if( isset( $aExtensions[$sExtName] ) ) { - $aExtension = $aExtensions[$sExtName]; - } elseif ( isset( $aExtensions["BlueSpice$sExtName"] ) ) { - $aExtension = $aExtensions["BlueSpice$sExtName"]; - } else { - $sFixedExtName = str_replace( 'BlueSpice', '', $sExtName ); - if( isset( $aExtensions[$sFixedExtName] ) ) { - $aExtension = $aExtensions[$sFixedExtName]; - } - } - if( !$aExtension ) { - throw new BsException( - "$sExtName is not a registered extension!" - ); - } - - $aDefinition = array_merge( - $aExtension, - $aDefinition + wfDeprecated( __METHOD__, '3.0.0' ); + $factory = MediaWikiServices::getInstance()->getService( + 'BSExtensionFactory' ); - if( !isset( $aDefinition['className'] ) ) { - $aDefinition['className'] = $sExtName; - } - if( !isset( $aDefinition['extPath'] ) ) { - $aDefinition['extPath'] = ""; - } - if( !isset( $aDefinition['status'] ) ) { - $aDefinition['status'] = "default"; - } - if( !isset( $aDefinition['package'] ) ) { - $aDefinition['package'] = "default"; - } - $aDefinition['status'] = str_replace( - 'default', - $GLOBALS['bsgBlueSpiceExtInfo']['status'], - $aDefinition['status'] - ); - $aDefinition['package'] = str_replace( - 'default', - $GLOBALS['bsgBlueSpiceExtInfo']['package'], - $aDefinition['package'] - ); - return $aDefinition; - } - - /** - * Collects and initializes all BlueSpice extensions - * @param BsCore $oCore - * @throws BsException - */ - public static function initialiseExtensions( $oCore ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - $extRegistry = ExtensionRegistry::getInstance(); - $aBSExtFromJSON = $extRegistry->getAttribute( - 'bsgExtensions' - ); - - if( empty( $GLOBALS['bsgExtensions'] ) ) { - $GLOBALS['bsgExtensions'] = []; - } - if( !empty( $aBSExtFromJSON ) ) { - $GLOBALS['bsgExtensions'] = array_merge( - //old global - $GLOBALS['bsgExtensions'], - //manifest version 1 - $aBSExtFromJSON, - //manifest version 2 - $extRegistry->getAttribute( 'BlueSpiceFoundationExtensions' ) - ); - } - - foreach( $GLOBALS['bsgExtensions'] as $sExtName => $aDefinition ) { - //Skip the definitions for BlueSpiceFoundation, as it is not a - //extension we can instantiate - if( $sExtName === 'BlueSpiceFoundation' ) { - continue; - } - self::$prRegisteredExtensions[$sExtName] - = self::makeExtensionDefinition( $sExtName, $aDefinition ); - } - - foreach ( self::$prRegisteredExtensions as $sExtName => $aDefinition ) { - $sClassName = $aDefinition['className']; - - if( !class_exists( $sClassName ) ) { - throw new BsException( - "Class $sClassName for Extension $sExtName not found!" - ); - } - - $config = \MediaWiki\MediaWikiServices::getInstance() - ->getConfigFactory()->makeConfig( 'bsg' ); - self::$prRunningExtensions[$sExtName] = new $sClassName( - $aDefinition, - RequestContext::getMain(), - $config - ); - if( !self::$prRunningExtensions[$sExtName] instanceof \BsExtensionMW ) { - wfProfileOut( 'Performance: ' . __METHOD__ ); - return; - } - - //this is for extensions using the old mechanism and may have their - //own __constructor - self::$prRunningExtensions[$sExtName]->setConfig( $config ); - self::$prRunningExtensions[$sExtName]->setContext( - RequestContext::getMain() - ); - self::$prRunningExtensions[$sExtName]->setCore( $oCore ); - self::$prRunningExtensions[$sExtName]->setup( - $sExtName, - $aDefinition - ); - } - - wfProfileOut( 'Performance: ' . __METHOD__ ); + return $factory->getExtensions(); } /** * Returns an instance of the requested BlueSpice extension or null, when * not found / not active + * @deprecated since version 3.0.0 - Use Service + * ('BSExtensionFactory')->getExtension instead * @param string $name - * @return BsExtensionMW + * @return Extension */ public static function getExtension( $name ) { - wfProfileIn( 'Performance: ' . __METHOD__ ); - //Backwards compatibility: extensions will have a BlueSice prefix in - //the future - $aExtensions = self::getRunningExtensions(); - if ( isset( $aExtensions["BlueSpice$name"] ) ) { - //TODO: Add a wfDeprecated( __METHOD__, 'next BS Version' ); - wfProfileOut( 'Performance: ' . __METHOD__ ); - return $aExtensions["BlueSpice$name"]; + wfDeprecated( __METHOD__, '3.0.0' ); + $factory = MediaWikiServices::getInstance()->getService( + 'BSExtensionFactory' + ); + $extension = $factory->getExtension( $name ); + if( !$extension ) { + //Backwards compatibility: extensions will have a BlueSice prefix in + //the future + $extension = $factory->getExtension( "BlueSpice$name" ); } - if ( isset( $aExtensions[$name] ) ) { - wfProfileOut( 'Performance: ' . __METHOD__ ); - return $aExtensions[$name]; - } - wfProfileOut( 'Performance: ' . __METHOD__ ); + return $extension; } /** * Returns a list of all running BlueSpice extensions + * @deprecated since version 3.0.0 - Use Service + * ('BSExtensionRegistry')->getNames instead * @return array */ public static function getExtensionNames() { - return array_keys( self::getRunningExtensions() ); + wfDeprecated( __METHOD__, '3.0.0' ); + $registry = MediaWikiServices::getInstance()->getService( + 'BSExtensionRegistry' + ); + return $registry->getNames(); } /** * Provides an array of inforation sets about all registered extensions + * @deprecated since version 3.0.0 - Use Service + * ('BSExtensionFactory')->getExtensionInformation instead * @return array */ public static function getExtensionInformation() { - wfProfileIn( 'Performance: ' . __METHOD__ ); - $aInformation = array(); - foreach ( self::$prRunningExtensions as $sExtName => $oExt ) { - $aInformation[$sExtName] = $oExt->getInfo(); - } - - wfProfileOut( 'Performance: ' . __METHOD__ ); - return $aInformation; + wfDeprecated( __METHOD__, '3.0.0' ); + $factory = MediaWikiServices::getInstance()->getService( + 'BSExtensionFactory' + ); + return $factory->getExtensionInformation(); } - - /** - * Creates a namespace AND a corresponding talk namespace with respect of - * an potential offest. You will need to register a - * "Extension.namespaces.php" file with "$wgExtensionMessagesFiles" as - * described on https://www.mediawiki.org/wiki/Localisation#Namespaces - * - * @deprecated since version 2.27.0 - * @global array $wgExtraNamespaces - * @param string $sCanonicalName - * @param int $iBaseIndex - */ - public static function registerNamespace( $sCanonicalName, $iBaseIndex, $isSystemNamespace = true ) { - wfDeprecated( __METHOD__, '2.27.0' ); - global $wgExtraNamespaces, $bsgSystemNamespaces; - - $sConstantName = 'NS_'.mb_strtoupper( $sCanonicalName ); - $iCalculatedNSId = BS_NS_OFFSET + $iBaseIndex; - - if ( !defined( $sConstantName ) ) { - define( $sConstantName, $iCalculatedNSId ); - $wgExtraNamespaces[$iCalculatedNSId] = $sCanonicalName; - } - - if ( $isSystemNamespace ) { - $bsgSystemNamespaces[$iCalculatedNSId] = $sConstantName; - } - - //Talk namespace - $sConstantName .= '_TALK'; - $iCalculatedNSId++; - - if ( !defined( $sConstantName ) ) { - define( $sConstantName, $iCalculatedNSId ); - $wgExtraNamespaces[$iCalculatedNSId] = $sCanonicalName.'_talk'; - } - - if ( $isSystemNamespace ) { - $bsgSystemNamespaces[$iCalculatedNSId] = $sConstantName; - } - } - - /** - * Hook handler for ResourceLoaderGetConfigVars - Appends the BlueSpice - * version number to JS config vars - * @global array $bsgBlueSpiceExtInfo - * @param array $vars - * @return boolean - */ - public static function onResourceLoaderGetConfigVars( array &$vars ) { - global $bsgBlueSpiceExtInfo; - - $vars["bsgVersion"] = $bsgBlueSpiceExtInfo["version"]; - - return true; - } -} \ No newline at end of file +} diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 653b764..cc15ae4 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -4,6 +4,20 @@ return [ + 'BSExtensionRegistry' => function ( MediaWikiServices $services ) { + return new \BlueSpice\ExtensionRegistry( + \ExtensionRegistry::getInstance(), + $services->getConfigFactory()->makeConfig( 'bsg' ) + ); + }, + + 'BSExtensionFactory' => function ( MediaWikiServices $services ) { + return new \BlueSpice\ExtensionFactory( + $services->getService( 'BSExtensionRegistry' ), + $services->getConfigFactory()->makeConfig( 'bsg' ) + ); + }, + 'BSConfigDefinitionFactory' => function ( MediaWikiServices $services ) { return new \BlueSpice\ConfigDefinitionFactory( $services->getConfigFactory()->makeConfig( 'bsg' ) diff --git a/includes/TemplateHelper.php b/includes/TemplateHelper.php index 0b29c71..8b5e10f 100644 --- a/includes/TemplateHelper.php +++ b/includes/TemplateHelper.php @@ -24,6 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v3 * @filesource */ +use MediaWiki\MediaWikiServices; /** * @package BlueSpiceFoundation @@ -34,7 +35,10 @@ protected static $sFileExt = '.mustache'; protected static function makeFullExtTemplatePathFromExtName( $sExtName ) { - $aExtensions = BsExtensionManager::getRegisteredExtensions(); + $registry = MediaWikiServices::getInstance()->getService( + 'BSExtensionRegistry' + ); + $aExtensions = $registry->getExtensionDefinitions(); if( !isset($aExtensions[$sExtName]) ) { throw new BsException( "Unknowen Extension $sExtName" ); } @@ -49,7 +53,10 @@ protected static function makeTemplateNameFromPath( $sExtName, $sFullPath ) { $sFullPath = BsFileSystemHelper::normalizePath( $sFullPath ); - $aExtensions = BsExtensionManager::getRegisteredExtensions(); + $registry = MediaWikiServices::getInstance()->getService( + 'BSExtensionRegistry' + ); + $aExtensions = $registry->getExtensionDefinitions(); if( !isset($aExtensions[$sExtName]) ) { throw new BsException( "Unknowen Extension $sExtName" ); } @@ -111,7 +118,10 @@ * @return array */ public static function getAllTemplates( $aReturn = [] ) { - $aExtensions = BsExtensionManager::getRegisteredExtensions(); + $registry = MediaWikiServices::getInstance()->getService( + 'BSExtensionRegistry' + ); + $aExtensions = $registry->getExtensionDefinitions(); foreach( $aExtensions as $sExtName => $aConfig ) { try { $aTplDir = static::makeFullExtTemplatePathFromExtName( diff --git a/includes/api/BSApiFileBackendStore.php b/includes/api/BSApiFileBackendStore.php index 7d4ee4f..7fa1b6d 100644 --- a/includes/api/BSApiFileBackendStore.php +++ b/includes/api/BSApiFileBackendStore.php @@ -309,9 +309,6 @@ } protected function addSecondaryFields( $aTrimmedData ) { - $oSecureFileStore = BsExtensionManager::getExtension( - 'SecureFileStore' - ); foreach( $aTrimmedData as $oDataSet ) { $oFilePage = Title::makeTitle( NS_FILE, $oDataSet->page_title ); @@ -324,12 +321,6 @@ //TODO: Make thumb size a parameter $sThumb = $oImg->createThumb( 80, 120 ); $sUrl = $oImg->getUrl(); - - //TODO: Remove, when SecureFileStore is finally removed - if( $oSecureFileStore ) { - $sThumb = html_entity_decode( SecureFileStore::secureStuff( $sThumb, true ) ); - $sUrl = html_entity_decode( SecureFileStore::secureStuff( $sUrl, true ) ); - } $oDataSet->file_url = $sUrl; $oDataSet->file_thumbnail_url = $sThumb; diff --git a/includes/skins/BsBaseTemplate.php b/includes/skins/BsBaseTemplate.php index 2d83dfd..70ddaea 100644 --- a/includes/skins/BsBaseTemplate.php +++ b/includes/skins/BsBaseTemplate.php @@ -427,17 +427,7 @@ $sText = $aVal[0]; if ( is_object( $oFile ) && $oFile->exists() ) { - //TODO: Remove, when SecureFileStore is finally - //removed - $oSecureFileStore - = BsExtensionManager::getExtension( - 'SecureFileStore' - ); - if ( $oSecureFileStore ) { - $sUrl = SecureFileStore::secureStuff( $oFile->getUrl(), true ); - } else { - $sUrl = $oFile->getUrl(); - } + $sUrl = $oFile->getUrl(); $sIcon = '<span class="icon24 custom-icon" style="background-image:url(' . $sUrl . ')"></span>'; } } diff --git a/includes/utility/FileSystemHelper.class.php b/includes/utility/FileSystemHelper.class.php index b3c6bb5..79388ee 100644 --- a/includes/utility/FileSystemHelper.class.php +++ b/includes/utility/FileSystemHelper.class.php @@ -632,19 +632,7 @@ $oPage = WikiPage::factory( $oRepoFile->getTitle() ); $oPage->doEditContent( new WikitextContent( $sPageText ), '' ); - //TODO: Remove, when SecureFileStore is finally removed - $oSecureFileStore = BsExtensionManager::getExtension( - 'SecureFileStore' - ); - if ( $oSecureFileStore ) { - return Status::newGood( SecureFileStore::secureStuff( - $oRepoFile->getUrl(), - true - )); - } - else{ - return Status::newGood( $oRepoFile->getUrl(), true ); - } + return Status::newGood( $oRepoFile->getUrl(), true ); } else{ return Status::newFatal( wfMessage( 'bs-filesystemhelper-upload-local-error-create' ) ); diff --git a/src/ExtensionFactory.php b/src/ExtensionFactory.php new file mode 100644 index 0000000..f823a0f --- /dev/null +++ b/src/ExtensionFactory.php @@ -0,0 +1,155 @@ +<?php +/** + * ExtensionFactory class for BlueSpice + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * This file is part of BlueSpice MediaWiki + * For further information visit http://bluespice.com + * + * @author Patric Wirth <wi...@hallowelt.com> + * @package BlueSpiceFoundation + * @copyright Copyright (C) 2016 Hallo Welt! GmbH, All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v3 + * @filesource + */ +namespace BlueSpice; + +class ExtensionFactory { + /** + * + * @var Extension[] + */ + protected $extensions = null; + + /** + * + * @var \BlueSpice\ExtensionRegistry + */ + protected $extensionRegistry = null; + + /** + * + * @var \Config + */ + protected $config = null; + + /** + * @param \BlueSpice\ExtensionRegistry $extensionRegistry + * @param \Config $config + * @return Extension | null + */ + public function __construct( $extensionRegistry, $config ) { + $this->extensionRegistry = $extensionRegistry; + $this->config = $config; + } + + protected function factory( $name, $definition ) { + $class = $definition['className']; + if( strpos( $class, "\\" ) !== 0 ) { + $class = "\\$class"; + } + + if( !class_exists( $class ) ) { + //this may change in the future, as there is not much left, that + //would be written into the extensin classes + throw new \BsException( + "Class $class for Extension $name not found!" + ); + } + + $this->extensions[$name] = new $class( + $definition, + \RequestContext::getMain(), + $this->config + ); + + $this->legacyFactory( $name, $this->extensions[$name] ); + return $this->extensions[$name]; + } + + protected function legacyFactory( $name, $extension ) { + if( !$extension instanceof \BsExtensionMW ) { + return; + } + + $core = \BsCore::getInstance(); + //this is for extensions using the old mechanism and may have their + //own __constructor + $extension->setConfig( $this->config ); + $extension->setContext( + \RequestContext::getMain() + ); + $extension->setCore( $core ); + $extension->setup( + $name, + $this->extensionRegistry->getExtensionDefinitionByName( $name ) + ); + return; + } + + /** + * Returns all instances of registerd BlueSpice extension + * @return Extension[] + */ + public function getExtensions() { + if( $this->extensions ) { + return $this->extensions; + } + $definitions = $this->extensionRegistry->getExtensionDefinitions(); + foreach( $definitions as $name => $definition ) { + if( $name === 'BlueSpiceFoundation' ) { + continue; + } + $this->extensions[] = $this->factory( $name, $definition ); + } + return $this->extensions; + } + + /** + * Returns an instance of the requested BlueSpice extension or null, when + * not found + * @param string $name + * @return Extension | null + */ + public function getExtension( $name ) { + $extensions = $this->getExtensions(); + if( isset( $extensions[$name] ) ) { + return $extensions[$name]; + } + return null; + } + + /** + * Returns a list of all running BlueSpice extensions + * @return array + */ + public function getExtensionNames() { + return array_keys( $this->getExtensions() ); + } + + /** + * Provides an array of inforation sets about all registered extensions + * @return array + */ + public function getExtensionInformation() { + $info = []; + foreach ( $this->getExtensions() as $name => $extension ) { + $info[$name] = $extension->getInfo(); + } + + return $info; + } +} + diff --git a/src/ExtensionRegistry.php b/src/ExtensionRegistry.php new file mode 100644 index 0000000..1f2081d --- /dev/null +++ b/src/ExtensionRegistry.php @@ -0,0 +1,189 @@ +<?php + +/** + * ExtensionRegistry class for BlueSpice + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * This file is part of BlueSpice MediaWiki + * For further information visit http://bluespice.com + * + * @author Patric Wirth <wi...@hallowelt.com> + * @package BlueSpiceFoundation + * @copyright Copyright (C) 2016 Hallo Welt! GmbH, All rights reserved. + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License v3 + * @filesource + */ +namespace BlueSpice; + +/** + * ExtensionRegistry class for BlueSpice + * @package BlueSpiceFoundation + */ +class ExtensionRegistry { + protected $extensionDefinitions = null; + + /** + * + * @var \ExtensionRegistry + */ + protected $extensionRegistry = null; + + /** + * + * @var \Config + */ + protected $config = null; + + /** + * + * @param name $config + */ + public function __construct( $extensionRegistry, $config ) { + $this->extensionRegistry = $extensionRegistry; + $this->config = $config; + } + + protected function runRegister() { + if( $this->extensionDefinitions ) { + return true; + } + + $extRegistryV1 = $this->extensionRegistry->getAttribute( + 'bsgExtensions' + ); + $extRegistryV2 = $this->extensionRegistry->getAttribute( + 'BlueSpiceFoundationExtensions' + ); + + if( empty( $GLOBALS['bsgExtensions'] ) ) { + $GLOBALS['bsgExtensions'] = []; + } + + $GLOBALS['bsgExtensions'] = array_merge( + //old global, wich is still in use in some cases + $GLOBALS['bsgExtensions'], + //manifest version 1 + $extRegistryV1, + //manifest version 2 + $extRegistryV2 + ); + + foreach( $GLOBALS['bsgExtensions'] as $name => $definition ) { + if( $name === 'BlueSpiceFoundation' ) { + continue; + } + $GLOBALS['bsgExtensions'][$name] = $this->makeExtensionDefinition( + $name, + $definition + ); + } + $this->extensionDefinitions = &$GLOBALS['bsgExtensions']; + + return true; + } + + protected function makeExtensionDefinition( $name, $definition ) { + $allThings = $this->extensionRegistry->getAllThings(); + + //Some BlueSpice extensions have been registered wrong in the past. + //The the extension name used as key in bsgExtensions must be equal with + //the extensions name in the "name" attribute of the extension.json! + if( !isset( $allThings[$name] ) ) { + throw new \BsException( + "$name is not a registered extension!" + ); + } + + $definition = array_merge( + $allThings[$name], + $definition + ); + if( !isset( $definition['className'] ) ) { + //this may change in the future, as there is not much left, that + //would be written into the extensin classes + throw new \BsException( + "$name className needs to be set!" + ); + } + if( !isset( $definition['extPath'] ) ) { + $definition['extPath'] = ""; + } + if( !isset( $definition['status'] ) ) { + $definition['status'] = "default"; + } + if( !isset( $definition['package'] ) ) { + $definition['package'] = "default"; + } + + $extInfo = $this->config->get( 'BlueSpiceExtInfo' ); + $definition['status'] = str_replace( + 'default', + $extInfo['status'], + $definition['status'] + ); + $definition['package'] = str_replace( + 'default', + $extInfo['package'], + $definition['package'] + ); + return $definition; + } + + /** + * Returns all registered extension definitions + * @return array + */ + public function getExtensionDefinitions() { + if( !$this->runRegister() ) { + return []; + } + return $this->extensionDefinitions; + } + + /** + * Checks if given name is a registered Extension + * @param string $sName + * @return bool + */ + public function hasName( $sName ) { + return in_array( + $sName, + $this->getNames() + ); + } + + /** + * Returns a registered extension by given name + * @param string $sName + * @return array + */ + public function getExtensionDefinitionByName( $sName ) { + if( !$this->hasName( $sName ) ) { + return []; + } + return $this->extensionDefinitions[$sName]; + } + + /** + * Returns all registered extensions names + * @return array + */ + public function getNames() { + return array_keys( + $this->getExtensionDefinitions() + ); + } + +} diff --git a/src/Hook/ResourceLoaderGetConfigVars/AddAssetsPaths.php b/src/Hook/ResourceLoaderGetConfigVars/AddAssetsPaths.php new file mode 100644 index 0000000..86d292c --- /dev/null +++ b/src/Hook/ResourceLoaderGetConfigVars/AddAssetsPaths.php @@ -0,0 +1,31 @@ +<?php + +namespace BlueSpice\Hook\ResourceLoaderGetConfigVars; + +use BlueSpice\Hook\ResourceLoaderGetConfigVars; + +class AddAssetsPaths extends ResourceLoaderGetConfigVars { + + protected function doProcess() { + $this->vars = array_merge( + $this->vars, + $this->getSettingsToExpose() + ); + return true; + } + + protected function getSettingsToExpose() { + $extensionAssetsPath = $this->getConfig()->get( 'ExtensionAssetsPath' ); + $registry = $this->getServices()->getService( + 'BSExtensionRegistry' + ); + $definitions = $registry->getExtensionDefinitions(); + $paths = []; + + foreach( $definitions as $sName => $definition ) { + $paths[$sName] = $extensionAssetsPath.$definition['extPath']; + } + + return ['bsExtensionManagerAssetsPaths' => $paths ]; + } +} diff --git a/src/Hook/ResourceLoaderGetConfigVars/AddVersion.php b/src/Hook/ResourceLoaderGetConfigVars/AddVersion.php new file mode 100644 index 0000000..fb6defe --- /dev/null +++ b/src/Hook/ResourceLoaderGetConfigVars/AddVersion.php @@ -0,0 +1,21 @@ +<?php + +namespace BlueSpice\Hook\ResourceLoaderGetConfigVars; + +use BlueSpice\Hook\ResourceLoaderGetConfigVars; + +class AddVersion extends ResourceLoaderGetConfigVars { + + protected function doProcess() { + $this->vars = array_merge( + $this->vars, + $this->getSettingsToExpose() + ); + return true; + } + + protected function getSettingsToExpose() { + $extInfo = $this->getConfig()->get( 'BlueSpiceExtInfo' ); + return [ 'bsgVersion' => $extInfo["version"] ]; + } +} -- To view, visit https://gerrit.wikimedia.org/r/396312 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I57ac9698b385c08e6dd087b85b0aa59697197392 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation Gerrit-Branch: master Gerrit-Owner: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits