3
final class PhabricatorDisplayPreferencesSettingsPanel
4
extends PhabricatorSettingsPanel {
6
public function getPanelKey() {
10
public function getPanelName() {
11
return pht('Display Preferences');
14
public function getPanelGroup() {
15
return pht('Application Settings');
18
public function processRequest(AphrontRequest $request) {
19
$user = $request->getUser();
20
$preferences = $user->loadPreferences();
22
$pref_monospaced = PhabricatorUserPreferences::PREFERENCE_MONOSPACED;
23
$pref_editor = PhabricatorUserPreferences::PREFERENCE_EDITOR;
24
$pref_multiedit = PhabricatorUserPreferences::PREFERENCE_MULTIEDIT;
25
$pref_titles = PhabricatorUserPreferences::PREFERENCE_TITLES;
26
$pref_monospaced_textareas =
27
PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS;
31
if ($request->isFormPost()) {
32
$monospaced = $request->getStr($pref_monospaced);
34
// Prevent the user from doing stupid things.
35
$monospaced = preg_replace('/[^a-z0-9 ,".]+/i', '', $monospaced);
37
$preferences->setPreference($pref_titles, $request->getStr($pref_titles));
38
$preferences->setPreference($pref_editor, $request->getStr($pref_editor));
39
$preferences->setPreference(
41
$request->getStr($pref_multiedit));
42
$preferences->setPreference($pref_monospaced, $monospaced);
43
$preferences->setPreference(
44
$pref_monospaced_textareas,
45
$request->getStr($pref_monospaced_textareas));
47
$editor_pattern = $preferences->getPreference($pref_editor);
48
if (strlen($editor_pattern)) {
49
$ok = PhabricatorHelpEditorProtocolController::hasAllowedProtocol(
52
$allowed_key = 'uri.allowed-editor-protocols';
53
$allowed_protocols = PhabricatorEnv::getEnvConfig($allowed_key);
55
$proto_names = array();
56
foreach (array_keys($allowed_protocols) as $protocol) {
57
$proto_names[] = $protocol.'://';
61
'Editor link has an invalid or missing protocol. You must '.
62
'use a whitelisted editor protocol from this list: %s. To '.
63
'add protocols, update %s.',
64
implode(', ', $proto_names),
65
phutil_tag('tt', array(), $allowed_key));
67
$e_editor = pht('Invalid');
73
return id(new AphrontRedirectResponse())
74
->setURI($this->getPanelURI('?saved=true'));
78
$example_string = <<<EXAMPLE
79
// This is what your monospaced font currently looks like.
80
function helloWorld() {
81
alert("Hello world!");
85
$editor_doc_link = phutil_tag(
88
'href' => PhabricatorEnv::getDoclink(
89
'User Guide: Configuring an External Editor'),
91
pht('User Guide: Configuring an External Editor'));
93
$font_default = PhabricatorEnv::getEnvConfig('style.monospace');
95
$pref_monospaced_textareas_value = $preferences
96
->getPreference($pref_monospaced_textareas);
97
if (!$pref_monospaced_textareas_value) {
98
$pref_monospaced_textareas_value = 'disabled';
101
$editor_instructions = pht('Link to edit files in external editor. '.
102
'%%f is replaced by filename, %%l by line number, %%r by repository '.
103
'callsign, %%%% by literal %%. For documentation, see: %s',
106
$form = id(new AphrontFormView())
109
id(new AphrontFormSelectControl())
110
->setLabel(pht('Page Titles'))
111
->setName($pref_titles)
112
->setValue($preferences->getPreference($pref_titles))
116
pht("In page titles, show Tool names as unicode glyphs: ".
119
pht('In page titles, show Tool names as plain text: '.
123
id(new AphrontFormTextControl())
124
->setLabel(pht('Editor Link'))
125
->setName($pref_editor)
126
->setCaption($editor_instructions)
127
->setError($e_editor)
128
->setValue($preferences->getPreference($pref_editor)))
130
id(new AphrontFormSelectControl())
131
->setLabel(pht('Edit Multiple Files'))
132
->setName($pref_multiedit)
134
'' => pht('Supported (paths separated by spaces)'),
135
'disable' => pht('Not Supported'),
137
->setValue($preferences->getPreference($pref_multiedit)))
139
id(new AphrontFormTextControl())
140
->setLabel(pht('Monospaced Font'))
141
->setName($pref_monospaced)
143
->setCaption(hsprintf(
145
pht('Overrides default fonts in tools like Differential.'),
148
->setValue($preferences->getPreference($pref_monospaced)))
150
id(new AphrontFormMarkupControl())
151
->setValue(phutil_tag(
153
array('class' => 'PhabricatorMonospaced'),
156
id(new AphrontFormRadioButtonControl())
157
->setLabel(pht('Monospaced Textareas'))
158
->setName($pref_monospaced_textareas)
159
->setValue($pref_monospaced_textareas_value)
160
->addButton('enabled', pht('Enabled'),
161
pht('Show all textareas using the monospaced font defined above.'))
162
->addButton('disabled', pht('Disabled'), null));
165
id(new AphrontFormSubmitControl())
166
->setValue(pht('Save Preferences')));
168
$form_box = id(new PHUIObjectBoxView())
169
->setHeaderText(pht('Display Preferences'))
170
->setFormErrors($errors)
171
->setFormSaved($request->getStr('saved') === 'true')