mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Continue modernizing application access to user preferences
Summary: Ref T4103. This is just incremental cleanup: - Add "internal" settings, which aren't editable via the UI. They can still do validation and run through the normal pathway. Move a couple settings to use this. - Remove `getPreference()` on `PhabricatorUser`, which was a sort of prototype version of `getUserSetting()`. - Make `getUserSetting()` validate setting values before returning them, to improve robustness if we change allowable values later. - Add a user setting cache, since reading user settings was getting fairly expensive on Calendar. - Improve performance of setting validation for timezone setting (don't require building/computing all timezone offsets). - Since we have the cache anyway, make the timezone override a little more general in its approach. - Move editor stuff to use `getUserSetting()`. Test Plan: - Changed search scopes. - Reconciled local and server timezone settings by ignoring and changing timezones. - Changed date/time settings, browsed Calendar, queried date ranges. - Verified editor links generate properly in Diffusion. - Browsed around with time/date settings looking at timestamps. - Grepped for `getPreference()`, nuked all the ones coming off `$user` or `$viewer` that I could find. - Changed accessiblity to high-contrast colors. - Ran all unit tests. - Grepped for removed constants. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16015
This commit is contained in:
parent
57c2f61b75
commit
67482fd19d
18 changed files with 171 additions and 100 deletions
|
@ -2594,6 +2594,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorInlineCommentPreviewController' => 'infrastructure/diff/PhabricatorInlineCommentPreviewController.php',
|
'PhabricatorInlineCommentPreviewController' => 'infrastructure/diff/PhabricatorInlineCommentPreviewController.php',
|
||||||
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
|
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
|
||||||
'PhabricatorInstructionsEditField' => 'applications/transactions/editfield/PhabricatorInstructionsEditField.php',
|
'PhabricatorInstructionsEditField' => 'applications/transactions/editfield/PhabricatorInstructionsEditField.php',
|
||||||
|
'PhabricatorInternalSetting' => 'applications/settings/setting/PhabricatorInternalSetting.php',
|
||||||
'PhabricatorInternationalizationManagementExtractWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php',
|
'PhabricatorInternationalizationManagementExtractWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php',
|
||||||
'PhabricatorInternationalizationManagementWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementWorkflow.php',
|
'PhabricatorInternationalizationManagementWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementWorkflow.php',
|
||||||
'PhabricatorInvalidConfigSetupCheck' => 'applications/config/check/PhabricatorInvalidConfigSetupCheck.php',
|
'PhabricatorInvalidConfigSetupCheck' => 'applications/config/check/PhabricatorInvalidConfigSetupCheck.php',
|
||||||
|
@ -3353,6 +3354,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchResultBucketGroup' => 'applications/search/buckets/PhabricatorSearchResultBucketGroup.php',
|
'PhabricatorSearchResultBucketGroup' => 'applications/search/buckets/PhabricatorSearchResultBucketGroup.php',
|
||||||
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
||||||
'PhabricatorSearchSchemaSpec' => 'applications/search/storage/PhabricatorSearchSchemaSpec.php',
|
'PhabricatorSearchSchemaSpec' => 'applications/search/storage/PhabricatorSearchSchemaSpec.php',
|
||||||
|
'PhabricatorSearchScopeSetting' => 'applications/settings/setting/PhabricatorSearchScopeSetting.php',
|
||||||
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
|
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
|
||||||
'PhabricatorSearchSelectField' => 'applications/search/field/PhabricatorSearchSelectField.php',
|
'PhabricatorSearchSelectField' => 'applications/search/field/PhabricatorSearchSelectField.php',
|
||||||
'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php',
|
'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php',
|
||||||
|
@ -3538,6 +3540,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorTimeFormatSetting' => 'applications/settings/setting/PhabricatorTimeFormatSetting.php',
|
'PhabricatorTimeFormatSetting' => 'applications/settings/setting/PhabricatorTimeFormatSetting.php',
|
||||||
'PhabricatorTimeGuard' => 'infrastructure/time/PhabricatorTimeGuard.php',
|
'PhabricatorTimeGuard' => 'infrastructure/time/PhabricatorTimeGuard.php',
|
||||||
'PhabricatorTimeTestCase' => 'infrastructure/time/__tests__/PhabricatorTimeTestCase.php',
|
'PhabricatorTimeTestCase' => 'infrastructure/time/__tests__/PhabricatorTimeTestCase.php',
|
||||||
|
'PhabricatorTimezoneIgnoreOffsetSetting' => 'applications/settings/setting/PhabricatorTimezoneIgnoreOffsetSetting.php',
|
||||||
'PhabricatorTimezoneSetting' => 'applications/settings/setting/PhabricatorTimezoneSetting.php',
|
'PhabricatorTimezoneSetting' => 'applications/settings/setting/PhabricatorTimezoneSetting.php',
|
||||||
'PhabricatorTimezoneSetupCheck' => 'applications/config/check/PhabricatorTimezoneSetupCheck.php',
|
'PhabricatorTimezoneSetupCheck' => 'applications/config/check/PhabricatorTimezoneSetupCheck.php',
|
||||||
'PhabricatorTitleGlyphsSetting' => 'applications/settings/setting/PhabricatorTitleGlyphsSetting.php',
|
'PhabricatorTitleGlyphsSetting' => 'applications/settings/setting/PhabricatorTitleGlyphsSetting.php',
|
||||||
|
@ -7196,6 +7199,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorInlineCommentPreviewController' => 'PhabricatorController',
|
'PhabricatorInlineCommentPreviewController' => 'PhabricatorController',
|
||||||
'PhabricatorInlineSummaryView' => 'AphrontView',
|
'PhabricatorInlineSummaryView' => 'AphrontView',
|
||||||
'PhabricatorInstructionsEditField' => 'PhabricatorEditField',
|
'PhabricatorInstructionsEditField' => 'PhabricatorEditField',
|
||||||
|
'PhabricatorInternalSetting' => 'PhabricatorSetting',
|
||||||
'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow',
|
'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow',
|
||||||
'PhabricatorInternationalizationManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
'PhabricatorInternationalizationManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
'PhabricatorInvalidConfigSetupCheck' => 'PhabricatorSetupCheck',
|
'PhabricatorInvalidConfigSetupCheck' => 'PhabricatorSetupCheck',
|
||||||
|
@ -8103,6 +8107,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchResultBucketGroup' => 'Phobject',
|
'PhabricatorSearchResultBucketGroup' => 'Phobject',
|
||||||
'PhabricatorSearchResultView' => 'AphrontView',
|
'PhabricatorSearchResultView' => 'AphrontView',
|
||||||
'PhabricatorSearchSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'PhabricatorSearchSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
|
'PhabricatorSearchScopeSetting' => 'PhabricatorInternalSetting',
|
||||||
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
||||||
'PhabricatorSearchSelectField' => 'PhabricatorSearchField',
|
'PhabricatorSearchSelectField' => 'PhabricatorSearchField',
|
||||||
'PhabricatorSearchStringListField' => 'PhabricatorSearchField',
|
'PhabricatorSearchStringListField' => 'PhabricatorSearchField',
|
||||||
|
@ -8304,6 +8309,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorTimeFormatSetting' => 'PhabricatorSelectSetting',
|
'PhabricatorTimeFormatSetting' => 'PhabricatorSelectSetting',
|
||||||
'PhabricatorTimeGuard' => 'Phobject',
|
'PhabricatorTimeGuard' => 'Phobject',
|
||||||
'PhabricatorTimeTestCase' => 'PhabricatorTestCase',
|
'PhabricatorTimeTestCase' => 'PhabricatorTestCase',
|
||||||
|
'PhabricatorTimezoneIgnoreOffsetSetting' => 'PhabricatorInternalSetting',
|
||||||
'PhabricatorTimezoneSetting' => 'PhabricatorOptionGroupSetting',
|
'PhabricatorTimezoneSetting' => 'PhabricatorOptionGroupSetting',
|
||||||
'PhabricatorTimezoneSetupCheck' => 'PhabricatorSetupCheck',
|
'PhabricatorTimezoneSetupCheck' => 'PhabricatorSetupCheck',
|
||||||
'PhabricatorTitleGlyphsSetting' => 'PhabricatorSelectSetting',
|
'PhabricatorTitleGlyphsSetting' => 'PhabricatorSelectSetting',
|
||||||
|
|
|
@ -64,8 +64,8 @@ final class AphrontAjaxResponse extends AphrontResponse {
|
||||||
if ($request) {
|
if ($request) {
|
||||||
$viewer = $request->getViewer();
|
$viewer = $request->getViewer();
|
||||||
if ($viewer) {
|
if ($viewer) {
|
||||||
$postprocessor_key = $viewer->getPreference(
|
$postprocessor_key = $viewer->getUserSetting(
|
||||||
PhabricatorUserPreferences::PREFERENCE_RESOURCE_POSTPROCESSOR);
|
PhabricatorAccessibilitySetting::SETTINGKEY);
|
||||||
if (strlen($postprocessor_key)) {
|
if (strlen($postprocessor_key)) {
|
||||||
$response->setPostprocessorKey($postprocessor_key);
|
$response->setPostprocessorKey($postprocessor_key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,9 @@ final class PhabricatorUser
|
||||||
private $authorities = array();
|
private $authorities = array();
|
||||||
private $handlePool;
|
private $handlePool;
|
||||||
private $csrfSalt;
|
private $csrfSalt;
|
||||||
private $timezoneOverride;
|
|
||||||
|
private $settingCacheKeys = array();
|
||||||
|
private $settingCache = array();
|
||||||
|
|
||||||
protected function readField($field) {
|
protected function readField($field) {
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
|
@ -481,19 +483,50 @@ final class PhabricatorUser
|
||||||
|
|
||||||
|
|
||||||
public function getUserSetting($key) {
|
public function getUserSetting($key) {
|
||||||
|
// NOTE: We store available keys and cached values separately to make it
|
||||||
|
// faster to check for `null` in the cache, which is common.
|
||||||
|
if (isset($this->settingCacheKeys[$key])) {
|
||||||
|
return $this->settingCache[$key];
|
||||||
|
}
|
||||||
|
|
||||||
$settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
|
$settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
|
||||||
$settings = $this->requireCacheData($settings_key);
|
$settings = $this->requireCacheData($settings_key);
|
||||||
|
|
||||||
if (array_key_exists($key, $settings)) {
|
|
||||||
return $settings[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
$defaults = PhabricatorSetting::getAllEnabledSettings($this);
|
$defaults = PhabricatorSetting::getAllEnabledSettings($this);
|
||||||
|
|
||||||
|
if (array_key_exists($key, $settings)) {
|
||||||
|
$value = $settings[$key];
|
||||||
|
|
||||||
|
// Make sure the value is valid before we return it. This makes things
|
||||||
|
// more robust when options are changed or removed.
|
||||||
if (isset($defaults[$key])) {
|
if (isset($defaults[$key])) {
|
||||||
return $defaults[$key]->getSettingDefaultValue();
|
try {
|
||||||
|
id(clone $defaults[$key])
|
||||||
|
->setViewer($this)
|
||||||
|
->assertValidValue($value);
|
||||||
|
|
||||||
|
$this->settingCacheKeys[$key] = true;
|
||||||
|
$this->settingCache[$key] = $value;
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// Fall through below and return the default value.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
if (isset($defaults[$key])) {
|
||||||
|
$value = id(clone $defaults[$key])
|
||||||
|
->setViewer($this)
|
||||||
|
->getSettingDefaultValue();
|
||||||
|
} else {
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->settingCacheKeys[$key] = true;
|
||||||
|
$this->settingCache[$key] = $value;
|
||||||
|
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -510,15 +543,25 @@ final class PhabricatorUser
|
||||||
return ($actual == $value);
|
return ($actual == $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @task settings
|
||||||
|
*/
|
||||||
|
public function clearUserSettingCache() {
|
||||||
|
$this->settingCacheKeys = array();
|
||||||
|
$this->settingCache = array();
|
||||||
|
|
||||||
|
$settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
|
||||||
|
$this->clearCacheData($settings_key);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTranslation() {
|
public function getTranslation() {
|
||||||
return $this->getUserSetting(PhabricatorTranslationSetting::SETTINGKEY);
|
return $this->getUserSetting(PhabricatorTranslationSetting::SETTINGKEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTimezoneIdentifier() {
|
public function getTimezoneIdentifier() {
|
||||||
if ($this->timezoneOverride) {
|
|
||||||
return $this->timezoneOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getUserSetting(PhabricatorTimezoneSetting::SETTINGKEY);
|
return $this->getUserSetting(PhabricatorTimezoneSetting::SETTINGKEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,7 +576,9 @@ final class PhabricatorUser
|
||||||
* @task settings
|
* @task settings
|
||||||
*/
|
*/
|
||||||
public function overrideTimezoneIdentifier($identifier) {
|
public function overrideTimezoneIdentifier($identifier) {
|
||||||
$this->timezoneOverride = $identifier;
|
$timezone_key = PhabricatorTimezoneSetting::SETTINGKEY;
|
||||||
|
$this->settingCacheKeys[$timezone_key] = true;
|
||||||
|
$this->settingCache[$timezone_key] = $identifier;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,17 +623,17 @@ final class PhabricatorUser
|
||||||
$line,
|
$line,
|
||||||
PhabricatorRepository $repository = null) {
|
PhabricatorRepository $repository = null) {
|
||||||
|
|
||||||
$editor = $this->loadPreferences()->getPreference(
|
$editor = $this->getUserSetting(PhabricatorEditorSetting::SETTINGKEY);
|
||||||
PhabricatorUserPreferences::PREFERENCE_EDITOR);
|
|
||||||
|
|
||||||
if (is_array($path)) {
|
if (is_array($path)) {
|
||||||
$multiedit = $this->loadPreferences()->getPreference(
|
$multi_key = PhabricatorEditorMultipleSetting::SETTINGKEY;
|
||||||
PhabricatorUserPreferences::PREFERENCE_MULTIEDIT);
|
$multiedit = $this->getUserSetting($multi_key);
|
||||||
switch ($multiedit) {
|
switch ($multiedit) {
|
||||||
case '':
|
case PhabricatorEditorMultipleSetting::VALUE_SPACES:
|
||||||
$path = implode(' ', $path);
|
$path = implode(' ', $path);
|
||||||
break;
|
break;
|
||||||
case 'disable':
|
case PhabricatorEditorMultipleSetting::VALUE_SINGLE:
|
||||||
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,48 +893,13 @@ final class PhabricatorUser
|
||||||
$format = 'M j';
|
$format = 'M j';
|
||||||
} else {
|
} else {
|
||||||
// Same year, month and day so show a time of day.
|
// Same year, month and day so show a time of day.
|
||||||
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
$pref_time = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
$format = $this->getPreference($pref_time);
|
$format = $this->getUserSetting($pref_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $when->format($format);
|
return $when->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPreference($key) {
|
|
||||||
$preferences = $this->loadPreferences();
|
|
||||||
|
|
||||||
// TODO: After T4103 and T7707 this should eventually be pushed down the
|
|
||||||
// stack into modular preference definitions and role profiles. This is
|
|
||||||
// just fixing T8601 and mildly anticipating those changes.
|
|
||||||
$value = $preferences->getPreference($key);
|
|
||||||
|
|
||||||
$allowed_values = null;
|
|
||||||
switch ($key) {
|
|
||||||
case PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT:
|
|
||||||
$allowed_values = array(
|
|
||||||
'g:i A',
|
|
||||||
'H:i',
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT:
|
|
||||||
$allowed_values = array(
|
|
||||||
'Y-m-d',
|
|
||||||
'n/j/Y',
|
|
||||||
'd-m-Y',
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($allowed_values !== null) {
|
|
||||||
$allowed_values = array_fuse($allowed_values);
|
|
||||||
if (empty($allowed_values[$value])) {
|
|
||||||
$value = head($allowed_values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
return $this->getUsername();
|
return $this->getUsername();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ final class PhabricatorSettingsTimezoneController
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$timezone = $request->getStr('timezone');
|
$timezone = $request->getStr('timezone');
|
||||||
|
|
||||||
$pref_ignore = PhabricatorUserPreferences::PREFERENCE_IGNORE_OFFSET;
|
$pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY;
|
||||||
$pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY;
|
$pref_timezone = PhabricatorTimezoneSetting::SETTINGKEY;
|
||||||
|
|
||||||
$preferences = $viewer->loadPreferences();
|
$preferences = $viewer->loadPreferences();
|
||||||
|
@ -56,8 +56,7 @@ final class PhabricatorSettingsTimezoneController
|
||||||
->setPreference($pref_timezone, $timezone)
|
->setPreference($pref_timezone, $timezone)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$viewer->clearCacheData(
|
$viewer->clearUserSettingCache();
|
||||||
PhabricatorUserPreferencesCacheType::KEY_PREFERENCES);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel {
|
||||||
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
||||||
$pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
|
$pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
|
||||||
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
||||||
$pref_ignore = PhabricatorUserPreferences::PREFERENCE_IGNORE_OFFSET;
|
$pref_ignore = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY;
|
||||||
$preferences = $user->loadPreferences();
|
$preferences = $user->loadPreferences();
|
||||||
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorInternalSetting
|
||||||
|
extends PhabricatorSetting {}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorSearchScopeSetting
|
||||||
|
extends PhabricatorInternalSetting {
|
||||||
|
|
||||||
|
const SETTINGKEY = 'search-scope';
|
||||||
|
|
||||||
|
public function getSettingName() {
|
||||||
|
return pht('Search Scope');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSettingDefaultValue() {
|
||||||
|
return 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -89,6 +89,10 @@ abstract class PhabricatorSetting extends Phobject {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assertValidValue($value) {
|
||||||
|
$this->validateTransactionValue($value);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTransactionNewValue($value) {
|
public function getTransactionNewValue($value) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorTimezoneIgnoreOffsetSetting
|
||||||
|
extends PhabricatorInternalSetting {
|
||||||
|
|
||||||
|
const SETTINGKEY = 'time.offset.ignore';
|
||||||
|
|
||||||
|
public function getSettingName() {
|
||||||
|
return pht('Timezone Ignored Offset');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,31 @@ final class PhabricatorTimezoneSetting
|
||||||
return date_default_timezone_get();
|
return date_default_timezone_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assertValidValue($value) {
|
||||||
|
// NOTE: This isn't doing anything fancy, it's just a much faster
|
||||||
|
// validator than doing all the timezone calculations to build the full
|
||||||
|
// list of options.
|
||||||
|
|
||||||
|
if (!$value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static $identifiers;
|
||||||
|
if ($identifiers === null) {
|
||||||
|
$identifiers = DateTimeZone::listIdentifiers();
|
||||||
|
$identifiers = array_fuse($identifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($identifiers[$value])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Timezone "%s" is not a valid timezone identiifer.',
|
||||||
|
$value));
|
||||||
|
}
|
||||||
|
|
||||||
protected function getSelectOptionGroups() {
|
protected function getSelectOptionGroups() {
|
||||||
$timezones = DateTimeZone::listIdentifiers();
|
$timezones = DateTimeZone::listIdentifiers();
|
||||||
$now = new DateTime('@'.PhabricatorTime::getNow());
|
$now = new DateTime('@'.PhabricatorTime::getNow());
|
||||||
|
|
|
@ -24,8 +24,6 @@ final class PhabricatorUserPreferences
|
||||||
const PREFERENCE_VARY_SUBJECT = 'vary-subject';
|
const PREFERENCE_VARY_SUBJECT = 'vary-subject';
|
||||||
const PREFERENCE_HTML_EMAILS = 'html-emails';
|
const PREFERENCE_HTML_EMAILS = 'html-emails';
|
||||||
|
|
||||||
const PREFERENCE_SEARCH_SCOPE = 'search-scope';
|
|
||||||
|
|
||||||
const PREFERENCE_DIFFUSION_BLAME = 'diffusion-blame';
|
const PREFERENCE_DIFFUSION_BLAME = 'diffusion-blame';
|
||||||
const PREFERENCE_DIFFUSION_COLOR = 'diffusion-color';
|
const PREFERENCE_DIFFUSION_COLOR = 'diffusion-color';
|
||||||
|
|
||||||
|
@ -46,7 +44,6 @@ final class PhabricatorUserPreferences
|
||||||
|
|
||||||
const PREFERENCE_PROFILE_MENU_COLLAPSED = 'profile-menu.collapsed';
|
const PREFERENCE_PROFILE_MENU_COLLAPSED = 'profile-menu.collapsed';
|
||||||
const PREFERENCE_FAVORITE_POLICIES = 'policy.favorites';
|
const PREFERENCE_FAVORITE_POLICIES = 'policy.favorites';
|
||||||
const PREFERENCE_IGNORE_OFFSET = 'time.offset.ignore';
|
|
||||||
|
|
||||||
// These are in an unusual order for historic reasons.
|
// These are in an unusual order for historic reasons.
|
||||||
const MAILTAG_PREFERENCE_NOTIFY = 0;
|
const MAILTAG_PREFERENCE_NOTIFY = 0;
|
||||||
|
|
|
@ -113,7 +113,7 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$readable = $this->formatTime($epoch, 'Y!m!d!g:i A');
|
$readable = $this->formatTime($epoch, 'Y!m!d!'.$this->getTimeFormat());
|
||||||
$readable = explode('!', $readable, 4);
|
$readable = explode('!', $readable, 4);
|
||||||
|
|
||||||
$year = $readable[0];
|
$year = $readable[0];
|
||||||
|
@ -140,13 +140,15 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTimeFormat() {
|
private function getTimeFormat() {
|
||||||
return $this->getViewer()
|
$viewer = $this->getViewer();
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
|
$time_key = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
|
return $viewer->getUserSetting($time_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateFormat() {
|
private function getDateFormat() {
|
||||||
return $this->getViewer()
|
$viewer = $this->getViewer();
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
|
$date_key = PhabricatorDateFormatSetting::SETTINGKEY;
|
||||||
|
return $viewer->getUserSetting($date_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTimeInputValue() {
|
private function getTimeInputValue() {
|
||||||
|
@ -241,7 +243,6 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
'format' => $this->getTimeFormat(),
|
'format' => $this->getTimeFormat(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
$time_sel = javelin_tag(
|
$time_sel = javelin_tag(
|
||||||
'input',
|
'input',
|
||||||
array(
|
array(
|
||||||
|
@ -262,9 +263,9 @@ final class AphrontFormDateControl extends AphrontFormControl {
|
||||||
),
|
),
|
||||||
$time_sel);
|
$time_sel);
|
||||||
|
|
||||||
$preferences = $this->getViewer()->loadPreferences();
|
$viewer = $this->getViewer();
|
||||||
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
|
$week_key = PhabricatorWeekStartDaySetting::SETTINGKEY;
|
||||||
$week_start = $preferences->getPreference($pref_week_start, 0);
|
$week_start = $viewer->getUserSetting($week_key);
|
||||||
|
|
||||||
Javelin::initBehavior('fancy-datepicker', array(
|
Javelin::initBehavior('fancy-datepicker', array(
|
||||||
'format' => $this->getDateFormat(),
|
'format' => $this->getDateFormat(),
|
||||||
|
|
|
@ -207,13 +207,15 @@ final class AphrontFormDateControlValue extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTimeFormat() {
|
private function getTimeFormat() {
|
||||||
return $this->getViewer()
|
$viewer = $this->getViewer();
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
|
$time_key = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
|
return $viewer->getUserSetting($time_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateFormat() {
|
private function getDateFormat() {
|
||||||
return $this->getViewer()
|
$viewer = $this->getViewer();
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
|
$date_key = PhabricatorDateFormatSetting::SETTINGKEY;
|
||||||
|
return $viewer->getUserSetting($date_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFormattedDateFromDate($date, $time) {
|
private function getFormattedDateFromDate($date, $time) {
|
||||||
|
|
|
@ -130,8 +130,8 @@ class PhabricatorBarePageView extends AphrontPageView {
|
||||||
if ($this->getRequest()) {
|
if ($this->getRequest()) {
|
||||||
$viewer = $this->getRequest()->getViewer();
|
$viewer = $this->getRequest()->getViewer();
|
||||||
if ($viewer) {
|
if ($viewer) {
|
||||||
$postprocessor_key = $viewer->getPreference(
|
$postprocessor_key = $viewer->getUserSetting(
|
||||||
PhabricatorUserPreferences::PREFERENCE_RESOURCE_POSTPROCESSOR);
|
PhabricatorAccessibilitySetting::SETTINGKEY);
|
||||||
if (strlen($postprocessor_key)) {
|
if (strlen($postprocessor_key)) {
|
||||||
$response->setPostProcessorKey($postprocessor_key);
|
$response->setPostProcessorKey($postprocessor_key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,13 +225,8 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
|
||||||
if ($user->isLoggedIn()) {
|
if ($user->isLoggedIn()) {
|
||||||
$offset = $user->getTimeZoneOffset();
|
$offset = $user->getTimeZoneOffset();
|
||||||
|
|
||||||
$preferences = $user->loadPreferences();
|
$ignore_key = PhabricatorTimezoneIgnoreOffsetSetting::SETTINGKEY;
|
||||||
$ignore_key = PhabricatorUserPreferences::PREFERENCE_IGNORE_OFFSET;
|
$ignore = $user->getUserSetting($ignore_key);
|
||||||
|
|
||||||
$ignore = $preferences->getPreference($ignore_key);
|
|
||||||
if (!strlen($ignore)) {
|
|
||||||
$ignore = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Javelin::initBehavior(
|
Javelin::initBehavior(
|
||||||
'detect-timezone',
|
'detect-timezone',
|
||||||
|
|
|
@ -50,7 +50,7 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
||||||
'');
|
'');
|
||||||
|
|
||||||
$search_datasource = new PhabricatorSearchDatasource();
|
$search_datasource = new PhabricatorSearchDatasource();
|
||||||
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
|
$scope_key = PhabricatorSearchScopeSetting::SETTINGKEY;
|
||||||
|
|
||||||
Javelin::initBehavior(
|
Javelin::initBehavior(
|
||||||
'phabricator-search-typeahead',
|
'phabricator-search-typeahead',
|
||||||
|
@ -177,10 +177,8 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
||||||
'href' => PhabricatorEnv::getDoclink('Search User Guide'),
|
'href' => PhabricatorEnv::getDoclink('Search User Guide'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
|
$scope_key = PhabricatorSearchScopeSetting::SETTINGKEY;
|
||||||
$current_value = $viewer->loadPreferences()->getPreference(
|
$current_value = $viewer->getUserSetting($scope_key);
|
||||||
$scope_key,
|
|
||||||
'all');
|
|
||||||
|
|
||||||
$current_icon = 'fa-globe';
|
$current_icon = 'fa-globe';
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
|
|
@ -147,16 +147,18 @@ final class PHUICalendarListView extends AphrontTagView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getEventTooltip(AphrontCalendarEventView $event) {
|
private function getEventTooltip(AphrontCalendarEventView $event) {
|
||||||
$time_pref = $this->getUser()
|
$viewer = $this->getViewer();
|
||||||
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
|
$time_key = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
|
$time_pref = $viewer->getUserSetting($time_key);
|
||||||
|
|
||||||
Javelin::initBehavior('phabricator-tooltips');
|
Javelin::initBehavior('phabricator-tooltips');
|
||||||
|
|
||||||
$start = id(AphrontFormDateControlValue::newFromEpoch(
|
$start = id(AphrontFormDateControlValue::newFromEpoch(
|
||||||
$this->getUser(),
|
$viewer,
|
||||||
$event->getEpochStart()));
|
$event->getEpochStart()));
|
||||||
|
|
||||||
$end = id(AphrontFormDateControlValue::newFromEpoch(
|
$end = id(AphrontFormDateControlValue::newFromEpoch(
|
||||||
$this->getUser(),
|
$viewer,
|
||||||
$event->getEpochEnd()));
|
$event->getEpochEnd()));
|
||||||
|
|
||||||
$start_date = $start->getDateTime()->format('m d Y');
|
$start_date = $start->getDateTime()->format('m d Y');
|
||||||
|
|
|
@ -31,21 +31,21 @@ function phabricator_relative_date($epoch, $user, $on = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function phabricator_time($epoch, $user) {
|
function phabricator_time($epoch, $user) {
|
||||||
$time_key = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
$time_key = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
return phabricator_format_local_time(
|
return phabricator_format_local_time(
|
||||||
$epoch,
|
$epoch,
|
||||||
$user,
|
$user,
|
||||||
$user->getPreference($time_key));
|
$user->getUserSetting($time_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
function phabricator_datetime($epoch, $user) {
|
function phabricator_datetime($epoch, $user) {
|
||||||
$time_key = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
|
$time_key = PhabricatorTimeFormatSetting::SETTINGKEY;
|
||||||
return phabricator_format_local_time(
|
return phabricator_format_local_time(
|
||||||
$epoch,
|
$epoch,
|
||||||
$user,
|
$user,
|
||||||
pht('%s, %s',
|
pht('%s, %s',
|
||||||
phutil_date_format($epoch),
|
phutil_date_format($epoch),
|
||||||
$user->getPreference($time_key)));
|
$user->getUserSetting($time_key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue