Merge branch 'aektos-extract_html_in_prefs_manage_to_twig'
Fixes #15098 Closes #15099 Closes #15055
This commit is contained in:
commit
0868cd17b1
@ -42,6 +42,13 @@ class MessageExtension extends AbstractExtension
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
new TwigFilter(
|
||||
'raw_success',
|
||||
function ($string) {
|
||||
return Message::rawSuccess($string)->getDisplay();
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ namespace PhpMyAdmin\Twig;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Class SanitizeExtension
|
||||
@ -44,4 +45,20 @@ class SanitizeExtension extends AbstractExtension
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction(
|
||||
'get_js_value',
|
||||
'PhpMyAdmin\Sanitize::getJsValue',
|
||||
['is_safe' => ['html']]
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,6 +178,11 @@ class UtilExtension extends AbstractExtension
|
||||
'timespan_format',
|
||||
'PhpMyAdmin\Util::timespanFormat'
|
||||
),
|
||||
new TwigFunction(
|
||||
'generate_hidden_max_file_size',
|
||||
'PhpMyAdmin\Util::generateHiddenMaxFileSize',
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
211
prefs_manage.php
211
prefs_manage.php
@ -13,11 +13,9 @@ use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\File;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\ThemeManager;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\UserPreferences;
|
||||
use PhpMyAdmin\Util;
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
if (! defined('ROOT_PATH')) {
|
||||
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
|
||||
@ -28,6 +26,8 @@ if (! defined('ROOT_PATH')) {
|
||||
*/
|
||||
require_once ROOT_PATH . 'libraries/common.inc.php';
|
||||
|
||||
$template = new Template();
|
||||
|
||||
$userPreferences = new UserPreferences();
|
||||
|
||||
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
|
||||
@ -123,33 +123,13 @@ if (isset($_POST['submit_export'])
|
||||
if (! $all_ok) {
|
||||
// mimic original form and post json in a hidden field
|
||||
include ROOT_PATH . 'libraries/user_preferences.inc.php';
|
||||
$msg = Message::error(
|
||||
__('Configuration contains incorrect data for some fields.')
|
||||
);
|
||||
$msg->display();
|
||||
echo '<div class="config-form">';
|
||||
echo $form_display->displayErrors();
|
||||
echo '</div>';
|
||||
echo '<form action="prefs_manage.php" method="post">';
|
||||
echo Url::getHiddenInputs() , "\n";
|
||||
echo '<input type="hidden" name="json" value="'
|
||||
, htmlspecialchars($json) , '">';
|
||||
echo '<input type="hidden" name="fix_errors" value="1">';
|
||||
if (! empty($_POST['import_merge'])) {
|
||||
echo '<input type="hidden" name="import_merge" value="1">';
|
||||
}
|
||||
if ($return_url) {
|
||||
echo '<input type="hidden" name="return_url" value="'
|
||||
, htmlspecialchars($return_url) , '">';
|
||||
}
|
||||
echo '<p>';
|
||||
echo __('Do you want to import remaining settings?');
|
||||
echo '</p>';
|
||||
echo '<input class="btn btn-secondary" type="submit" name="submit_import" value="'
|
||||
, __('Yes') , '">';
|
||||
echo '<input class="btn btn-secondary" type="submit" name="submit_ignore" value="'
|
||||
, __('No') , '">';
|
||||
echo '</form>';
|
||||
|
||||
echo $template->render('prefs_manage_error', [
|
||||
'form_errors' => $form_display->displayErrors(),
|
||||
'json' => $json,
|
||||
'import_merge' => isset($_POST['import_merge']) ? $_POST['import_merge'] : null,
|
||||
'return_url' => $return_url
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -173,7 +153,7 @@ if (isset($_POST['submit_export'])
|
||||
$result = $userPreferences->save($cf->getConfigArray());
|
||||
if ($result === true) {
|
||||
if ($return_url) {
|
||||
$query = PhpMyAdmin\Util::splitURLQuery($return_url);
|
||||
$query = PhpMyAdmin\Util::splitURLQuery($return_url);
|
||||
$return_url = parse_url($return_url, PHP_URL_PATH);
|
||||
|
||||
foreach ($query as $q) {
|
||||
@ -211,7 +191,7 @@ if (isset($_POST['submit_export'])
|
||||
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('config.js');
|
||||
|
||||
require ROOT_PATH . 'libraries/user_preferences.inc.php';
|
||||
@ -219,168 +199,15 @@ if ($error) {
|
||||
if (! $error instanceof Message) {
|
||||
$error = Message::error($error);
|
||||
}
|
||||
$error->display();
|
||||
$error->getDisplay();
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php
|
||||
Sanitize::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
|
||||
?>
|
||||
</script>
|
||||
<div id="maincontainer">
|
||||
<div id="main_pane_left">
|
||||
<div class="group">
|
||||
<?php
|
||||
echo '<h2>' , __('Import') , '</h2>'
|
||||
, '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
|
||||
, ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
|
||||
, Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
|
||||
, Url::getHiddenInputs()
|
||||
, '<input type="hidden" name="json" value="">'
|
||||
, '<input type="radio" id="import_text_file" name="import_type"'
|
||||
, ' value="text_file" checked="checked">'
|
||||
, '<label for="import_text_file">' . __('Import from file') . '</label>'
|
||||
, '<div id="opts_import_text_file" class="prefsmanage_opts">'
|
||||
, '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
|
||||
, '<input type="file" name="import_file" id="input_import_file">'
|
||||
, '</div>'
|
||||
, '<input type="radio" id="import_local_storage" name="import_type"'
|
||||
, ' value="local_storage" disabled="disabled">'
|
||||
, '<label for="import_local_storage">'
|
||||
, __('Import from browser\'s storage') , '</label>'
|
||||
, '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
|
||||
, '<div class="localStorage-supported">'
|
||||
, __('Settings will be imported from your browser\'s local storage.')
|
||||
, '<br>'
|
||||
, '<div class="localStorage-exists">'
|
||||
, __('Saved on: @DATE@')
|
||||
, '</div>'
|
||||
, '<div class="localStorage-empty">';
|
||||
Message::notice(__('You have no saved settings!'))->display();
|
||||
echo '</div>'
|
||||
, '</div>'
|
||||
, '<div class="localStorage-unsupported">';
|
||||
Message::notice(
|
||||
__('This feature is not supported by your web browser')
|
||||
)->display();
|
||||
echo '</div>'
|
||||
, '</div>'
|
||||
, '<input type="checkbox" id="import_merge" name="import_merge">'
|
||||
, '<label for="import_merge">'
|
||||
, __('Merge with current configuration') . '</label>'
|
||||
, '<br><br>'
|
||||
, '<input class="btn btn-primary" type="submit" name="submit_import" value="'
|
||||
, __('Go') . '">'
|
||||
, '</form>'
|
||||
, '</div>';
|
||||
if (@file_exists(ROOT_PATH . 'setup/index.php') && ! @file_exists(CONFIG_FILE)) {
|
||||
// show only if setup script is available, allows to disable this message
|
||||
// by simply removing setup directory
|
||||
// Also do not show in config exists (and setup would refuse to work)
|
||||
?>
|
||||
<div class="group">
|
||||
<h2><?php echo __('More settings') ?></h2>
|
||||
<div class="group-cnt">
|
||||
<?php
|
||||
echo sprintf(
|
||||
__(
|
||||
'You can set more settings by modifying config.inc.php, eg. '
|
||||
. 'by using %sSetup script%s.'
|
||||
),
|
||||
'<a href="setup/index.php" target="_blank">',
|
||||
'</a>'
|
||||
) , PhpMyAdmin\Util::showDocu('setup', 'setup-script');
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div id="main_pane_right">
|
||||
<div class="group">
|
||||
<h2><?php echo __('Export'); ?></h2>
|
||||
<div class="click-hide-message group-cnt hide">
|
||||
<?php
|
||||
Message::rawSuccess(
|
||||
__('Configuration has been saved.')
|
||||
)->display();
|
||||
?>
|
||||
</div>
|
||||
<form class="group-cnt prefs-form disableAjax" name="prefs_export"
|
||||
action="prefs_manage.php" method="post">
|
||||
<?php echo Url::getHiddenInputs(); ?>
|
||||
<div>
|
||||
<input type="radio" id="export_text_file" name="export_type"
|
||||
value="text_file" checked="checked">
|
||||
<label for="export_text_file">
|
||||
<?php echo __('Save as JSON file'); ?>
|
||||
</label><br>
|
||||
<input type="radio" id="export_php_file" name="export_type"
|
||||
value="php_file">
|
||||
<label for="export_php_file">
|
||||
<?php echo __('Save as PHP file'); ?>
|
||||
</label><br>
|
||||
<input type="radio" id="export_local_storage" name="export_type"
|
||||
value="local_storage" disabled="disabled">
|
||||
<label for="export_local_storage">
|
||||
<?php echo __('Save to browser\'s storage'); ?></label>
|
||||
</div>
|
||||
<div id="opts_export_local_storage"
|
||||
class="prefsmanage_opts disabled">
|
||||
<span class="localStorage-supported">
|
||||
<?php
|
||||
echo __(
|
||||
'Settings will be saved in your browser\'s local '
|
||||
. 'storage.'
|
||||
);
|
||||
?>
|
||||
<div class="localStorage-exists">
|
||||
<b>
|
||||
<?php
|
||||
echo __(
|
||||
'Existing settings will be overwritten!'
|
||||
);
|
||||
?>
|
||||
</b>
|
||||
</div>
|
||||
</span>
|
||||
<div class="localStorage-unsupported">
|
||||
<?php
|
||||
Message::notice(
|
||||
__('This feature is not supported by your web browser')
|
||||
)->display();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<?php
|
||||
echo '<input class="btn btn-primary" type="submit" name="submit_export" value="' , __(
|
||||
'Go'
|
||||
) , '">';
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<div class="group">
|
||||
<h2><?php echo __('Reset'); ?></h2>
|
||||
<form class="group-cnt prefs-form disableAjax" name="prefs_reset"
|
||||
action="prefs_manage.php" method="post">
|
||||
<?php
|
||||
echo Url::getHiddenInputs() , __(
|
||||
'You can reset all your settings and restore them to default '
|
||||
. 'values.'
|
||||
);
|
||||
?>
|
||||
<br><br>
|
||||
<input class="btn btn-secondary" type="submit" name="submit_clear"
|
||||
value="<?php echo __('Reset'); ?>">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clearfloat">
|
||||
</div>
|
||||
|
||||
<?php
|
||||
echo $template->render('prefs_manage', [
|
||||
'error' => $error,
|
||||
'max_upload_size' => $GLOBALS['max_upload_size'],
|
||||
'exists_setup_and_not_exists_config' => @file_exists(ROOT_PATH . 'setup/index.php') && ! @file_exists(CONFIG_FILE),
|
||||
]);
|
||||
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('_disableNaviSettings', true);
|
||||
} else {
|
||||
|
||||
112
templates/prefs_manage.twig
Normal file
112
templates/prefs_manage.twig
Normal file
@ -0,0 +1,112 @@
|
||||
{{ error|raw }}
|
||||
<script type="text/javascript">
|
||||
{{ get_js_value("PMA_messages['strSavedOn']", 'Saved on: @DATE@'|trans) }}
|
||||
</script>
|
||||
<div id="maincontainer">
|
||||
<div id="main_pane_left">
|
||||
<div class="group">
|
||||
<h2> {% trans 'Import' %} </h2>
|
||||
<form class="group-cnt prefs-form disableAjax" name="prefs_import" action="prefs_manage.php" method="post"
|
||||
enctype="multipart/form-data">
|
||||
{{ generate_hidden_max_file_size(max_upload_size) }}
|
||||
{{ get_hidden_inputs() }}
|
||||
<input type="hidden" name="json" value="">
|
||||
<input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked">
|
||||
<label for="import_text_file"> {% trans 'Import from file' %} </label>
|
||||
<div id="opts_import_text_file" class="prefsmanage_opts">
|
||||
<label for="input_import_file"> {% trans 'Browse your computer:' %} </label>
|
||||
<input type="file" name="import_file" id="input_import_file">
|
||||
</div>
|
||||
<input type="radio" id="import_local_storage" name="import_type" value="local_storage"
|
||||
disabled="disabled">
|
||||
<label for="import_local_storage"> {% trans 'Import from browser\'s storage' %} </label>
|
||||
<div id="opts_import_local_storage" class="prefsmanage_opts disabled">
|
||||
<div class="localStorage-supported">
|
||||
{% trans 'Settings will be imported from your browser\'s local storage.' %}
|
||||
<br>
|
||||
<div class="localStorage-exists">
|
||||
{% trans 'Saved on: @DATE@' %}
|
||||
</div>
|
||||
<div class="localStorage-empty">
|
||||
{{ 'You have no saved settings!'|trans|notice }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="localStorage-unsupported">
|
||||
{{ 'This feature is not supported by your web browser'|trans|notice }}
|
||||
</div>
|
||||
</div>
|
||||
<input type="checkbox" id="import_merge" name="import_merge">
|
||||
<label for="import_merge"> {% trans 'Merge with current configuration' %} </label>
|
||||
<br><br>
|
||||
<input class="btn btn-primary" type="submit" name="submit_import" value="{{ 'Go'|trans }}">
|
||||
</form>
|
||||
</div>
|
||||
{% if exists_setup_and_not_exists_config %}
|
||||
{# show only if setup script is available, allows to disable this message #}
|
||||
{# by simply removing setup directory #}
|
||||
{# Also do not show in config exists (and setup would refuse to work) #}
|
||||
<div class="group">
|
||||
<h2>{% trans 'More settings' %}</h2>
|
||||
<div class="group-cnt">
|
||||
{{ 'You can set more settings by modifying config.inc.php, eg. by using %sSetup script%s.'|trans|format('<a href="setup/index.php" target="_blank">','</a>')|raw }}
|
||||
{{ show_docu('setup', 'setup-script') }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="main_pane_right">
|
||||
<div class="group">
|
||||
<h2>{% trans 'Export' %}</h2>
|
||||
<div class="click-hide-message group-cnt hide">
|
||||
{{ 'Configuration has been saved.'|trans|raw_success }}
|
||||
</div>
|
||||
<form class="group-cnt prefs-form disableAjax" name="prefs_export"
|
||||
action="prefs_manage.php" method="post">
|
||||
{{ get_hidden_inputs() }}
|
||||
<div>
|
||||
<input type="radio" id="export_text_file" name="export_type"
|
||||
value="text_file" checked="checked">
|
||||
<label for="export_text_file">
|
||||
{% trans 'Save as JSON file' %}
|
||||
</label><br>
|
||||
<input type="radio" id="export_php_file" name="export_type" value="php_file">
|
||||
<label for="export_php_file">
|
||||
{% trans 'Save as PHP file' %}
|
||||
</label><br>
|
||||
<input type="radio" id="export_local_storage" name="export_type" value="local_storage"
|
||||
disabled="disabled">
|
||||
<label for="export_local_storage">
|
||||
{% trans 'Save to browser\'s storage' %}
|
||||
</label>
|
||||
</div>
|
||||
<div id="opts_export_local_storage"
|
||||
class="prefsmanage_opts disabled">
|
||||
<span class="localStorage-supported">
|
||||
{% trans 'Settings will be saved in your browser\'s local storage.' %}
|
||||
<div class="localStorage-exists">
|
||||
<b>
|
||||
{% trans 'Existing settings will be overwritten!' %}
|
||||
</b>
|
||||
</div>
|
||||
</span>
|
||||
<div class="localStorage-unsupported">
|
||||
{{ 'This feature is not supported by your web browser'|trans|notice }}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<input class="btn btn-primary" type="submit" name="submit_export" value="{% trans 'Go' %}">
|
||||
</form>
|
||||
</div>
|
||||
<div class="group">
|
||||
<h2>{% trans 'Reset' %}</h2>
|
||||
<form class="group-cnt prefs-form disableAjax" name="prefs_reset"
|
||||
action="prefs_manage.php" method="post">
|
||||
{{ get_hidden_inputs() }}
|
||||
{% trans 'You can reset all your settings and restore them to default values.' %}
|
||||
<br><br>
|
||||
<input class="btn btn-secondary" type="submit" name="submit_clear" value="{% trans 'Reset' %}">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clearfloat">
|
||||
</div>
|
||||
20
templates/prefs_manage_error.twig
Normal file
20
templates/prefs_manage_error.twig
Normal file
@ -0,0 +1,20 @@
|
||||
{{ 'Configuration contains incorrect data for some fields.'|trans|error }}
|
||||
<div class="config-form">
|
||||
{{ form_errors|raw }}
|
||||
</div>
|
||||
<form action="prefs_manage.php" method="post">
|
||||
{{ get_hidden_inputs() }}
|
||||
<input type="hidden" name="json" value="{{ json }}">
|
||||
<input type="hidden" name="fix_errors" value="1">
|
||||
{% if import_merge is not empty %}
|
||||
<input type="hidden" name="import_merge" value="1">
|
||||
{% endif %}
|
||||
{% if return_url %}
|
||||
<input type="hidden" name="return_url" value="{{ return_url }}">
|
||||
{% endif %}
|
||||
<p>
|
||||
{% trans 'Do you want to import remaining settings?' %}
|
||||
</p>
|
||||
<input class="btn btn-secondary" type="submit" name="submit_import" value="{{ 'Yes'|trans }}">
|
||||
<input class="btn btn-secondary" type="submit" name="submit_ignore" value="{{ 'No'|trans }}">
|
||||
</form>
|
||||
Loading…
Reference in New Issue
Block a user