diff --git a/libraries/classes/Rte/RteList.php b/libraries/classes/Rte/RteList.php index 79d0e2b605..9021dfcd7b 100644 --- a/libraries/classes/Rte/RteList.php +++ b/libraries/classes/Rte/RteList.php @@ -207,36 +207,20 @@ class RteList * Creates the contents for a row in the list of routines * * @param array $routine An array of routine data - * @param string $rowclass Additional class + * @param string $rowClass Additional class * * @return string HTML code of a row for the list of routines */ - public function getRoutineRow(array $routine, $rowclass = '') + public function getRoutineRow(array $routine, $rowClass = '') { - global $db, $table, $titles; + global $db, $table; - $sql_drop = sprintf( + $sqlDrop = sprintf( 'DROP %s IF EXISTS %s', $routine['type'], Util::backquote($routine['name']) ); - $retval = " \n"; - $retval .= " \n"; - $retval .= ' '; - $retval .= " \n"; - $retval .= " \n"; - $retval .= " " - . htmlspecialchars($sql_drop) . "\n"; - $retval .= " \n"; - $retval .= ' ' - . htmlspecialchars($routine['name']) . "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= " \n"; - // this is for our purpose to decide whether to // show the edit link or not, so we need the DEFINER for the routine $where = 'ROUTINE_SCHEMA ' . Util::getCollateForIS() . '=' @@ -244,29 +228,14 @@ class RteList . "AND SPECIFIC_NAME='" . $this->dbi->escapeString($routine['name']) . "'" . "AND ROUTINE_TYPE='" . $this->dbi->escapeString($routine['type']) . "'"; $query = 'SELECT `DEFINER` FROM INFORMATION_SCHEMA.ROUTINES WHERE ' . $where . ';'; - $routine_definer = $this->dbi->fetchValue($query); + $routineDefiner = $this->dbi->fetchValue($query); - $curr_user = $this->dbi->getCurrentUser(); + $currentUser = $this->dbi->getCurrentUser(); // Since editing a procedure involved dropping and recreating, check also for // CREATE ROUTINE privilege to avoid lost procedures. - if ((Util::currentUserHasPrivilege('CREATE ROUTINE', $db) - && $curr_user == $routine_definer) - || $this->dbi->isSuperuser() - ) { - $retval .= ' ' . $titles['Edit'] . "\n"; - } else { - $retval .= ' ' . $titles['NoEdit'] . "\n"; - } - $retval .= " \n"; - $retval .= " \n"; + $hasEditPrivilege = (Util::currentUserHasPrivilege('CREATE ROUTINE', $db) + && $currentUser == $routineDefiner) || $this->dbi->isSuperuser(); // There is a problem with Util::currentUserHasPrivilege(): // it does not detect all kinds of privileges, for example @@ -284,6 +253,9 @@ class RteList $routine['type'], $routine['name'] ); + $hasExecutePrivilege = Util::currentUserHasPrivilege('EXECUTE', $db); + $executeAction = ''; + if ($definition !== null) { $parser = new Parser($definition); @@ -294,80 +266,34 @@ class RteList $params = Routine::getParameters($stmt); - if (Util::currentUserHasPrivilege('EXECUTE', $db)) { - $execute_action = 'execute_routine'; + if ($hasExecutePrivilege) { + $executeAction = 'execute_routine'; for ($i = 0; $i < $params['num']; $i++) { if ($routine['type'] == 'PROCEDURE' && $params['dir'][$i] == 'OUT' ) { continue; } - $execute_action = 'execute_dialog'; + $executeAction = 'execute_dialog'; break; } - $queryPart = [ - $execute_action => 1, - 'item_name' => $routine['name'], - 'item_type' => $routine['type'], - ]; - $retval .= ' ' . $titles['Execute'] . "\n"; - } else { - $retval .= ' ' . $titles['NoExecute'] . "\n"; } } - $retval .= " \n"; - $retval .= " \n"; - if ((Util::currentUserHasPrivilege('CREATE ROUTINE', $db) - && $curr_user == $routine_definer) - || $this->dbi->isSuperuser() - ) { - $retval .= ' ' . $titles['Export'] . "\n"; - } else { - $retval .= ' ' . $titles['NoExport'] . "\n"; - } - $retval .= " \n"; - $retval .= " \n"; - $retval .= Generator::linkOrButton( - Url::getFromRoute( - '/sql', - [ - 'db' => $db, - 'table' => $table, - 'sql_query' => $sql_drop, - 'goto' => Url::getFromRoute('/database/routines', ['db' => $db]), - ] - ), - $titles['Drop'], - ['class' => 'ajax drop_anchor'] - ); - $retval .= " \n"; - $retval .= " \n"; - $retval .= ' ' . $routine['type'] . "\n"; - $retval .= " \n"; - $retval .= " \n"; - $retval .= ' ' - . htmlspecialchars($routine['returns']) . "\n"; - $retval .= " \n"; - $retval .= " \n"; + $hasExportPrivilege = (Util::currentUserHasPrivilege('CREATE ROUTINE', $db) + && $currentUser == $routineDefiner) || $this->dbi->isSuperuser(); - return $retval; + return $this->template->render('rte/routines/row', [ + 'db' => $db, + 'table' => $table, + 'sql_drop' => $sqlDrop, + 'routine' => $routine, + 'row_class' => $rowClass, + 'has_edit_privilege' => $hasEditPrivilege, + 'has_export_privilege' => $hasExportPrivilege, + 'has_execute_privilege' => $hasExecutePrivilege, + 'execute_action' => $executeAction, + ]); } /** diff --git a/templates/rte/routines/row.twig b/templates/rte/routines/row.twig new file mode 100644 index 0000000000..ce500897d6 --- /dev/null +++ b/templates/rte/routines/row.twig @@ -0,0 +1,82 @@ + + + + + + {{ sql_drop }} + {{ routine.name }} + + + {% if has_edit_privilege %} + + {{ get_icon('b_edit', 'Edit'|trans) }} + + {% else %} + {{ get_icon('bd_edit', 'Edit'|trans) }} + {% endif %} + + + {% if has_execute_privilege and execute_action is not empty %} + {% if execute_action == 'execute_routine' %} + + {{ get_icon('b_nextpage', 'Execute'|trans) }} + + {% else %} + + {{ get_icon('b_nextpage', 'Execute'|trans) }} + + {% endif %} + {% else %} + {{ get_icon('bd_nextpage', 'Execute'|trans) }} + {% endif %} + + + {% if has_export_privilege %} + + {{ get_icon('b_export', 'Export'|trans) }} + + {% else %} + {{ get_icon('bd_export', 'Export'|trans) }} + {% endif %} + + + {{ link_or_button( + url('/sql', { + 'db': db, + 'table': table, + 'sql_query': sql_drop, + 'goto': url('/database/routines', {'db': db}) + }), + get_icon('b_drop', 'Drop'|trans), + {'class': 'ajax drop_anchor'} + ) }} + + + {{ routine.type }} + + + {{ routine.returns }} + +