Differential D7274 Diff 16372 src/applications/settings/panel/PhabricatorSettingsPanelDisplayPreferences.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorSettingsPanelDisplayPreferences.php
Show All 20 Lines | public function processRequest(AphrontRequest $request) { | ||||
$pref_monospaced = PhabricatorUserPreferences::PREFERENCE_MONOSPACED; | $pref_monospaced = PhabricatorUserPreferences::PREFERENCE_MONOSPACED; | ||||
$pref_editor = PhabricatorUserPreferences::PREFERENCE_EDITOR; | $pref_editor = PhabricatorUserPreferences::PREFERENCE_EDITOR; | ||||
$pref_multiedit = PhabricatorUserPreferences::PREFERENCE_MULTIEDIT; | $pref_multiedit = PhabricatorUserPreferences::PREFERENCE_MULTIEDIT; | ||||
$pref_titles = PhabricatorUserPreferences::PREFERENCE_TITLES; | $pref_titles = PhabricatorUserPreferences::PREFERENCE_TITLES; | ||||
$pref_monospaced_textareas = | $pref_monospaced_textareas = | ||||
PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS; | PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS; | ||||
$errors = array(); | |||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$monospaced = $request->getStr($pref_monospaced); | $monospaced = $request->getStr($pref_monospaced); | ||||
if (!preg_match('/^[^"]*("[^"]*"[^"]*)*$/', $monospaced) || | |||||
// Prevent the user from doing stupid things. | preg_match('/[^a-z0-9 ,"-](?=(?:[^"]*"[^"]*")*[^"]*$)/i', | ||||
$monospaced = preg_replace('/[^a-z0-9 ,"]+/i', '', $monospaced); | $monospaced)) { | ||||
$errors[] = pht( | |||||
'Monospaced Font definition must not contain any mismatched double '. | |||||
'quotes, and any font names that do not consist of purely '. | |||||
'alphanumeric, space, comma, double quote, or hyphen characters '. | |||||
'must be wrapped in double quotes.'); | |||||
} else { | |||||
$preferences->setPreference($pref_monospaced, $monospaced); | |||||
} | |||||
$preferences->setPreference($pref_titles, $request->getStr($pref_titles)); | $preferences->setPreference($pref_titles, $request->getStr($pref_titles)); | ||||
$preferences->setPreference($pref_editor, $request->getStr($pref_editor)); | $preferences->setPreference($pref_editor, $request->getStr($pref_editor)); | ||||
$preferences->setPreference( | $preferences->setPreference( | ||||
$pref_multiedit, | $pref_multiedit, | ||||
$request->getStr($pref_multiedit)); | $request->getStr($pref_multiedit)); | ||||
$preferences->setPreference($pref_monospaced, $monospaced); | |||||
$preferences->setPreference( | $preferences->setPreference( | ||||
$pref_monospaced_textareas, | $pref_monospaced_textareas, | ||||
$request->getStr($pref_monospaced_textareas)); | $request->getStr($pref_monospaced_textareas)); | ||||
$preferences->save(); | $preferences->save(); | ||||
if (!$errors) { | |||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($this->getPanelURI('?saved=true')); | ->setURI($this->getPanelURI('?saved=true')); | ||||
} | } | ||||
} | |||||
$example_string = <<<EXAMPLE | $example_string = <<<EXAMPLE | ||||
// This is what your monospaced font currently looks like. | // This is what your monospaced font currently looks like. | ||||
function helloWorld() { | function helloWorld() { | ||||
alert("Hello world!"); | alert("Hello world!"); | ||||
} | } | ||||
EXAMPLE; | EXAMPLE; | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | $form = id(new AphrontFormView()) | ||||
pht('Show all textareas using the monospaced font defined above.')) | pht('Show all textareas using the monospaced font defined above.')) | ||||
->addButton('disabled', pht('Disabled'), null)); | ->addButton('disabled', pht('Disabled'), null)); | ||||
$form->appendChild( | $form->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->setValue(pht('Save Preferences'))); | ->setValue(pht('Save Preferences'))); | ||||
$error_view = null; | $error_view = null; | ||||
if (!$errors) { | |||||
if ($request->getStr('saved') === 'true') { | if ($request->getStr('saved') === 'true') { | ||||
$error_view = id(new AphrontErrorView()) | $error_view = id(new AphrontErrorView()) | ||||
->setTitle(pht('Preferences Saved')) | ->setTitle(pht('Preferences Saved')) | ||||
->setSeverity(AphrontErrorView::SEVERITY_NOTICE) | ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) | ||||
->setErrors(array(pht('Your preferences have been saved.'))); | ->setErrors(array(pht('Your preferences have been saved.'))); | ||||
} | } | ||||
} else { | |||||
$error_view = id(new AphrontErrorView()) | |||||
->setTitle(pht('Form Errors')) | |||||
->setErrors($errors); | |||||
} | |||||
$form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText(pht('Display Preferences')) | ->setHeaderText(pht('Display Preferences')) | ||||
->setFormError($error_view) | ->setFormError($error_view) | ||||
->setForm($form); | ->setForm($form); | ||||
return array( | return array( | ||||
$form_box, | $form_box, | ||||
); | ); | ||||
} | } | ||||
} | } | ||||