コード例 #1
0
 /**
  * Return an associative array mapping preferences keys to the kind of a preference they're
  * used for. Different kinds are handled differently when setting or reading preferences.
  *
  * See User::listOptionKinds for the list of valid option types that can be provided.
  *
  * @see User::listOptionKinds
  * @param IContextSource $context
  * @param array $options Assoc. array with options keys to check as keys.
  *   Defaults to $this->mOptions.
  * @return array The key => kind mapping data
  */
 public function getOptionKinds(IContextSource $context, $options = null)
 {
     $this->loadOptions();
     if ($options === null) {
         $options = $this->mOptions;
     }
     $prefs = Preferences::getPreferences($this, $context);
     $mapping = array();
     // Pull out the "special" options, so they don't get converted as
     // multiselect or checkmatrix.
     $specialOptions = array_fill_keys(Preferences::getSaveBlacklist(), true);
     foreach ($specialOptions as $name => $value) {
         unset($prefs[$name]);
     }
     // Multiselect and checkmatrix options are stored in the database with
     // one key per option, each having a boolean value. Extract those keys.
     $multiselectOptions = array();
     foreach ($prefs as $name => $info) {
         if (isset($info['type']) && $info['type'] == 'multiselect' || isset($info['class']) && $info['class'] == 'HTMLMultiSelectField') {
             $opts = HTMLFormField::flattenOptions($info['options']);
             $prefix = isset($info['prefix']) ? $info['prefix'] : $name;
             foreach ($opts as $value) {
                 $multiselectOptions["{$prefix}{$value}"] = true;
             }
             unset($prefs[$name]);
         }
     }
     $checkmatrixOptions = array();
     foreach ($prefs as $name => $info) {
         if (isset($info['type']) && $info['type'] == 'checkmatrix' || isset($info['class']) && $info['class'] == 'HTMLCheckMatrix') {
             $columns = HTMLFormField::flattenOptions($info['columns']);
             $rows = HTMLFormField::flattenOptions($info['rows']);
             $prefix = isset($info['prefix']) ? $info['prefix'] : $name;
             foreach ($columns as $column) {
                 foreach ($rows as $row) {
                     $checkmatrixOptions["{$prefix}{$column}-{$row}"] = true;
                 }
             }
             unset($prefs[$name]);
         }
     }
     // $value is ignored
     foreach ($options as $key => $value) {
         if (isset($prefs[$key])) {
             $mapping[$key] = 'registered';
         } elseif (isset($multiselectOptions[$key])) {
             $mapping[$key] = 'registered-multiselect';
         } elseif (isset($checkmatrixOptions[$key])) {
             $mapping[$key] = 'registered-checkmatrix';
         } elseif (isset($specialOptions[$key])) {
             $mapping[$key] = 'special';
         } elseif (substr($key, 0, 7) === 'userjs-') {
             $mapping[$key] = 'userjs';
         } else {
             $mapping[$key] = 'unused';
         }
     }
     return $mapping;
 }