/** * returns the formular for Preferences * @return string the formular string */ public function getForm() { if (wfReadOnly()) { throw new ReadOnlyError(); } $this->getOutput()->addModuleScripts('ext.bluespice.preferences'); $this->getOutput()->addHTML('<br />'); $oRequest = $this->getRequest(); if ($this->getRequest()->getVal('success') == true) { $this->getOutput()->wrapWikiMsg('<div class="successbox"><strong>$1</strong></div><div id="mw-pref-clear"></div>' . "\n", 'savedprefs'); } $orig_deliver = BsConfig::deliverUsersSettings(false); BsConfig::loadSettings(); BsExtensionManager::getExtensionInformation(); $vars = BsConfig::getRegisteredVars(); $bShowall = $oRequest->getFuzzyBool('showall'); if ($bShowall) { $out = ''; foreach ($vars as $var) { $out .= $var->getAdapter() . "::"; if ($var->getExtension() !== null) { $out .= $var->getExtension() . "::"; } $out .= $var->getName() . "<br>"; } return $out; } $preferences = array(); $aSortedVariables = array(); foreach ($vars as $var) { $options = $var->getOptions(); if (!($options & (BsConfig::LEVEL_PUBLIC | BsConfig::LEVEL_USER))) { continue; } if ($options & BsConfig::NO_DEFAULT) { continue; } $extension = $var->getI18nExtension() ? $var->getI18nExtension() : 'BASE'; $aSortedVariables[$extension][] = $var; } foreach ($aSortedVariables as $sExtensionName => $aExtensions) { if (!count($aExtensions)) { continue; } foreach ($aExtensions as $oVariable) { // if continue, then $oAdapterSetView is not added to output if (!count($oVariable)) { continue; } $sSection = $sExtensionName; $oExtension = BsExtensionManager::getExtension($sExtensionName); $field = $oVariable->getFieldDefinition($sSection); if ($oVariable->getOptions() & BsConfig::USE_PLUGIN_FOR_PREFS) { $oExtension = BsExtensionManager::getExtension($sExtensionName); $tmp = $oExtension->runPreferencePlugin('MW', $oVariable); $field = array_merge($field, $tmp); } $preferences[$oVariable->generateFieldId()] = $field; } } BsConfig::deliverUsersSettings($orig_deliver); $oForm = new HTMLFormEx($preferences, 'prefs'); $oForm->setTitle($this->getTitle()); $oForm->addHiddenField('mode', 'Preferences'); $oForm->setSubmitText(wfMessage('bs-extjs-save')->plain()); $oForm->setSubmitName('WikiAdminPreferencesSubmit'); $oForm->setSubmitCallback(array($this, 'savePreferences')); $oForm->show(); $this->getOutput()->addHTML('<br />'); return ''; }
/** * Hook handler for UserSaveOptions * @param User $user User whose options are being modified. * @param Array &$options Options array * @return true always true to keep hook alive */ public function onUserSaveOptions($user, &$options) { BsConfig::loadSettings(); $oCurrentTitle = $this->getTitle(); //May return null in CLI if ($oCurrentTitle instanceof Title && $oCurrentTitle->isSpecialPage()) { $bDeliverUserSettings = true; } else { $bDeliverUserSettings = false; } $bOrigDeliver = BsConfig::deliverUsersSettings($bDeliverUserSettings); $aRegisteredVariables = BsConfig::getRegisteredVars(); $aSortedVariables = array(); foreach ($aRegisteredVariables as $oVariable) { $iOptions = $oVariable->getOptions(); if (!($iOptions & BsConfig::LEVEL_USER)) { continue; } if ($bDeliverUserSettings === false) { if ($iOptions & BsConfig::NO_DEFAULT) { continue; } } $sAdapterName = strtoupper($oVariable->getAdapter()); $sExtensionName = $oVariable->getExtension(); if (empty($sExtensionName)) { $sExtensionName = 'BASE'; } $aSortedVariables[$sAdapterName][$sExtensionName][] = $oVariable; } foreach ($aSortedVariables as $sAdapterName => $aExtensions) { if (!count($aExtensions)) { continue; } foreach ($aExtensions as $sExtensionName => $aSettings) { // if continue, then $oAdapterSetView is not added to output if (!count($aSettings)) { continue; } foreach ($aSettings as $oVariable) { //Avoid "undefined index" notices and weird NULL values in settings $value = $oVariable->getValue(); if (isset($options[$oVariable->generateFieldId()])) { //Set but no bool $value = $options[$oVariable->generateFieldId()]; } if (isset($options[$oVariable->getKey()])) { //Set but no bool $value = $options[$oVariable->getKey()]; } $options[$oVariable->getKey()] = BsStringHelper::isSerialized($value) ? $value : serialize($value); unset($options[$oVariable->generateFieldId()]); } } } BsConfig::deliverUsersSettings($bOrigDeliver); return true; }