jenkins-bot has submitted this change and it was merged. Change subject: 1072 [BS224] PermissionManager: LockMode & pm-settings.php Backup ......................................................................
1072 [BS224] PermissionManager: LockMode & pm-settings.php Backup I added extra checks if a new configuration file has to be built. Lockmode now writes a new pm-settings.php, only if any of its needed settings are not set. Additionally, I also added a session flag to short-circuit the whole checking process if the process was running once in the current session AND if the state of Lockmode (active|inactive) didn't changed. I tried to reformat the file closely to the styleguide. Change-Id: I83ecc91d58e1f3efba2451f5945b2ec999f9af2c --- M PermissionManager/PermissionManager.class.php 1 file changed, 229 insertions(+), 205 deletions(-) Approvals: Robert Vogel: Looks good to me, approved Tweichart: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/PermissionManager/PermissionManager.class.php b/PermissionManager/PermissionManager.class.php index 45e60fc..76de763 100644 --- a/PermissionManager/PermissionManager.class.php +++ b/PermissionManager/PermissionManager.class.php @@ -47,49 +47,50 @@ */ protected static $aGroups = array(); protected static $aBuiltInGroups = array( - 'autoconfirmed', 'emailconfirmed', 'bot', 'sysop', 'bureaucrat', 'developer' + 'autoconfirmed', 'emailconfirmed', 'bot', 'sysop', 'bureaucrat', 'developer' ); /** * @var array */ - protected static $aInvisibleGroups = array('Sysop'); + protected static $aInvisibleGroups = array( 'Sysop' ); + /** * Constructor of PermissionManager */ public function __construct() { - wfProfileIn('BS::' . __METHOD__); + wfProfileIn( 'BS::' . __METHOD__ ); // Base settings $this->mExtensionFile = __FILE__; $this->mExtensionType = EXTTYPE::SPECIALPAGE; $this->mInfo = array( - EXTINFO::NAME => 'PermissionManager', - EXTINFO::DESCRIPTION => 'bs-permissionmanager-desc', - EXTINFO::AUTHOR => 'Sebastian Ulbricht', - EXTINFO::VERSION => 'default', - EXTINFO::STATUS => 'default', - EXTINFO::PACKAGE => 'default', - EXTINFO::URL => 'http://www.hallowelt.biz', - EXTINFO::DEPS => array('bluespice' => '2.23.0') + EXTINFO::NAME => 'PermissionManager', + EXTINFO::DESCRIPTION => 'bs-permissionmanager-desc', + EXTINFO::AUTHOR => 'Sebastian Ulbricht', + EXTINFO::VERSION => 'default', + EXTINFO::STATUS => 'default', + EXTINFO::PACKAGE => 'default', + EXTINFO::URL => 'http://www.hallowelt.biz', + EXTINFO::DEPS => array( 'bluespice' => '2.23.0' ) ); - WikiAdmin::registerModule('PermissionManager', array( - 'image' => '/extensions/BlueSpiceExtensions/WikiAdmin/resources/images/bs-btn_rechteverwaltung_v1.png', - 'level' => 'wikiadmin', - 'message' => 'bs-permissionmanager-label' + WikiAdmin::registerModule( 'PermissionManager', array( + 'image' => '/extensions/BlueSpiceExtensions/WikiAdmin/resources/images/bs-btn_rechteverwaltung_v1.png', + 'level' => 'wikiadmin', + 'message' => 'bs-permissionmanager-label' ) ); - wfProfileOut('BS::' . __METHOD__); + wfProfileOut( 'BS::' . __METHOD__ ); } protected function initExt() { - BsConfig::registerVar('MW::PermissionManager::Lockmode', false, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-permissionmanager-pref-lockmode', 'toggle'); - BsConfig::registerVar('MW::PermissionManager::SkipSystemNS', false, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL, 'bs-permissionmanager-pref-skipsysns', 'toggle'); - BsConfig::registerVar('MW::PermissionManager::RealityCheck', false, BsConfig::LEVEL_PUBLIC|BsConfig::TYPE_BOOL|BsConfig::RENDER_AS_JAVASCRIPT, 'bs-permissionmanager-pref-enablerealitycheck', 'toggle'); + BsConfig::registerVar( 'MW::PermissionManager::Lockmode', false, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-permissionmanager-pref-lockmode', 'toggle' ); + BsConfig::registerVar( 'MW::PermissionManager::SkipSystemNS', false, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL, 'bs-permissionmanager-pref-skipsysns', 'toggle' ); + BsConfig::registerVar( 'MW::PermissionManager::RealityCheck', false, BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_BOOL | BsConfig::RENDER_AS_JAVASCRIPT, 'bs-permissionmanager-pref-enablerealitycheck', 'toggle' ); - $this->setHook('BSWikiAdminUserManagerBeforeUserListSend'); - $this->setHook('BSGroupManagerGroupNameChanged'); + $this->setHook( 'BSWikiAdminUserManagerBeforeUserListSend' ); + $this->setHook( 'BSGroupManagerGroupNameChanged' ); } /** @@ -99,64 +100,64 @@ */ public static function getSchemaUpdates( $updater ) { $updater->addExtensionTable( - 'bs_permission_templates', - __DIR__.DS .'db'.DS.'PermissionManager.sql' + 'bs_permission_templates', + __DIR__ . DS . 'db' . DS . 'PermissionManager.sql' ); return true; } - public function onBSGroupManagerGroupNameChanged($sGroup, $sNewGroup, &$result) { + public function onBSGroupManagerGroupNameChanged( $sGroup, $sNewGroup, &$result ) { global $wgGroupPermissions, $wgNamespacePermissionLockdown; - $wgGroupPermissions[$sNewGroup] = $wgGroupPermissions[$sGroup]; - unset($wgGroupPermissions[$sGroup]); - foreach ($wgNamespacePermissionLockdown as $iNs => $aPermissions) { - foreach ($aPermissions as $sPermission => $aGroups) { - $iIndex = array_search($sGroup, $aGroups); - if ($iIndex !== false) { - array_splice($wgNamespacePermissionLockdown[$iNs][$sPermission], $iIndex, 1, array($sNewGroup)); + $wgGroupPermissions[ $sNewGroup ] = $wgGroupPermissions[ $sGroup ]; + unset( $wgGroupPermissions[ $sGroup ] ); + foreach ( $wgNamespacePermissionLockdown as $iNs => $aPermissions ) { + foreach ( $aPermissions as $sPermission => $aGroups ) { + $iIndex = array_search( $sGroup, $aGroups ); + if ( $iIndex !== false ) { + array_splice( $wgNamespacePermissionLockdown[ $iNs ][ $sPermission ], $iIndex, 1, array( $sNewGroup ) ); } } } - $result = PermissionManager::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown); + $result = PermissionManager::writeGroupSettings( $wgGroupPermissions, $wgNamespacePermissionLockdown ); return true; } - public function onBSGroupManagerGroupDeleted($sGroup, &$result) { + public function onBSGroupManagerGroupDeleted( $sGroup, &$result ) { global $wgGroupPermissions, $wgNamespacePermissionLockdown; - unset($wgGroupPermissions[$sGroup]); + unset( $wgGroupPermissions[ $sGroup ] ); - foreach ($wgNamespacePermissionLockdown as $iNS => $aPermissions) { - foreach ($aPermissions as $sPermission => $aGroups) { - $iIndex = array_search($sGroup, $aGroups); - if ($iIndex !== false) { - if (count($aGroups) == 1) { - unset($wgNamespacePermissionLockdown[$iNS][$sPermission]); + foreach ( $wgNamespacePermissionLockdown as $iNS => $aPermissions ) { + foreach ( $aPermissions as $sPermission => $aGroups ) { + $iIndex = array_search( $sGroup, $aGroups ); + if ( $iIndex !== false ) { + if ( count( $aGroups ) == 1 ) { + unset( $wgNamespacePermissionLockdown[ $iNS ][ $sPermission ] ); } else { - array_splice($wgNamespacePermissionLockdown[$iNS][$sPermission], $iIndex, 1); + array_splice( $wgNamespacePermissionLockdown[ $iNS ][ $sPermission ], $iIndex, 1 ); } } } } - $result = PermissionManager::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown); + $result = PermissionManager::writeGroupSettings( $wgGroupPermissions, $wgNamespacePermissionLockdown ); return true; } - public function onBSWikiAdminUserManagerBeforeUserListSend($oUserManager, &$data) { - if (!BsConfig::get('MW::PermissionManager::Lockmode')) + public function onBSWikiAdminUserManagerBeforeUserListSend( $oUserManager, &$data ) { + if ( !BsConfig::get( 'MW::PermissionManager::Lockmode' ) ) return true; - foreach ($data['users'] as $keyname => $aUser) { - foreach ($aUser as $index => $value) { - if (is_array($value)) { - foreach ($value as $indexof => $val) { - if (is_array($val)) { - foreach ($val as $indexname => $groupName) { - if ($indexname == 'group') { - if ($groupName == BsGroupHelper::getLockModeGroup()) { - unset($data['users'][$keyname][$index][$indexof]); - $data['users'][$keyname][$index] = array_values($data['users'][$keyname][$index]); + foreach ( $data[ 'users' ] as $keyname => $aUser ) { + foreach ( $aUser as $index => $value ) { + if ( is_array( $value ) ) { + foreach ( $value as $indexof => $val ) { + if ( is_array( $val ) ) { + foreach ( $val as $indexname => $groupName ) { + if ( $indexname == 'group' ) { + if ( $groupName == BsGroupHelper::getLockModeGroup() ) { + unset( $data[ 'users' ][ $keyname ][ $index ][ $indexof ] ); + $data[ 'users' ][ $keyname ][ $index ] = array_values( $data[ 'users' ][ $keyname ][ $index ] ); } } } @@ -171,61 +172,84 @@ public static function setupLockmodePermissions() { global $wgAdditionalGroups, $wgGroupPermissions, $wgNamespacePermissionLockdown; - if (!BsConfig::get('MW::PermissionManager::Lockmode')) { - $bSave = false; - if (isset($wgGroupPermissions[self::$sPmLockModeGroup]) && !empty($wgGroupPermissions[self::$sPmLockModeGroup]) ) { - unset($wgGroupPermissions[self::$sPmLockModeGroup]); + + // return directly if the settings got already checked in this session and the state of Lockmode didn't change. + $oRequest = RequestContext::getMain()->getRequest(); + $bLockmodeActive = BsConfig::get( 'MW::PermissionManager::Lockmode' ); + if ( $oRequest->getSessionData( 'bsLockmodeIsSetup' ) === $bLockmodeActive ) { + return true; + } + $oRequest->setSessionData( 'bsLockmodeIsSetup', $bLockmodeActive ); + + $bSave = false; + + if ( !$bLockmodeActive ) { + if ( isset( $wgGroupPermissions[ self::$sPmLockModeGroup ] ) && !empty( $wgGroupPermissions[ self::$sPmLockModeGroup ] ) ) { + unset( $wgGroupPermissions[ self::$sPmLockModeGroup ] ); $bSave = true; } if ( is_array( $wgNamespacePermissionLockdown ) ) { - foreach ($wgNamespacePermissionLockdown as $iNsIndex => $aNsRights) { - foreach ($aNsRights as $sRight => $aGroups) { - if (!in_array(self::$sPmLockModeGroup, $aGroups)) + foreach ( $wgNamespacePermissionLockdown as $iNsIndex => $aNsRights ) { + foreach ( $aNsRights as $sRight => $aGroups ) { + if ( !in_array( self::$sPmLockModeGroup, $aGroups ) ) continue; - $key = array_search(self::$sPmLockModeGroup, $aGroups); - if ($key !== false) { - unset($wgNamespacePermissionLockdown[$iNsIndex][$sRight][$key]); - if (empty($wgNamespacePermissionLockdown[$iNsIndex][$sRight])) { - unset($wgNamespacePermissionLockdown[$iNsIndex][$sRight]); + $key = array_search( self::$sPmLockModeGroup, $aGroups ); + if ( $key !== false ) { + unset( $wgNamespacePermissionLockdown[ $iNsIndex ][ $sRight ][ $key ] ); + if ( empty( $wgNamespacePermissionLockdown[ $iNsIndex ][ $sRight ] ) ) { + unset( $wgNamespacePermissionLockdown[ $iNsIndex ][ $sRight ] ); } $bSave = true; } } - if (empty($wgNamespacePermissionLockdown[$iNsIndex])) { - unset($wgNamespacePermissionLockdown[$iNsIndex]); + if ( empty( $wgNamespacePermissionLockdown[ $iNsIndex ] ) ) { + unset( $wgNamespacePermissionLockdown[ $iNsIndex ] ); } } } - if ($bSave) { - self::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown); + if ( $bSave ) { + self::writeGroupSettings( $wgGroupPermissions, $wgNamespacePermissionLockdown ); } return true; } - $wgAdditionalGroups[self::$sPmLockModeGroup] = array(); - foreach (BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_MEDIA, NS_SPECIAL)) as $nsKey => $nsName) { + $wgAdditionalGroups[ self::$sPmLockModeGroup ] = array(); + foreach ( BsNamespaceHelper::getNamespacesForSelectOptions( array( NS_MEDIA, NS_SPECIAL ) ) as $nsKey => $nsName ) { // skip mediawiki namespaces - if (BsConfig::get('MW::PermissionManager::SkipSystemNS') && $nsKey <= 15) { + if ( BsConfig::get( 'MW::PermissionManager::SkipSystemNS' ) && $nsKey <= 15 ) { continue; } + if ( !isset( $wgGroupPermissions[ self::$sPmLockModeGroup ] ) ) { + $wgGroupPermissions[ self::$sPmLockModeGroup ] = array(); + } + $aAvailablePermissions = User::getAllRights(); - foreach ($aAvailablePermissions as $permissionName) { - $wgGroupPermissions[self::$sPmLockModeGroup][$permissionName] = true; - if (isset($wgNamespacePermissionLockdown[$nsKey][$permissionName])) { - $wgNamespacePermissionLockdown[$nsKey][$permissionName] = array_unique( - array_merge($wgNamespacePermissionLockdown[$nsKey][$permissionName], array(self::$sPmLockModeGroup) - ) - ); + foreach ( $aAvailablePermissions as $permissionName ) { + if ( !isset( $wgGroupPermissions[ self::$sPmLockModeGroup ][ $permissionName ] ) ) { + $wgGroupPermissions[ self::$sPmLockModeGroup ][ $permissionName ] = true; + $bSave = true; + } + if ( isset( $wgNamespacePermissionLockdown[ $nsKey ][ $permissionName ] ) ) { + if ( !in_array( self::$sPmLockModeGroup, $wgNamespacePermissionLockdown[ $nsKey ][ $permissionName ] ) ) { + $wgNamespacePermissionLockdown[ $nsKey ][ $permissionName ] = array_unique( + array_merge( $wgNamespacePermissionLockdown[ $nsKey ][ $permissionName ], array( self::$sPmLockModeGroup ) + ) + ); + $bSave = true; + } } else { - $wgNamespacePermissionLockdown[$nsKey][$permissionName] = array(self::$sPmLockModeGroup); + $wgNamespacePermissionLockdown[ $nsKey ][ $permissionName ] = array( self::$sPmLockModeGroup ); + $bSave = true; } } } - self::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown); + if ( $bSave ) { + self::writeGroupSettings( $wgGroupPermissions, $wgNamespacePermissionLockdown ); + } return true; } @@ -233,65 +257,65 @@ public function getForm() { global $wgImplicitGroups, $wgGroupPermissions, $wgNamespacePermissionLockdown; - $this->getOutput()->addModules('ext.bluespice.permissionManager'); + $this->getOutput()->addModules( 'ext.bluespice.permissionManager' ); $aGroups = array( - 'text' => '*', - 'builtin' => true, - 'implicit' => true, - 'expanded' => true, - 'children' => array( - array( - 'text' => 'user', - 'builtin' => true, - 'implicit' => true, - 'expanded' => true, - 'children' => array() + 'text' => '*', + 'builtin' => true, + 'implicit' => true, + 'expanded' => true, + 'children' => array( + array( + 'text' => 'user', + 'builtin' => true, + 'implicit' => true, + 'expanded' => true, + 'children' => array() + ) ) - ) ); $aExplicitGroups = BsGroupHelper::getAvailableGroups( - array('blacklist' => $wgImplicitGroups) + array( 'blacklist' => $wgImplicitGroups ) ); - sort($aExplicitGroups); + sort( $aExplicitGroups ); $aExplicitGroupNodes = array(); - foreach ($aExplicitGroups as $sExplicitGroup) { + foreach ( $aExplicitGroups as $sExplicitGroup ) { $aExplicitGroupNode = array( - 'text' => $sExplicitGroup, - 'leaf' => true + 'text' => $sExplicitGroup, + 'leaf' => true ); - if (in_array($sExplicitGroup, self::$aBuiltInGroups)) { - $aExplicitGroupNode['builtin'] = true; + if ( in_array( $sExplicitGroup, self::$aBuiltInGroups ) ) { + $aExplicitGroupNode[ 'builtin' ] = true; } $aExplicitGroupNodes[] = $aExplicitGroupNode; } - $aGroups['children'][0]['children'] = $aExplicitGroupNodes; + $aGroups[ 'children' ][ 0 ][ 'children' ] = $aExplicitGroupNodes; $aJsVars = array( - 'bsPermissionManagerGroupsTree' => $aGroups, - 'bsPermissionManagerNamespaces' => self::buildNamespaceMetadata(), - 'bsPermissionManagerRights' => self::buildRightsMetadata(), - 'bsPermissionManagerGroupPermissions' => $wgGroupPermissions, - 'bsPermissionManagerPermissionLockdown' => $wgNamespacePermissionLockdown, - 'bsPermissionManagerPermissionTemplates' => self::getTemplateRules() + 'bsPermissionManagerGroupsTree' => $aGroups, + 'bsPermissionManagerNamespaces' => self::buildNamespaceMetadata(), + 'bsPermissionManagerRights' => self::buildRightsMetadata(), + 'bsPermissionManagerGroupPermissions' => $wgGroupPermissions, + 'bsPermissionManagerPermissionLockdown' => $wgNamespacePermissionLockdown, + 'bsPermissionManagerPermissionTemplates' => self::getTemplateRules() ); - wfRunHooks('BsPermissionManager::beforeLoadPermissions', array(&$aJsVars)); + wfRunHooks( 'BsPermissionManager::beforeLoadPermissions', array( &$aJsVars ) ); //Make sure a new group without any explicit permissions is converted into an object! //Without any key => value it would be converted into an empty array. - foreach( $aJsVars['bsPermissionManagerGroupPermissions'] as $sGroup => $aPermissions ) { - if( !empty($aPermissions) ) continue; - $aJsVars['bsPermissionManagerGroupPermissions'][$sGroup] = (object) array(); + foreach ( $aJsVars[ 'bsPermissionManagerGroupPermissions' ] as $sGroup => $aPermissions ) { + if ( !empty( $aPermissions ) ) continue; + $aJsVars[ 'bsPermissionManagerGroupPermissions' ][ $sGroup ] = (object)array(); } - $this->getOutput()->addJsConfigVars($aJsVars); + $this->getOutput()->addJsConfigVars( $aJsVars ); return '<div id="panelPermissionManager" style="height: 500px"></div>'; } @@ -300,24 +324,24 @@ global $wgLang; $aNamespaces = $wgLang->getNamespaces(); - ksort($aNamespaces); + ksort( $aNamespaces ); $aMetadata = array(); - foreach ($aNamespaces as $iNSId => $sLocalizedNSText) { - if( $iNSId < 0 ) { //Filter pseudo namespaces + foreach ( $aNamespaces as $iNSId => $sLocalizedNSText ) { + if ( $iNSId < 0 ) { //Filter pseudo namespaces continue; } - $sNsText = str_replace('_', ' ', $sLocalizedNSText); - if( $iNSId == NS_MAIN ) { - $sNsText = wfMessage('bs-ns_main')->text(); + $sNsText = str_replace( '_', ' ', $sLocalizedNSText ); + if ( $iNSId == NS_MAIN ) { + $sNsText = wfMessage( 'bs-ns_main' )->text(); } $aMetadata[] = array( - 'id' => $iNSId, - 'name' => $sNsText, - 'hideable' => $iNSId !== NS_MAIN + 'id' => $iNSId, + 'name' => $sNsText, + 'hideable' => $iNSId !== NS_MAIN ); } @@ -338,19 +362,19 @@ natsort( $aRights ); if ( is_array( $aRights ) ) { foreach ( $aRights as $sRight ) { - if ( !isset( $bsgPermissionConfig[$sRight] ) ) { - $bsgPermissionConfig[$sRight] = array( - 'type' => 'namespace' + if ( !isset( $bsgPermissionConfig[ $sRight ] ) ) { + $bsgPermissionConfig[ $sRight ] = array( + 'type' => 'namespace' ); } - $aConfig = $bsgPermissionConfig[$sRight]; - $bGlobalPermission = (isset($aConfig['type']) && $aConfig['type'] == 'global') ? true : false; + $aConfig = $bsgPermissionConfig[ $sRight ]; + $bGlobalPermission = ( isset( $aConfig[ 'type' ] ) && $aConfig[ 'type' ] == 'global' ) ? true : false; $aMetadata[] = array( - 'right' => $sRight, - 'type' => $bGlobalPermission ? 2 : 1, - 'typeHeader' => $bGlobalPermission - ? wfMessage('bs-permissionmanager-grouping-global')->plain() - : wfMessage('bs-permissionmanager-grouping-local')->plain() + 'right' => $sRight, + 'type' => $bGlobalPermission ? 2 : 1, + 'typeHeader' => $bGlobalPermission + ? wfMessage( 'bs-permissionmanager-grouping-global' )->plain() + : wfMessage( 'bs-permissionmanager-grouping-local' )->plain() ); } } @@ -362,55 +386,55 @@ public static function setTemplateData() { global $wgRequest; - $dbw = wfGetDB(DB_WRITE); - $oTemplate = $data = FormatJson::decode($wgRequest->getVal('template', '{}')); + $dbw = wfGetDB( DB_WRITE ); + $oTemplate = $data = FormatJson::decode( $wgRequest->getVal( 'template', '{}' ) ); $iId = $oTemplate->id + 0; - $sName = $dbw->strencode($oTemplate->text); + $sName = $dbw->strencode( $oTemplate->text ); $aPermissions = $oTemplate->ruleSet; - $sDescription = $dbw->strencode($oTemplate->description); + $sDescription = $dbw->strencode( $oTemplate->description ); - if ($iId == 0) { - $bSaveResult = PermissionTemplates::addTemplate($sName, $aPermissions, $sDescription); + if ( $iId == 0 ) { + $bSaveResult = PermissionTemplates::addTemplate( $sName, $aPermissions, $sDescription ); } else { - $bSaveResult = PermissionTemplates::editTemplate($iId, $sName, $aPermissions, $sDescription); + $bSaveResult = PermissionTemplates::editTemplate( $iId, $sName, $aPermissions, $sDescription ); } $aResult = array( - 'success' => false, - 'msg' => '' + 'success' => false, + 'msg' => '' ); - if ($bSaveResult) { - $aResult['success'] = true; + if ( $bSaveResult ) { + $aResult[ 'success' ] = true; } else { - $aResult['msg'] = wfMessage('bs-permissionmanager-msgtpled-savefailure')->plain(); + $aResult[ 'msg' ] = wfMessage( 'bs-permissionmanager-msgtpled-savefailure' )->plain(); } - return json_encode($aResult); + return json_encode( $aResult ); } public static function deleteTemplate() { global $wgRequest; - $iId = $wgRequest->getInt('id', 0); + $iId = $wgRequest->getInt( 'id', 0 ); - if ($iId) { - $bDeleteResult = PermissionTemplates::removeTemplate($iId); + if ( $iId ) { + $bDeleteResult = PermissionTemplates::removeTemplate( $iId ); } else { $bDeleteResult = false; } $aResult = array( - 'success' => false, - 'msg' => '' + 'success' => false, + 'msg' => '' ); - if ($bDeleteResult) { - $aResult['success'] = true; + if ( $bDeleteResult ) { + $aResult[ 'success' ] = true; } else { - $aResult['msg'] = wfMessage('bs-permissionmanager-msgtpled-deletefail')->plain(); + $aResult[ 'msg' ] = wfMessage( 'bs-permissionmanager-msgtpled-deletefail' )->plain(); } - return json_encode($aResult); + return json_encode( $aResult ); } /** @@ -419,29 +443,29 @@ */ public static function savePermissions() { global $wgRequest; - $data = FormatJson::decode($wgRequest->getVal('data', '{}'), true); + $data = FormatJson::decode( $wgRequest->getVal( 'data', '{}' ), true ); - if(!is_array($data) || !isset($data['groupPermission']) || !isset($data['permissionLockdown'])) { - return json_encode(array( - 'success' => false, - 'msg' => 'NO VALID DATA' - )); + if ( !is_array( $data ) || !isset( $data[ 'groupPermission' ] ) || !isset( $data[ 'permissionLockdown' ] ) ) { + return json_encode( array( + 'success' => false, + 'msg' => 'NO VALID DATA' + ) ); } - $aGroupPermissions = $data['groupPermission']; - $aLockdown = $data['permissionLockdown']; - $mStatus = wfRunHooks('BsPermissionManager::beforeSavePermissions', array(&$aLockdown, &$aGroupPermissions)); + $aGroupPermissions = $data[ 'groupPermission' ]; + $aLockdown = $data[ 'permissionLockdown' ]; + $mStatus = wfRunHooks( 'BsPermissionManager::beforeSavePermissions', array( &$aLockdown, &$aGroupPermissions ) ); - if($mStatus === true) { + if ( $mStatus === true ) { return FormatJson::encode( - self::writeGroupSettings( $aGroupPermissions, $aLockdown ) + self::writeGroupSettings( $aGroupPermissions, $aLockdown ) ); } else { return FormatJson::encode( - array( - 'success' => false, - 'msg' => $mStatus - ) + array( + 'success' => false, + 'msg' => $mStatus + ) ); } } @@ -459,17 +483,17 @@ return; } foreach ( $aRights as $sRight ) { - if ( isset( $bsgPermissionConfig[$sRight]['preventLockout'] ) ) { + if ( isset( $bsgPermissionConfig[ $sRight ][ 'preventLockout' ] ) ) { $bIsSet = false; if ( is_array( $aGroupPermissions ) ) { foreach ( $aGroupPermissions as $aDataset ) { - if ( isset( $aDataset[$sRight] ) && $aDataset[$sRight] ) { + if ( isset( $aDataset[ $sRight ] ) && $aDataset[ $sRight ] ) { $bIsSet = true; continue; } } if ( !$bIsSet ) { - $aGroupPermissions['sysop'][$sRight] = true; + $aGroupPermissions[ 'sysop' ][ $sRight ] = true; } } } @@ -481,76 +505,76 @@ $aOutput = array(); /* @var $oTemplate PermissionTemplates */ - foreach ($aTemplates as $oTemplate) { + foreach ( $aTemplates as $oTemplate ) { $aOutput[] = array( - 'id' => $oTemplate->getId(), - 'text' => $oTemplate->getName(), - 'leaf' => true, - 'description' => $oTemplate->getDescription(), - 'ruleSet' => $oTemplate->getPermissions() + 'id' => $oTemplate->getId(), + 'text' => $oTemplate->getName(), + 'leaf' => true, + 'description' => $oTemplate->getDescription(), + 'ruleSet' => $oTemplate->getPermissions() ); } return $aOutput; } - protected static function writeGroupSettings($aGroupPermissions, $aNamespacePermissionLockdown) { + protected static function writeGroupSettings( $aGroupPermissions, $aNamespacePermissionLockdown ) { global $bsgPermissionManagerGroupSettingsFile; - if (wfReadOnly()) { + if ( wfReadOnly() ) { global $wgReadOnly; return array( - 'success' => false, - 'msg' => wfMessage('bs-readonly', $wgReadOnly)->plain() + 'success' => false, + 'msg' => wfMessage( 'bs-readonly', $wgReadOnly )->plain() ); } - if (BsCore::checkAccessAdmission('wikiadmin') === false) + if ( BsCore::checkAccessAdmission( 'wikiadmin' ) === false ) return true; - wfRunHooks('BsNamespacemanageOnSavePermission', array(&$aNamespacePermissionLockdown, &$aGroupPermissions)); - wfRunHooks('BsPermissionManager::writeGroupSettings', array(&$aNamespacePermissionLockdown, &$aGroupPermissions)); + wfRunHooks( 'BsNamespacemanageOnSavePermission', array( &$aNamespacePermissionLockdown, &$aGroupPermissions ) ); + wfRunHooks( 'BsPermissionManager::writeGroupSettings', array( &$aNamespacePermissionLockdown, &$aGroupPermissions ) ); self::backupExistingSettings(); $sSaveContent = "<?php\n"; - foreach ($aGroupPermissions as $sGroup => $aPermissions) { - foreach ($aPermissions as $sPermission => $bValue) { - $sSaveContent .= "\$wgGroupPermissions['{$sGroup}']['{$sPermission}'] = " . ($bValue ? 'true' : 'false') . ";\n"; + foreach ( $aGroupPermissions as $sGroup => $aPermissions ) { + foreach ( $aPermissions as $sPermission => $bValue ) { + $sSaveContent .= "\$wgGroupPermissions['{$sGroup}']['{$sPermission}'] = " . ( $bValue ? 'true' : 'false' ) . ";\n"; } } - if (is_array($aNamespacePermissionLockdown)) { - foreach ($aNamespacePermissionLockdown as $iNS => $aPermissions) { + if ( is_array( $aNamespacePermissionLockdown ) ) { + foreach ( $aNamespacePermissionLockdown as $iNS => $aPermissions ) { $isReadLockdown = false; $sNsCanonicalName = MWNamespace::getCanonicalName( $iNS ); - if( $iNS == NS_MAIN ) { + if ( $iNS == NS_MAIN ) { $sNsCanonicalName = 'MAIN'; } - $sNsConstant = 'NS_'.strtoupper( $sNsCanonicalName ); - foreach ($aPermissions as $sPermission => $aGroups) { - if( empty( $aGroups ) ) { + $sNsConstant = 'NS_' . strtoupper( $sNsCanonicalName ); + foreach ( $aPermissions as $sPermission => $aGroups ) { + if ( empty( $aGroups ) ) { continue; } $sSaveContent .= "\$wgNamespacePermissionLockdown[$sNsConstant]['$sPermission']" - . " = array(" . (count($aGroups) ? "'" . implode("','", $aGroups) . "'" : '') . ");\n"; - if ($sPermission == 'read') { + . " = array(" . ( count( $aGroups ) ? "'" . implode( "','", $aGroups ) . "'" : '' ) . ");\n"; + if ( $sPermission == 'read' ) { $isReadLockdown = true; } } - if ($isReadLockdown) { + if ( $isReadLockdown ) { $sSaveContent .= "\$wgNonincludableNamespaces[] = $sNsConstant;\n"; } } } - $res = file_put_contents($bsgPermissionManagerGroupSettingsFile, $sSaveContent); - if ($res) { - return array('success' => true); + $res = file_put_contents( $bsgPermissionManagerGroupSettingsFile, $sSaveContent ); + if ( $res ) { + return array( 'success' => true ); } else { return array( - 'success' => false, + 'success' => false, // TODO SU (04.07.11 12:06): i18n - 'msg' => 'Not able to create or write "' . $bsgPermissionManagerGroupSettingsFile . '".' + 'msg' => 'Not able to create or write "' . $bsgPermissionManagerGroupSettingsFile . '".' ); } } @@ -563,10 +587,10 @@ protected static function backupExistingSettings() { global $bsgPermissionManagerGroupSettingsFile; - if( file_exists( $bsgPermissionManagerGroupSettingsFile ) ) { + if ( file_exists( $bsgPermissionManagerGroupSettingsFile ) ) { $timestamp = wfTimestampNow(); $backupFilename = "pm-settings-backup-{$timestamp}.php"; - $backupFile = dirname( $bsgPermissionManagerGroupSettingsFile )."/{$backupFilename}"; + $backupFile = dirname( $bsgPermissionManagerGroupSettingsFile ) . "/{$backupFilename}"; file_put_contents( $backupFile, file_get_contents( $bsgPermissionManagerGroupSettingsFile ) ); } -- To view, visit https://gerrit.wikimedia.org/r/235411 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I83ecc91d58e1f3efba2451f5945b2ec999f9af2c Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Lilu <o0lilu0o1...@gmail.com> Gerrit-Reviewer: Dvogel hallowelt <daniel.vo...@hallowelt.com> Gerrit-Reviewer: Jgoettlich <goettl...@hallowelt.biz> Gerrit-Reviewer: Lilu <o0lilu0o1...@gmail.com> Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pigpen <reym...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: Tweichart <weich...@hallowelt.biz> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits