1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Convert "Display Preferences" to modular settings

Summary: Ref T4103. Just porting these directly for now, no attempt to organize things yet.

Test Plan: {F1669263}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4103

Differential Revision: https://secure.phabricator.com/D15997
This commit is contained in:
epriestley 2016-05-31 16:06:18 -07:00
parent ba505c03f9
commit 9b27b5c7da
10 changed files with 245 additions and 2 deletions

View file

@ -1711,6 +1711,7 @@ phutil_register_library_map(array(
'PhabricatorAccessControlTestCase' => 'applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php',
'PhabricatorAccessLog' => 'infrastructure/log/PhabricatorAccessLog.php',
'PhabricatorAccessLogConfigOptions' => 'applications/config/option/PhabricatorAccessLogConfigOptions.php',
'PhabricatorAccessibilitySetting' => 'applications/settings/setting/PhabricatorAccessibilitySetting.php',
'PhabricatorAccountSettingsPanel' => 'applications/settings/panel/PhabricatorAccountSettingsPanel.php',
'PhabricatorActionListView' => 'view/layout/PhabricatorActionListView.php',
'PhabricatorActionView' => 'view/layout/PhabricatorActionView.php',
@ -2373,6 +2374,8 @@ phutil_register_library_map(array(
'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php',
'PhabricatorEditType' => 'applications/transactions/edittype/PhabricatorEditType.php',
'PhabricatorEditor' => 'infrastructure/PhabricatorEditor.php',
'PhabricatorEditorMultipleSetting' => 'applications/settings/setting/PhabricatorEditorMultipleSetting.php',
'PhabricatorEditorSetting' => 'applications/settings/setting/PhabricatorEditorSetting.php',
'PhabricatorElasticFulltextStorageEngine' => 'applications/search/fulltextstorage/PhabricatorElasticFulltextStorageEngine.php',
'PhabricatorElasticSearchSetupCheck' => 'applications/config/check/PhabricatorElasticSearchSetupCheck.php',
'PhabricatorEmailAddressesSettingsPanel' => 'applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php',
@ -2732,6 +2735,8 @@ phutil_register_library_map(array(
'PhabricatorMetaMTASendGridReceiveController' => 'applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php',
'PhabricatorMetaMTAWorker' => 'applications/metamta/PhabricatorMetaMTAWorker.php',
'PhabricatorMetronomicTriggerClock' => 'infrastructure/daemon/workers/clock/PhabricatorMetronomicTriggerClock.php',
'PhabricatorMonospacedFontSetting' => 'applications/settings/setting/PhabricatorMonospacedFontSetting.php',
'PhabricatorMonospacedTextareasSetting' => 'applications/settings/setting/PhabricatorMonospacedTextareasSetting.php',
'PhabricatorMotivatorProfilePanel' => 'applications/search/profilepanel/PhabricatorMotivatorProfilePanel.php',
'PhabricatorMultiColumnUIExample' => 'applications/uiexample/examples/PhabricatorMultiColumnUIExample.php',
'PhabricatorMultiFactorSettingsPanel' => 'applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php',
@ -3463,6 +3468,7 @@ phutil_register_library_map(array(
'PhabricatorStorageSetupCheck' => 'applications/config/check/PhabricatorStorageSetupCheck.php',
'PhabricatorStreamingProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorStreamingProtocolAdapter.php',
'PhabricatorStringListEditField' => 'applications/transactions/editfield/PhabricatorStringListEditField.php',
'PhabricatorStringSetting' => 'applications/settings/setting/PhabricatorStringSetting.php',
'PhabricatorSubscribableInterface' => 'applications/subscriptions/interface/PhabricatorSubscribableInterface.php',
'PhabricatorSubscribedToObjectEdgeType' => 'applications/transactions/edges/PhabricatorSubscribedToObjectEdgeType.php',
'PhabricatorSubscribersEditField' => 'applications/transactions/editfield/PhabricatorSubscribersEditField.php',
@ -3522,6 +3528,7 @@ phutil_register_library_map(array(
'PhabricatorTimeGuard' => 'infrastructure/time/PhabricatorTimeGuard.php',
'PhabricatorTimeTestCase' => 'infrastructure/time/__tests__/PhabricatorTimeTestCase.php',
'PhabricatorTimezoneSetupCheck' => 'applications/config/check/PhabricatorTimezoneSetupCheck.php',
'PhabricatorTitleGlyphsSetting' => 'applications/settings/setting/PhabricatorTitleGlyphsSetting.php',
'PhabricatorToken' => 'applications/tokens/storage/PhabricatorToken.php',
'PhabricatorTokenController' => 'applications/tokens/controller/PhabricatorTokenController.php',
'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php',
@ -6137,6 +6144,7 @@ phutil_register_library_map(array(
'PhabricatorAccessControlTestCase' => 'PhabricatorTestCase',
'PhabricatorAccessLog' => 'Phobject',
'PhabricatorAccessLogConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorAccessibilitySetting' => 'PhabricatorSelectSetting',
'PhabricatorAccountSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorActionListView' => 'AphrontView',
'PhabricatorActionView' => 'AphrontView',
@ -6914,6 +6922,8 @@ phutil_register_library_map(array(
'PhabricatorEditPage' => 'Phobject',
'PhabricatorEditType' => 'Phobject',
'PhabricatorEditor' => 'Phobject',
'PhabricatorEditorMultipleSetting' => 'PhabricatorSelectSetting',
'PhabricatorEditorSetting' => 'PhabricatorStringSetting',
'PhabricatorElasticFulltextStorageEngine' => 'PhabricatorFulltextStorageEngine',
'PhabricatorElasticSearchSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorEmailAddressesSettingsPanel' => 'PhabricatorSettingsPanel',
@ -7318,6 +7328,8 @@ phutil_register_library_map(array(
'PhabricatorMetaMTASendGridReceiveController' => 'PhabricatorMetaMTAController',
'PhabricatorMetaMTAWorker' => 'PhabricatorWorker',
'PhabricatorMetronomicTriggerClock' => 'PhabricatorTriggerClock',
'PhabricatorMonospacedFontSetting' => 'PhabricatorStringSetting',
'PhabricatorMonospacedTextareasSetting' => 'PhabricatorSelectSetting',
'PhabricatorMotivatorProfilePanel' => 'PhabricatorProfilePanel',
'PhabricatorMultiColumnUIExample' => 'PhabricatorUIExample',
'PhabricatorMultiFactorSettingsPanel' => 'PhabricatorSettingsPanel',
@ -8204,6 +8216,7 @@ phutil_register_library_map(array(
'PhabricatorStorageSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorStreamingProtocolAdapter' => 'PhabricatorProtocolAdapter',
'PhabricatorStringListEditField' => 'PhabricatorEditField',
'PhabricatorStringSetting' => 'PhabricatorSetting',
'PhabricatorSubscribedToObjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorSubscribersEditField' => 'PhabricatorTokenizerEditField',
'PhabricatorSubscribersQuery' => 'PhabricatorQuery',
@ -8262,6 +8275,7 @@ phutil_register_library_map(array(
'PhabricatorTimeGuard' => 'Phobject',
'PhabricatorTimeTestCase' => 'PhabricatorTestCase',
'PhabricatorTimezoneSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorTitleGlyphsSetting' => 'PhabricatorSelectSetting',
'PhabricatorToken' => array(
'PhabricatorTokenDAO',
'PhabricatorPolicyInterface',

View file

@ -10,7 +10,7 @@ final class CelerityDefaultPostprocessor
}
public function getPostprocessorName() {
return pht('Use Default Colors');
return pht('Use Standard Colors');
}
public function buildDefaultPostprocessor() {

View file

@ -0,0 +1,39 @@
<?php
final class PhabricatorAccessibilitySetting
extends PhabricatorSelectSetting {
const SETTINGKEY = 'resource-postprocessor';
public function getSettingName() {
return pht('Accessibility');
}
protected function getControlInstructions() {
return pht(
'If you have difficulty reading the Phabricator UI, these settings '.
'may make Phabricator more accessible.');
}
public function getSettingDefaultValue() {
return CelerityDefaultPostprocessor::POSTPROCESSOR_KEY;
}
protected function getSelectOptions() {
$postprocessor_map = CelerityPostprocessor::getAllPostprocessors();
$postprocessor_map = mpull($postprocessor_map, 'getPostprocessorName');
asort($postprocessor_map);
$postprocessor_order = array(
CelerityDefaultPostprocessor::POSTPROCESSOR_KEY,
);
$postprocessor_map = array_select_keys(
$postprocessor_map,
$postprocessor_order) + $postprocessor_map;
return $postprocessor_map;
}
}

View file

@ -0,0 +1,32 @@
<?php
final class PhabricatorEditorMultipleSetting
extends PhabricatorSelectSetting {
const SETTINGKEY = 'multiedit';
const VALUE_SPACES = 'spaces';
const VALUE_SINGLE = 'disable';
public function getSettingName() {
return pht('Edit Mulitple Files');
}
protected function getControlInstructions() {
return pht(
'Some editors support opening multiple files with a single URI. You '.
'can specify the behavior of your editor here.');
}
public function getSettingDefaultValue() {
return self::VALUE_SPACES;
}
protected function getSelectOptions() {
return array(
self::VALUE_SPACES => pht('Supported, Separated by Spaces'),
self::VALUE_SINGLE => pht('Not Supported'),
);
}
}

View file

@ -0,0 +1,33 @@
<?php
final class PhabricatorEditorSetting
extends PhabricatorStringSetting {
const SETTINGKEY = 'editor';
public function getSettingName() {
return pht('Editor Link');
}
protected function getControlInstructions() {
return pht(
"Many text editors can be configured as URI handlers for special ".
"protocols like `editor://`. If you have such an editor, Phabricator ".
"can generate links that you can click to open files locally.".
"\n\n".
"These special variables are supported:".
"\n\n".
"| Value | Replaced With |\n".
"|-------|---------------|\n".
"| `%%f` | Filename |\n".
"| `%%l` | Line Number |\n".
"| `%%r` | Repository Callsign |\n".
"| `%%%%` | Literal `%%` |\n".
"\n\n".
"For complete instructions on editor configuration, ".
"see **[[ %s | %s ]]**.",
PhabricatorEnv::getDoclink('User Guide: Configuring an External Editor'),
pht('User Guide: Configuring an External Editor'));
}
}

View file

@ -0,0 +1,40 @@
<?php
final class PhabricatorMonospacedFontSetting
extends PhabricatorStringSetting {
const SETTINGKEY = 'monospaced';
public function getSettingName() {
return pht('Monospaced Font');
}
protected function getControlInstructions() {
return pht(
'You can customize the font used when showing monospaced text, '.
'including source code. You should enter a valid CSS font declaration '.
'like: `13px Consolas`');
}
public function validateTransactionValue($value) {
if (!strlen($value)) {
return;
}
$filtered = self::filterMonospacedCSSRule($value);
if ($filtered !== $value) {
throw new Exception(
pht(
'Monospaced font value "%s" is unsafe. You may only enter '.
'letters, numbers, spaces, commas, periods, forward slashes '.
'and double quotes.',
$value));
}
}
public static function filterMonospacedCSSRule($monospaced) {
// Prevent the user from doing dangerous things.
return preg_replace('([^a-z0-9 ,"./]+)i', '', $monospaced);
}
}

View file

@ -0,0 +1,34 @@
<?php
final class PhabricatorMonospacedTextareasSetting
extends PhabricatorSelectSetting {
const SETTINGKEY = 'monospaced-textareas';
const VALUE_TEXT_VARIABLE_WIDTH = 'disabled';
const VALUE_TEXT_MONOSPACED = 'enabled';
public function getSettingName() {
return pht('Monospaced Textareas');
}
protected function getControlInstructions() {
return pht(
'You can choose to use either a monospaced or variable-width font '.
'in textareas in the UI. Textareas are used for editing descriptions '.
'and writing comments, among other things.');
}
public function getSettingDefaultValue() {
return self::VALUE_TEXT_VARIABLE_WIDTH;
}
protected function getSelectOptions() {
return array(
self::VALUE_TEXT_VARIABLE_WIDTH => pht('Use Variable-Width Font'),
self::VALUE_TEXT_MONOSPACED => pht('Use Monospaced Font'),
);
}
}

View file

@ -0,0 +1,18 @@
<?php
abstract class PhabricatorStringSetting
extends PhabricatorSetting {
final protected function newCustomEditField($object) {
return $this->newEditField($object, new PhabricatorTextEditField());
}
public function getTransactionNewValue($value) {
if (!strlen($value)) {
return null;
}
return (string)$value;
}
}

View file

@ -0,0 +1,33 @@
<?php
final class PhabricatorTitleGlyphsSetting
extends PhabricatorSelectSetting {
const SETTINGKEY = 'titles';
const VALUE_TITLE_GLYPHS = 'glyph';
const VALUE_TITLE_TEXT = 'text';
public function getSettingName() {
return pht('Page Titles');
}
protected function getControlInstructions() {
return pht(
'Phabricator uses unicode glyphs in page titles to provide a compact '.
'representation of the current application. You can substitute plain '.
'text instead if these glyphs do not display on your system.');
}
public function getSettingDefaultValue() {
return self::VALUE_TITLE_GLYPHS;
}
protected function getSelectOptions() {
return array(
self::VALUE_TITLE_GLYPHS => pht("Use Unicode Glyphs: \xE2\x9A\x99"),
self::VALUE_TITLE_TEXT => pht('Use Plain Text: [Differential]'),
);
}
}

View file

@ -374,7 +374,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
// We can't print this normally because escaping quotation marks will
// break the CSS. Instead, filter it strictly and then mark it as safe.
$monospaced = new PhutilSafeHTML(
PhabricatorUserPreferences::filterMonospacedCSSRule(
PhabricatorMonospacedFontSetting::filterMonospacedCSSRule(
$monospaced));
$font_css = hsprintf(