/**
  * Return a instance of SearchService.
  * @return SearchService Instance of SearchService
  */
 public static function getInstance()
 {
     wfProfileIn('BS::' . __METHOD__);
     if (self::$oInstance === null) {
         if (PHP_SAPI === 'cli') {
             $oDbr = wfGetDB(DB_SLAVE);
             if ($oDbr->tableExists('bs_settings')) {
                 BsConfig::loadSettings();
             }
         }
         $aUrl = parse_url(BsConfig::get('MW::ExtendedSearch::SolrServiceUrl'));
         if (empty($aUrl['host']) || empty($aUrl['port']) || empty($aUrl['path'])) {
             wfProfileOut('BS::' . __METHOD__);
             throw new Exception('Creating instance of ' . __CLASS__ . ' not possible with these params:' . ', $host=' . (isset($aUrl['host']) ? $aUrl['host'] : '') . ', $port=' . (isset($aUrl['port']) ? $aUrl['port'] : '') . ', $path=' . (isset($aUrl['path']) ? $aUrl['path'] : ''));
         }
         $oServer = new self($aUrl['scheme'], $aUrl['host'], $aUrl['port'], $aUrl['path']);
         self::$oInstance = $oServer;
         wfProfileOut('BS::' . __METHOD__);
         return $oServer;
     }
     wfProfileOut('BS::' . __METHOD__);
     return self::$oInstance;
 }
 /**
  * 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;
 }