Pwirth has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/388498 )
Change subject: BSAvatars: Using new config mechanism ...................................................................... BSAvatars: Using new config mechanism => Requires: I1776ef3ba3e00963a342c01bcb717249c50b7de9 Change-Id: Iba259cb1c976046895e23cb93a1c8a46f803c560 --- M Avatars.class.php M composer.json M extension.json A src/ConfigDefinition/AvatarsDefaultSize.php A src/ConfigDefinition/AvatarsGenerator.php 5 files changed, 76 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceAvatars refs/changes/98/388498/1 diff --git a/Avatars.class.php b/Avatars.class.php index 6f0ae97..f4d138d 100644 --- a/Avatars.class.php +++ b/Avatars.class.php @@ -36,27 +36,9 @@ * @package BlueSpice_Extensions * @subpackage Avatars */ -class Avatars extends BsExtensionMW { +class Avatars extends \BlueSpice\Extension { - public static $bAvatarsActive = true; public static $sAvatarFilePrefix = "BS_avatar_"; - - /** - * Initialization of Avatar extension - */ - protected function initExt() { - wfProfileIn('BS::' . __METHOD__); - - BsConfig::registerVar('MW::Avatars::DefaultSize', 40, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_INT, 'bs-avatars-pref-defaultsize', 'int'); - BsConfig::registerVar('MW::Avatars::Generator', 'InstantAvatar', BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_STRING | BsConfig::USE_PLUGIN_FOR_PREFS, 'bs-avatars-pref-generator', 'select'); - - $this->setHook('BSCoreGetUserMiniProfileBeforeInit'); - $this->setHook('BsAuthorPageProfileImageAfterInitFields'); - - # TODO: required rights? user->read? - #$this->mCore->registerPermission( 'viewfiles', array( 'user' ) ); - wfProfileOut('BS::' . __METHOD__); - } /** * extension.json callback @@ -67,7 +49,7 @@ if ( version_compare( $GLOBALS['wgVersion'], '1.28c', '>' ) ) { $wgForeignFileRepos[] = array( 'class' => 'FileRepo', - 'name' => 'Avatars', + 'name' => 'BlueSpiceAvatars', 'directory' => BS_DATA_DIR . '/Avatars/', 'hashLevels' => 0, 'url' => BS_DATA_PATH . '/Avatars', @@ -75,7 +57,7 @@ } else { $wgForeignFileRepos[] = array( 'class' => 'FSRepo', - 'name' => 'Avatars', + 'name' => 'BlueSpiceAvatars', 'directory' => BS_DATA_DIR . '/Avatars/', 'hashLevels' => 0, 'url' => BS_DATA_PATH . '/Avatars', @@ -108,7 +90,7 @@ * @param type $aParams * @return boolean */ - public function onBSCoreGetUserMiniProfileBeforeInit(&$oUserMiniProfileView, &$oUser, &$aParams) { + public static function onBSCoreGetUserMiniProfileBeforeInit( &$oUserMiniProfileView, &$oUser, &$aParams ) { # Set anonymous image for anonymous or deleted users if ($oUser->isAnon()) { $oUserMiniProfileView->setUserImageSrc(BsConfig::get('MW::DeletedUserImage')); @@ -127,8 +109,9 @@ return true; } + $oAvatars = \BsExtensionManager::getExtension( 'BlueSpiceAvatars' ); # Set or generate user's avatar - $oUserMiniProfileView->setUserImageSrc( $this->generateAvatar( + $oUserMiniProfileView->setUserImageSrc( $oAvatars->generateAvatar( $oUser, $aParams )); @@ -143,7 +126,7 @@ */ public static function getAvatarFile( $iUserId ) { $sAvatarFileName = self::$sAvatarFilePrefix . $iUserId . ".png"; - return BsFileSystemHelper::getFileFromRepoName( $sAvatarFileName, 'Avatars' ); + return BsFileSystemHelper::getFileFromRepoName( $sAvatarFileName, 'BlueSpiceAvatars' ); } /** @@ -152,7 +135,7 @@ * @param User $oUser * @return boolean */ - public function onBsAuthorPageProfileImageAfterInitFields($oView, $oUser) { + public static function onBsAuthorPageProfileImageAfterInitFields($oView, $oUser) { # If user has set MW image or URL return immediately if ($oUser->getOption('MW::UserImage')) return true; @@ -161,7 +144,9 @@ $oView->setImagePath(BsConfig::get('MW::DefaultUserImage')); return true; } - $oView->setImagePath($this->generateAvatar($oUser)); + + $oAvatars = \BsExtensionManager::getExtension( 'BlueSpiceAvatars' ); + $oView->setImagePath( $oAvatars->generateAvatar( $oUser ) ); return true; } @@ -176,7 +161,7 @@ } $oUser = RequestContext::getMain()->getUser(); self::unsetUserImage($oUser); - $oAvatars = BsExtensionManager::getExtension('Avatars'); + $oAvatars = \BsExtensionManager::getExtension( 'BlueSpiceAvatars' ); $sNewPath = $oAvatars->generateAvatar($oUser, array(), true); return FormatJson::encode(wfMessage('bs-avatars-generate-complete')->plain()); } @@ -200,7 +185,11 @@ * @return string Relative URL to avatar image */ public function generateAvatar($oUser, $aParams = array(), $bOverwrite = false) { - $iAvatarDefaultSize = BsConfig::get('MW::Avatars::DefaultSize'); + $config = \BsExtensionManager::getExtension( + 'BlueSpiceAvatars' + )->getConfig(); + + $iAvatarDefaultSize = $config->get( 'AvatarsDefaultSize' ); $iAvatarHeight = ( isset($aParams['height']) ) ? $aParams['height'] : $iAvatarDefaultSize; $iAvatarWidth = ( isset($aParams['width']) ) ? $aParams['width'] : $iAvatarDefaultSize; @@ -218,7 +207,7 @@ # If avatar doesn't yet exit, create one if (!$oFile->exists() || $bOverwrite) { - $sGenerator = BsConfig::get('MW::Avatars::Generator'); + $sGenerator = $config->get( 'AvatarsGenerator' ); switch ($sGenerator) { case 'Identicon': require_once( __DIR__ . "/includes/lib/Identicon/identicon.php" ); @@ -246,15 +235,15 @@ } $sAvatarFileName = $oFile->getName(); - $oStatus = BsFileSystemHelper::saveToDataDirectory($sAvatarFileName, $sRawPNGAvatar, 'Avatars'); + $oStatus = BsFileSystemHelper::saveToDataDirectory($sAvatarFileName, $sRawPNGAvatar, 'BlueSpiceAvatars'); if ( !$oStatus->isGood() ) { throw new MWException( 'FATAL: Avatar could not be saved! '.$oStatus->getMessage() ); } # found no way to regenerate thumbs. just delete thumb folder if it exists - $oStatus = BsFileSystemHelper::deleteFolder('Avatars' . DS . 'thumb' . DS . $sAvatarFileName, true); + $oStatus = BsFileSystemHelper::deleteFolder('BlueSpiceAvatars' . DS . 'thumb' . DS . $sAvatarFileName, true); if (!$oStatus->isGood()) throw new MWException('FATAL: Avatar thumbs could no be deleted!'); - $oFile = BsFileSystemHelper::getFileFromRepoName($sAvatarFileName, 'Avatars'); + $oFile = BsFileSystemHelper::getFileFromRepoName($sAvatarFileName, 'BlueSpiceAvatars'); $oUser->invalidateCache(); } @@ -269,7 +258,7 @@ * @return boolean */ public static function onLocalUserCreated( $user, $autocreated ) { - $oAvatars = BsExtensionManager::getExtension( 'Avatars' ); + $oAvatars = \BsExtensionManager::getExtension( 'BlueSpiceAvatars' ); try{ $sNewPath = $oAvatars->generateAvatar( $user, array(), true ); } catch( Exception $e ) { @@ -291,7 +280,7 @@ * @return boolean */ public static function onBSUserManagerAfterAddUser( $oUserManager, $oUser, $aMetaData, &$oStatus, $oPerformer ) { - $oAvatars = BsExtensionManager::getExtension( 'Avatars' ); + $oAvatars = \BsExtensionManager::getExtension( 'BlueSpiceAvatars' ); try{ $sNewPath = $oAvatars->generateAvatar( $oUser, array(), true ); } catch( Exception $e ) { diff --git a/composer.json b/composer.json index 2461e1b..01af609 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ }, "autoload": { "psr-4": { + "BlueSpice\\Avatars\\" : "src" } } } \ No newline at end of file diff --git a/extension.json b/extension.json index 9b19712..240b38e 100644 --- a/extension.json +++ b/extension.json @@ -8,7 +8,11 @@ "bsgExtensions": { "BlueSpiceAvatars": { "className": "Avatars", - "extPath": "/BlueSpiceAvatars" + "extPath": "/BlueSpiceAvatars", + "configDefinitions": { + "AvatarsDefaultSize": "\\BlueSpice\\Avatars\\ConfigDefinition\\AvatarsDefaultSize::getInstance", + "AvatarsGenerator": "\\BlueSpice\\Avatars\\ConfigDefinition\\AvatarsGenerator::getInstance" + } } }, "callback": "Avatars::onRegistration", @@ -28,6 +32,9 @@ "ext.bluespice.avatars.js": { "scripts": [ "bluespice.avatars.js" + ], + "dependencies": [ + "ext.bluespice.extjs" ], "messages": [ "bs-avatars-upload-title", @@ -49,11 +56,22 @@ "localBasePath": "resources", "remoteExtPath": "BlueSpiceAvatars/resources" }, + "config_prefix": "bsg", + "config": { + "AvatarsDefaultSize": { + "value": 40 + }, + "AvatarsGenerator": { + "value": "InstantAvatar" + } + }, "Hooks": { "BeforePageDisplay": "Avatars::onBeforePageDisplay", "BSUserManagerAfterAddUser": "Avatars::onBSUserManagerAfterAddUser", "LocalUserCreated": "Avatars::onLocalUserCreated", - "UnitTestsList": "Avatars::onUnitTestsList" + "UnitTestsList": "Avatars::onUnitTestsList", + "BSCoreGetUserMiniProfileBeforeInit": "Avatars::onBSCoreGetUserMiniProfileBeforeInit", + "BsAuthorPageProfileImageAfterInitFields": "Avatars::onBsAuthorPageProfileImageAfterInitFields" }, "load_composer_autoloader": true, "manifest_version": 1 diff --git a/src/ConfigDefinition/AvatarsDefaultSize.php b/src/ConfigDefinition/AvatarsDefaultSize.php new file mode 100644 index 0000000..1884a2e --- /dev/null +++ b/src/ConfigDefinition/AvatarsDefaultSize.php @@ -0,0 +1,14 @@ +<?php + +namespace BlueSpice\Avatars\ConfigDefinition; + +class AvatarsDefaultSize extends \BlueSpice\ConfigDefinition\IntSetting { + + public function getLabelMessageKey() { + return 'bs-avatars-pref-defaultsize'; + } + + public function isStored() { + return true; + } +} diff --git a/src/ConfigDefinition/AvatarsGenerator.php b/src/ConfigDefinition/AvatarsGenerator.php new file mode 100644 index 0000000..399d200 --- /dev/null +++ b/src/ConfigDefinition/AvatarsGenerator.php @@ -0,0 +1,18 @@ +<?php + +namespace BlueSpice\Avatars\ConfigDefinition; + +class AvatarsGenerator extends \BlueSpice\ConfigDefinition\ArraySetting { + + public function getHtmlFormField() { + return new \HTMLSelectField( $this->makeFormFieldParams() ); + } + + public function getLabelMessageKey() { + return 'bs-avatars-pref-generator'; + } + + public function isStored() { + return true; + } +} -- To view, visit https://gerrit.wikimedia.org/r/388498 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iba259cb1c976046895e23cb93a1c8a46f803c560 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceAvatars Gerrit-Branch: master Gerrit-Owner: Pwirth <wi...@hallowelt.biz> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits