diff --git a/libraries/classes/SqlQueryForm.php b/libraries/classes/SqlQueryForm.php index 25c1a9ba8ff5..7c3e6660cfb7 100644 --- a/libraries/classes/SqlQueryForm.php +++ b/libraries/classes/SqlQueryForm.php @@ -20,6 +20,19 @@ */ class SqlQueryForm { + /** + * @var Template + */ + private $template; + + /** + * @param Template $template Template object + */ + public function __construct(Template $template) + { + $this->template = $template; + } + /** * return HTML for the sql query boxes * @@ -203,179 +216,21 @@ public function getHtmlForInsert( $query = '', $delimiter = ';' ) { - // enable auto select text in textarea - if ($GLOBALS['cfg']['TextareaAutoSelect']) { - $auto_sel = ' onclick="Functions.selectContent(this, sqlBoxLocked, true);"'; - } else { - $auto_sel = ''; - } - - $locking = ''; - $height = $GLOBALS['cfg']['TextareaRows'] * 2; - list($legend, $query, $columns_list) = $this->init($query); - - if (! empty($columns_list)) { - $sqlquerycontainer_id = 'sqlquerycontainer'; - } else { - $sqlquerycontainer_id = 'sqlquerycontainerfull'; - } - - $html = '' - . '
' - . '
'; - $html .= '' . $legend . ''; - $html .= '
'; - $html .= '
' - . ''; - $html .= '
'; - // Add buttons to generate query easily for - // select all, single select, insert, update and delete - if (! empty($columns_list)) { - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - } - $html .= ''; - if ($GLOBALS['cfg']['CodemirrorEnable']) { - $html .= ''; - } - $html .= ''; - - // parameter binding - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= Util::showDocu('faq', 'faq6-40'); - $html .= '
'; - $html .= '
'; - - $html .= '
' . "\n"; - - if (! empty($columns_list)) { - $html .= '
' - . '' - . '' - . '
'; - if (Util::showIcons('ActionLinksMode')) { - $html .= ''; - } else { - $html .= ''; - } - $html .= '
' . "\n" - . '
' . "\n"; - } - - $html .= '
' . "\n"; - $html .= '
' . "\n"; - $cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']); - if ($cfgBookmark) { - $html .= '
'; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - } - $html .= '
' . "\n"; - $html .= '
' . "\n" - . '
' . "\n"; - - $html .= '
' . "\n"; - $html .= '
' . "\n"; - $html .= '
' . "\n"; - - $html .= '
'; - $html .= '' . "\n"; - $html .= ' ]'; - $html .= '
'; - - $html .= '
'; - $html .= '' - . ''; - $html .= '
'; - - $html .= '
'; - $html .= '' - . ''; - $html .= '
'; - - $html .= '
'; - $html .= '' - . ''; - $html .= '
'; - - // Disable/Enable foreign key checks - $html .= '
'; - $html .= Util::getFKCheckbox(); - $html .= '
'; - - $html .= '' . "\n"; - $html .= '
' . "\n"; - $html .= '
' . "\n"; - - return $html; + return $this->template->render('sql/query/insert', [ + 'legend' => $legend, + 'textarea_cols' => $GLOBALS['cfg']['TextareaCols'], + 'textarea_rows' => $GLOBALS['cfg']['TextareaRows'], + 'textarea_auto_select' => $GLOBALS['cfg']['TextareaAutoSelect'], + 'query' => $query, + 'columns_list' => $columns_list, + 'codemirror_enable' => $GLOBALS['cfg']['CodemirrorEnable'], + 'has_bookmark' => $cfgBookmark, + 'delimiter' => $delimiter, + 'retain_query_box' => $GLOBALS['cfg']['RetainQueryBox'] !== false, + ]); } /** diff --git a/services.yml b/services.yml index 55f6d9234005..af4f990c70c6 100644 --- a/services.yml +++ b/services.yml @@ -116,6 +116,8 @@ services: sql_query_form: class: 'PhpMyAdmin\SqlQueryForm' + arguments: + template: '@template' status_data: class: 'PhpMyAdmin\Server\Status\Data' diff --git a/templates/sql/query/insert.twig b/templates/sql/query/insert.twig new file mode 100644 index 000000000000..fd864b76e525 --- /dev/null +++ b/templates/sql/query/insert.twig @@ -0,0 +1,115 @@ + +
+
+ {{ legend|raw }} +
+
+ +
+ + {% if columns_list is not empty %} + + + + + + {% endif %} + + {% if codemirror_enable %} + + {% endif %} + + +
+ + + {{ show_docu('faq', 'faq6-40') }} +
+
+
+ + {% if columns_list is not empty %} +
+ + + +
+ {% if show_icons('ActionLinksMode') %} + + {% else %} + + {% endif %} +
+
+ {% endif %} + +
+
+ + {% if has_bookmark %} +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ {% endif %} + +
+
+
+ +
+
+ +
+ [ + + + ] +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ {{ get_fk_checkbox() }} +
+ + + +
+
diff --git a/test/classes/SqlQueryFormTest.php b/test/classes/SqlQueryFormTest.php index 6c6e188cc577..5552ccb7b866 100644 --- a/test/classes/SqlQueryFormTest.php +++ b/test/classes/SqlQueryFormTest.php @@ -11,7 +11,7 @@ use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\SqlQueryForm; -use PhpMyAdmin\Theme; +use PhpMyAdmin\Template; use PhpMyAdmin\Url; use PhpMyAdmin\Util; use PHPUnit\Framework\TestCase; @@ -40,7 +40,7 @@ class SqlQueryFormTest extends TestCase */ protected function setUp(): void { - $this->sqlQueryForm = new SqlQueryForm(); + $this->sqlQueryForm = new SqlQueryForm(new Template()); //$GLOBALS $GLOBALS['max_upload_size'] = 100; diff --git a/test/classes/TrackingTest.php b/test/classes/TrackingTest.php index 929c942ad17a..740401054361 100644 --- a/test/classes/TrackingTest.php +++ b/test/classes/TrackingTest.php @@ -73,7 +73,8 @@ protected function setUp(): void $GLOBALS['dbi'] = $dbi; - $this->tracking = new Tracking(new SqlQueryForm(), new Template(), new Relation($dbi)); + $template = new Template(); + $this->tracking = new Tracking(new SqlQueryForm($template), $template, new Relation($dbi)); } /** @@ -208,7 +209,8 @@ public function testGetHtmlForMain() /* Here, we need to overwrite the object written in the setUp function because $dbi object is not the one mocked at the beginning. */ - $this->tracking = new Tracking(new SqlQueryForm(), new Template(), new Relation($dbi)); + $template = new Template(); + $this->tracking = new Tracking(new SqlQueryForm($template), $template, new Relation($dbi)); $html = $this->tracking->getHtmlForMainPage( $url_params,