Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/setting/PhabricatorEditorSetting.php
| <?php | <?php | ||||
| final class PhabricatorEditorSetting | final class PhabricatorEditorSetting | ||||
| extends PhabricatorStringSetting { | extends PhabricatorStringSetting { | ||||
| const SETTINGKEY = 'editor'; | const SETTINGKEY = 'editor'; | ||||
| public function getSettingName() { | public function getSettingName() { | ||||
| return pht('Editor Link'); | return pht('Editor Link'); | ||||
| } | } | ||||
| public function getSettingPanelKey() { | |||||
| return PhabricatorDisplayPreferencesSettingsPanel::PANELKEY; | |||||
| } | |||||
| protected function getSettingOrder() { | |||||
| return 300; | |||||
| } | |||||
| protected function getControlInstructions() { | protected function getControlInstructions() { | ||||
| return pht( | return pht( | ||||
| "Many text editors can be configured as URI handlers for special ". | "Many text editors can be configured as URI handlers for special ". | ||||
| "protocols like `editor://`. If you have such an editor, Phabricator ". | "protocols like `editor://`. If you have such an editor, Phabricator ". | ||||
| "can generate links that you can click to open files locally.". | "can generate links that you can click to open files locally.". | ||||
| "\n\n". | "\n\n". | ||||
| "These special variables are supported:". | "These special variables are supported:". | ||||
| "\n\n". | "\n\n". | ||||
| "| Value | Replaced With |\n". | "| Value | Replaced With |\n". | ||||
| "|-------|---------------|\n". | "|-------|---------------|\n". | ||||
| "| `%%f` | Filename |\n". | "| `%%f` | Filename |\n". | ||||
| "| `%%l` | Line Number |\n". | "| `%%l` | Line Number |\n". | ||||
| "| `%%r` | Repository Callsign |\n". | "| `%%r` | Repository Callsign |\n". | ||||
| "| `%%%%` | Literal `%%` |\n". | "| `%%%%` | Literal `%%` |\n". | ||||
| "\n\n". | "\n\n". | ||||
| "For complete instructions on editor configuration, ". | "For complete instructions on editor configuration, ". | ||||
| "see **[[ %s | %s ]]**.", | "see **[[ %s | %s ]]**.", | ||||
| PhabricatorEnv::getDoclink('User Guide: Configuring an External Editor'), | PhabricatorEnv::getDoclink('User Guide: Configuring an External Editor'), | ||||
| pht('User Guide: Configuring an External Editor')); | pht('User Guide: Configuring an External Editor')); | ||||
| } | } | ||||
| public function validateTransactionValue($value) { | |||||
| $ok = PhabricatorHelpEditorProtocolController::hasAllowedProtocol($value); | |||||
| if ($ok) { | |||||
| return; | |||||
| } | |||||
| $allowed_key = 'uri.allowed-editor-protocols'; | |||||
| $allowed_protocols = PhabricatorEnv::getEnvConfig($allowed_key); | |||||
| $proto_names = array(); | |||||
| foreach (array_keys($allowed_protocols) as $protocol) { | |||||
| $proto_names[] = $protocol.'://'; | |||||
| } | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Editor link has an invalid or missing protocol. You must '. | |||||
| 'use a whitelisted editor protocol from this list: %s. To '. | |||||
| 'add protocols, update "%s" in Config.', | |||||
| implode(', ', $proto_names), | |||||
| $allowed_key)); | |||||
| } | |||||
| } | } | ||||