/**
 * Initalize the settings stored in a serialized file.
 * This have to be done before the end of LocalSettings.php but is in a function
 * because administrators might configure some settings between the moment where
 * the file is loaded and the execution of these function.
 * Settings are not filled only if they doesn't exists because of a security
 * hole if the register_globals feature of PHP is enabled.
 *
 * @param $wiki String
 */
function efConfigureSetup($wiki = 'default')
{
    global $wgConf, $wgConfigureFilesPath, $wgConfigureExtDir, $wgConfigureHandler, $wgConfigureAllowDeferSetup;
    wfProfileIn(__FUNCTION__);
    # Create the new configuration object...
    $oldConf = $wgConf;
    require_once dirname(__FILE__) . '/Configure.obj.php';
    $wgConf = new WebConfiguration($wiki, $wgConfigureFilesPath);
    # Copy the existing settings...
    $wgConf->suffixes = $oldConf->suffixes;
    $wgConf->wikis = $oldConf->wikis;
    $wgConf->settings = $oldConf->settings;
    $wgConf->localVHosts = $oldConf->localVHosts;
    $wgConf->siteParamsCallback = $oldConf->siteParamsCallback;
    $wgConf->snapshotDefaults();
    if ($wgConfigureAllowDeferSetup && $wgConfigureHandler == 'db') {
        // Defer to after caches and database are set up.
        global $wgExtensionFunctions;
        $wgExtensionFunctions[] = 'efConfigureInitialise';
    } else {
        efConfigureInitialise();
    }
    # Cleanup $wgConfigureExtDir as needed
    if (substr($wgConfigureExtDir, -1) != '/' && substr($wgConfigureExtDir, -1) != '\\') {
        $wgConfigureExtDir .= '/';
    }
    wfProfileOut(__FUNCTION__);
}
/**
 * Initalize the settings stored in a serialized file.
 * This have to be done before the end of LocalSettings.php but is in a function
 * because administrators might configure some settings between the moment where
 * the file is loaded and the execution of these function.
 * Settings are not filled only if they doesn't exists because of a security
 * hole if the register_globals feature of PHP is enabled.
 *
 * @param String $wiki
 */
function efConfigureSetup($wiki = 'default')
{
    global $wgConf, $wgConfigureFilesPath;
    # Create the new configuration object...
    $oldConf = $wgConf;
    require_once dirname(__FILE__) . '/Configure.obj.php';
    $wgConf = new WebConfiguration($wiki, $wgConfigureFilesPath);
    # Copy the existing settings...
    $wgConf->suffixes = $oldConf->suffixes;
    $wgConf->wikis = $oldConf->wikis;
    $wgConf->settings = $oldConf->settings;
    $wgConf->localVHosts = $oldConf->localVHosts;
    # Load the new configuration, and fill in the settings
    $wgConf->initialise();
    $wgConf->extract();
}
 /**
  * Process a diff for one setting
  *
  * @param $name String: setting name
  * @patam $old Mixed: old value
  * @param $new Mixed: new value
  * @param $type String: setting type
  * @return String: XHTML
  */
 function processDiffSetting($name, $old, $new, $type)
 {
     $msg = $this->msg('configure-setting-' . $name);
     $rawVal = Xml::element('tt', null, "\${$name}");
     if ($msg->exists()) {
         $msgVal = $msg->parse() . " ({$rawVal})";
     } else {
         $msgVal = $rawVal;
     }
     $oldSet = $this->getSettingAsArray(WebConfiguration::filterVar($old), $name, $type);
     $newSet = $this->getSettingAsArray(WebConfiguration::filterVar($new), $name, $type);
     $diffs = new Diff($oldSet, $newSet);
     $formatter = new TableDiffFormatter();
     return "<tr><td class=\"diff-lineno configure-setting\" colspan=\"4\">{$msgVal}</td></tr>\n" . $formatter->format($diffs);
 }
 /**
  * Really build the content of the form
  *
  * @param $settings array
  * @param $params array
  * @return xhtml
  */
 protected function buildSettings($settings, $param = array())
 {
     global $wgConf;
     $defaults = $wgConf->getDefaultsForWiki($this->mWiki);
     $ret = '';
     $perms = array();
     $notEditableSet = $this->getUneditableSettings();
     foreach ($settings as $title => $groups) {
         $res = true;
         if (!isset($param['restrict'])) {
             $res = true;
         } elseif (is_array($param['restrict'])) {
             if (isset($param['restrict'][$title])) {
                 $res = $param['restrict'][$title];
             } elseif (isset($param['restrict']['_default'])) {
                 $res = $param['restrict']['_default'];
             } else {
                 $res = true;
             }
         } else {
             $res = (bool) $param['restrict'];
         }
         foreach ($groups as $name => $sect) {
             foreach ($sect as $setting => $unused) {
                 if (in_array($setting, $notEditableSet)) {
                     unset($groups[$name][$setting]);
                     continue;
                 }
                 $read = $this->userCanRead($setting);
                 $edit = $this->userCanEdit($setting);
                 if ($this->mCanEdit ? $edit : $read) {
                     $res = false;
                 }
                 $perms[$setting] = array('read' => $read, 'edit' => $edit);
             }
             if (!count($groups[$name])) {
                 unset($groups[$name]);
             }
         }
         $thisSection = '';
         if (!$res) {
             if (!isset($param['showlink'])) {
                 $showlink = true;
             } elseif (is_array($param['showlink'])) {
                 if (isset($param['showlink'][$title])) {
                     $showlink = $param['showlink'][$title];
                 } elseif (isset($param['showlink']['_default'])) {
                     $showlink = $param['showlink']['_default'];
                 } else {
                     $showlink = true;
                 }
             } else {
                 $showlink = (bool) $param['showlink'];
             }
             foreach ($groups as $group => $settings) {
                 $thisGroup = '';
                 foreach ($settings as $setting => $type) {
                     $params = $perms[$setting] + array('type' => $type, 'value' => $this->getSettingValue($setting), 'link' => $showlink);
                     $customised = !array_key_exists($setting, $defaults);
                     $customised = $customised || WebConfiguration::filterVar($defaults[$setting]) != WebConfiguration::filterVar($params['value']);
                     $params['customised'] = $customised;
                     $show = $this->mCanEdit ? isset($params['edit']) ? $params['edit'] : $this->userCanEdit($setting) : (isset($params['read']) ? $params['read'] : $this->userCanRead($setting));
                     $show = $show && $this->isSettingAvailable($setting);
                     if ($show) {
                         $thisGroup .= $this->buildTableRow($setting, $params);
                     } else {
                         ## Don't even show it.
                     }
                 }
                 if ($thisGroup) {
                     $thisSection .= $this->buildTableHeading($group) . $thisGroup . Html::closeElement('table');
                 }
             }
             if ($thisSection) {
                 $thisSection = Html::rawElement('legend', null, $this->msg("configure-section-{$title}")->parse()) . $thisSection;
                 $ret .= Html::rawElement('fieldset', null, $thisSection);
             }
         }
     }
     return $ret;
 }