Merge pull request #13675 from mauriciofauth/functions
Refactor some function calls to static method calls
This commit is contained in:
commit
1e1c622466
@ -5,12 +5,13 @@
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\BrowseForeigners;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/browse_foreigners.lib.php';
|
||||
|
||||
/**
|
||||
* Sets globals from $_REQUEST
|
||||
@ -39,7 +40,7 @@ $header->setBodyId('body_browse_foreigners');
|
||||
*/
|
||||
|
||||
$foreigners = Relation::getForeigners($db, $table);
|
||||
$foreign_limit = PMA_getForeignLimit(
|
||||
$foreign_limit = BrowseForeigners::getForeignLimit(
|
||||
isset($_REQUEST['foreign_showAll']) ? $_REQUEST['foreign_showAll'] : null
|
||||
);
|
||||
|
||||
@ -53,7 +54,7 @@ $foreignData = Relation::getForeignData(
|
||||
);
|
||||
|
||||
// HTML output
|
||||
$html = PMA_getHtmlForRelationalFieldSelection(
|
||||
$html = BrowseForeigners::getHtmlForRelationalFieldSelection(
|
||||
$db, $table, $_REQUEST['field'], $foreignData,
|
||||
isset($fieldkey) ? $fieldkey : null,
|
||||
isset($data) ? $data : null
|
||||
|
||||
@ -28,7 +28,7 @@ require_once 'libraries/common.inc.php';
|
||||
/**
|
||||
* functions implementation for this script
|
||||
*/
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
// add a javascript file for jQuery functions to handle Ajax actions
|
||||
$response = Response::getInstance();
|
||||
|
||||
@ -14,7 +14,7 @@ require_once 'libraries/common.inc.php';
|
||||
/**
|
||||
* Include all other files
|
||||
*/
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* Do the magic
|
||||
|
||||
@ -192,7 +192,7 @@ if ($server > 0 || count($cfg['Servers']) > 1
|
||||
* Displays the mysql server related links
|
||||
*/
|
||||
if ($server > 0) {
|
||||
include_once 'libraries/check_user_privileges.lib.php';
|
||||
include_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
// Logout for advanced authentication
|
||||
if ($cfg['Server']['auth_type'] != 'config') {
|
||||
|
||||
@ -1,341 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Contains functions used by browse_foreigners.php
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
/**
|
||||
* Function to get html for one relational key
|
||||
*
|
||||
* @param integer $horizontal_count the current horizontal count
|
||||
* @param string $header table header
|
||||
* @param array $keys all the keys
|
||||
* @param integer $indexByKeyname index by keyname
|
||||
* @param array $descriptions descriptions
|
||||
* @param integer $indexByDescription index by description
|
||||
* @param string $current_value current value on the edit form
|
||||
*
|
||||
* @return string $html the generated html
|
||||
*/
|
||||
function PMA_getHtmlForOneKey($horizontal_count, $header, $keys,
|
||||
$indexByKeyname, $descriptions, $indexByDescription, $current_value
|
||||
) {
|
||||
$horizontal_count++;
|
||||
$output = '';
|
||||
|
||||
// whether the key name corresponds to the selected value in the form
|
||||
$rightKeynameIsSelected = false;
|
||||
$leftKeynameIsSelected = false;
|
||||
|
||||
if ($GLOBALS['cfg']['RepeatCells'] > 0
|
||||
&& $horizontal_count > $GLOBALS['cfg']['RepeatCells']
|
||||
) {
|
||||
$output .= $header;
|
||||
$horizontal_count = 0;
|
||||
}
|
||||
|
||||
// key names and descriptions for the left section,
|
||||
// sorted by key names
|
||||
$leftKeyname = $keys[$indexByKeyname];
|
||||
list(
|
||||
$leftDescription,
|
||||
$leftDescriptionTitle
|
||||
) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
|
||||
|
||||
// key names and descriptions for the right section,
|
||||
// sorted by descriptions
|
||||
$rightKeyname = $keys[$indexByDescription];
|
||||
list(
|
||||
$rightDescription,
|
||||
$rightDescriptionTitle
|
||||
) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
|
||||
|
||||
$indexByDescription++;
|
||||
|
||||
if (! empty($current_value)) {
|
||||
$rightKeynameIsSelected = $rightKeyname == $current_value;
|
||||
$leftKeynameIsSelected = $leftKeyname == $current_value;
|
||||
}
|
||||
|
||||
$output .= '<tr class="noclick">';
|
||||
|
||||
$output .= PMA_getHtmlForColumnElement(
|
||||
'class="nowrap"', $leftKeynameIsSelected,
|
||||
$leftKeyname, $leftDescription,
|
||||
$leftDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= PMA_getHtmlForColumnElement(
|
||||
'', $leftKeynameIsSelected, $leftKeyname,
|
||||
$leftDescription, $leftDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= '<td width="20%">'
|
||||
. '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
|
||||
. ' width="1" height="1" /></td>';
|
||||
|
||||
$output .= PMA_getHtmlForColumnElement(
|
||||
'', $rightKeynameIsSelected, $rightKeyname,
|
||||
$rightDescription, $rightDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= PMA_getHtmlForColumnElement(
|
||||
'class="nowrap"', $rightKeynameIsSelected,
|
||||
$rightKeyname, $rightDescription,
|
||||
$rightDescriptionTitle
|
||||
);
|
||||
$output .= '</tr>';
|
||||
|
||||
return array($output, $horizontal_count, $indexByDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for relational field selection
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $field field
|
||||
* @param array $foreignData foreign column data
|
||||
* @param string $fieldkey field key
|
||||
* @param string $current_value current columns's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
|
||||
$fieldkey, $current_value
|
||||
) {
|
||||
$gotopage = PMA_getHtmlForGotoPage($foreignData);
|
||||
$showall = PMA_getHtmlForShowAll($foreignData);
|
||||
|
||||
$output = '<form class="ajax" '
|
||||
. 'id="browse_foreign_form" name="browse_foreign_from" '
|
||||
. 'action="browse_foreigners.php" method="post">'
|
||||
. '<fieldset>'
|
||||
. Url::getHiddenInputs($db, $table)
|
||||
. '<input type="hidden" name="field" value="' . htmlspecialchars($field)
|
||||
. '" />'
|
||||
. '<input type="hidden" name="fieldkey" value="'
|
||||
. (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
|
||||
|
||||
if (isset($_REQUEST['rownumber'])) {
|
||||
$output .= '<input type="hidden" name="rownumber" value="'
|
||||
. htmlspecialchars($_REQUEST['rownumber']) . '" />';
|
||||
}
|
||||
$filter_value = (isset($_REQUEST['foreign_filter'])
|
||||
? htmlspecialchars($_REQUEST['foreign_filter'])
|
||||
: '');
|
||||
$output .= '<span class="formelement">'
|
||||
. '<label for="input_foreign_filter">' . __('Search:') . '</label>'
|
||||
. '<input type="text" name="foreign_filter" '
|
||||
. 'id="input_foreign_filter" '
|
||||
. 'value="' . $filter_value . '" data-old="' . $filter_value . '" '
|
||||
. '/>'
|
||||
. '<input type="submit" name="submit_foreign_filter" value="'
|
||||
. __('Go') . '" />'
|
||||
. '</span>'
|
||||
. '<span class="formelement">' . $gotopage . '</span>'
|
||||
. '<span class="formelement">' . $showall . '</span>'
|
||||
. '</fieldset>'
|
||||
. '</form>';
|
||||
|
||||
$output .= '<table width="100%" id="browse_foreign_table">';
|
||||
|
||||
if (!is_array($foreignData['disp_row'])) {
|
||||
$output .= '</tbody>'
|
||||
. '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
$header = '<tr>
|
||||
<th>' . __('Keyname') . '</th>
|
||||
<th>' . __('Description') . '</th>
|
||||
<td width="20%"></td>
|
||||
<th>' . __('Description') . '</th>
|
||||
<th>' . __('Keyname') . '</th>
|
||||
</tr>';
|
||||
|
||||
$output .= '<thead>' . $header . '</thead>' . "\n"
|
||||
. '<tfoot>' . $header . '</tfoot>' . "\n"
|
||||
. '<tbody>' . "\n";
|
||||
|
||||
$descriptions = array();
|
||||
$keys = array();
|
||||
foreach ($foreignData['disp_row'] as $relrow) {
|
||||
if ($foreignData['foreign_display'] != false) {
|
||||
$descriptions[] = $relrow[$foreignData['foreign_display']];
|
||||
} else {
|
||||
$descriptions[] = '';
|
||||
}
|
||||
|
||||
$keys[] = $relrow[$foreignData['foreign_field']];
|
||||
}
|
||||
|
||||
asort($keys);
|
||||
|
||||
$horizontal_count = 0;
|
||||
$indexByDescription = 0;
|
||||
|
||||
foreach ($keys as $indexByKeyname => $value) {
|
||||
list(
|
||||
$html,
|
||||
$horizontal_count,
|
||||
$indexByDescription
|
||||
) = PMA_getHtmlForOneKey(
|
||||
$horizontal_count, $header, $keys, $indexByKeyname,
|
||||
$descriptions, $indexByDescription, $current_value
|
||||
);
|
||||
$output .= $html;
|
||||
}
|
||||
|
||||
$output .= '</tbody>'
|
||||
. '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description (possibly truncated) and the title
|
||||
*
|
||||
* @param string $description the key name's description
|
||||
*
|
||||
* @return array the new description and title
|
||||
*/
|
||||
function PMA_getDescriptionAndTitle($description)
|
||||
{
|
||||
$limitChars = $GLOBALS['cfg']['LimitChars'];
|
||||
if (mb_strlen($description) <= $limitChars) {
|
||||
$description = htmlspecialchars(
|
||||
$description
|
||||
);
|
||||
$descriptionTitle = '';
|
||||
} else {
|
||||
$descriptionTitle = htmlspecialchars(
|
||||
$description
|
||||
);
|
||||
$description = htmlspecialchars(
|
||||
mb_substr(
|
||||
$description, 0, $limitChars
|
||||
)
|
||||
. '...'
|
||||
);
|
||||
}
|
||||
return array($description, $descriptionTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for each column element
|
||||
*
|
||||
* @param string $cssClass class="nowrap" or ''
|
||||
* @param bool $isSelected whether current equals form's value
|
||||
* @param string $keyname current key
|
||||
* @param string $description current value
|
||||
* @param string $title current title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForColumnElement($cssClass, $isSelected, $keyname,
|
||||
$description, $title
|
||||
) {
|
||||
$keyname = htmlspecialchars($keyname);
|
||||
$output = '<td';
|
||||
if (! empty($cssClass)) {
|
||||
$output .= ' ' . $cssClass;
|
||||
}
|
||||
$output .= '>'
|
||||
. ($isSelected ? '<strong>' : '')
|
||||
. '<a class="foreign_value" data-key="' . $keyname . '" '
|
||||
. 'href="#" title="' . __('Use this value')
|
||||
. ($title != ''
|
||||
? ': ' . $title
|
||||
: '')
|
||||
. '">';
|
||||
if ($cssClass !== '') {
|
||||
$output .= $keyname;
|
||||
} else {
|
||||
$output .= $description;
|
||||
}
|
||||
|
||||
$output .= '</a>' . ($isSelected ? '</strong>' : '') . '</td>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for show all case
|
||||
*
|
||||
* @param array $foreignData foreign data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForShowAll($foreignData)
|
||||
{
|
||||
$showall = '';
|
||||
if (is_array($foreignData['disp_row'])) {
|
||||
if ($GLOBALS['cfg']['ShowAll']
|
||||
&& ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
|
||||
) {
|
||||
$showall = '<input type="submit" id="foreign_showAll" '
|
||||
. 'name="foreign_showAll" '
|
||||
. 'value="' . __('Show all') . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
return $showall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for the goto page option
|
||||
*
|
||||
* @param array $foreignData foreign data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForGotoPage($foreignData)
|
||||
{
|
||||
$gotopage = '';
|
||||
isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
|
||||
if (!is_array($foreignData['disp_row'])) {
|
||||
return $gotopage;
|
||||
}
|
||||
|
||||
$session_max_rows = $GLOBALS['cfg']['MaxRows'];
|
||||
$pageNow = @floor($pos / $session_max_rows) + 1;
|
||||
$nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
|
||||
|
||||
if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
|
||||
$gotopage = PhpMyAdmin\Util::pageselector(
|
||||
'pos',
|
||||
$session_max_rows,
|
||||
$pageNow,
|
||||
$nbTotalPage,
|
||||
200,
|
||||
5,
|
||||
5,
|
||||
20,
|
||||
10,
|
||||
__('Page number:')
|
||||
);
|
||||
}
|
||||
|
||||
return $gotopage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get foreign limit
|
||||
*
|
||||
* @param string $foreign_showAll foreign navigation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getForeignLimit($foreign_showAll)
|
||||
{
|
||||
if (isset($foreign_showAll) && $foreign_showAll == __('Show all')) {
|
||||
return null;
|
||||
}
|
||||
isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
|
||||
return 'LIMIT ' . $pos . ', ' . intval($GLOBALS['cfg']['MaxRows']) . ' ';
|
||||
}
|
||||
29
libraries/check_user_privileges.inc.php
Normal file
29
libraries/check_user_privileges.inc.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Get user's global privileges and some db-specific privileges
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
|
||||
$GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser();
|
||||
|
||||
list($username, $hostname) = $GLOBALS['dbi']->getCurrentUserAndHost();
|
||||
if ($username === '') { // MySQL is started with --skip-grant-tables
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = array('*');
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
} else {
|
||||
CheckUserPrivileges::analyseShowGrant();
|
||||
}
|
||||
@ -1,322 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Get user's global privileges and some db-specific privileges
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
$GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser();
|
||||
|
||||
/**
|
||||
* Extracts details from a result row of a SHOW GRANT query
|
||||
*
|
||||
* @param string $row grant row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function PMA_getItemsFromShowGrantsRow($row)
|
||||
{
|
||||
$db_name_offset = mb_strpos($row, ' ON ') + 4;
|
||||
$show_grants_dbname = mb_substr(
|
||||
$row, $db_name_offset,
|
||||
mb_strpos($row, '.', $db_name_offset) - $db_name_offset
|
||||
);
|
||||
|
||||
$show_grants_dbname = PhpMyAdmin\Util::unQuote($show_grants_dbname, '`');
|
||||
|
||||
$show_grants_str = mb_substr(
|
||||
$row,
|
||||
6,
|
||||
(mb_strpos($row, ' ON ') - 6)
|
||||
);
|
||||
|
||||
// extrac table from GRANT sytax
|
||||
$tblname_start_offset = mb_strpos($row, '.') + 1;
|
||||
$tblname_end_offset = mb_strpos($row, ' TO ');
|
||||
|
||||
$show_grants_tblname = mb_substr(
|
||||
$row, $tblname_start_offset,
|
||||
$tblname_end_offset - $tblname_start_offset
|
||||
);
|
||||
$show_grants_tblname = PhpMyAdmin\Util::unQuote($show_grants_tblname, '`');
|
||||
|
||||
return array(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has required privileges for
|
||||
* performing 'Adjust privileges' operations
|
||||
*
|
||||
* @param string $show_grants_str string containing grants for user
|
||||
* @param string $show_grants_dbname name of db extracted from grant string
|
||||
* @param string $show_grants_tblname name of table extracted from grant string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) {
|
||||
// '... ALL PRIVILEGES ON *.* ...' OR '... ALL PRIVILEGES ON `mysql`.* ..'
|
||||
// OR
|
||||
// SELECT, INSERT, UPDATE, DELETE .... ON *.* OR `mysql`.*
|
||||
if ($show_grants_str == 'ALL'
|
||||
|| $show_grants_str == 'ALL PRIVILEGES'
|
||||
|| (mb_strpos(
|
||||
$show_grants_str, 'SELECT, INSERT, UPDATE, DELETE'
|
||||
) !== false)
|
||||
) {
|
||||
if ($show_grants_dbname == '*'
|
||||
&& $show_grants_tblname == '*'
|
||||
) {
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
|
||||
if ($show_grants_str == 'ALL PRIVILEGES'
|
||||
|| $show_grants_str == 'ALL'
|
||||
) {
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check for specific tables in `mysql` db
|
||||
// Ex. '... ALL PRIVILEGES on `mysql`.`columns_priv` .. '
|
||||
if ($show_grants_dbname == 'mysql') {
|
||||
switch ($show_grants_tblname) {
|
||||
case "columns_priv":
|
||||
$GLOBALS['col_priv'] = true;
|
||||
break;
|
||||
case "db":
|
||||
$GLOBALS['db_priv'] = true;
|
||||
break;
|
||||
case "procs_priv":
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
break;
|
||||
case "tables_priv":
|
||||
$GLOBALS['table_priv'] = true;
|
||||
break;
|
||||
case "*":
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets privilege information extracted from SHOW GRANTS result
|
||||
*
|
||||
* Detection for some CREATE privilege.
|
||||
*
|
||||
* Since MySQL 4.1.2, we can easily detect current user's grants using $userlink
|
||||
* (no control user needed) and we don't have to try any other method for
|
||||
* detection
|
||||
*
|
||||
* @todo fix to get really all privileges, not only explicitly defined for this user
|
||||
* from MySQL manual: (https://dev.mysql.com/doc/refman/5.0/en/show-grants.html)
|
||||
* SHOW GRANTS displays only the privileges granted explicitly to the named
|
||||
* account. Other privileges might be available to the account, but they are not
|
||||
* displayed. For example, if an anonymous account exists, the named account
|
||||
* might be able to use its privileges, but SHOW GRANTS will not display them.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_analyseShowGrant()
|
||||
{
|
||||
if (PhpMyAdmin\Util::cacheExists('is_create_db_priv')) {
|
||||
$GLOBALS['is_create_db_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'is_create_db_priv'
|
||||
);
|
||||
$GLOBALS['is_reload_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'is_reload_priv'
|
||||
);
|
||||
$GLOBALS['db_to_create'] = PhpMyAdmin\Util::cacheGet(
|
||||
'db_to_create'
|
||||
);
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = PhpMyAdmin\Util::cacheGet(
|
||||
'dbs_where_create_table_allowed'
|
||||
);
|
||||
$GLOBALS['dbs_to_test'] = PhpMyAdmin\Util::cacheGet(
|
||||
'dbs_to_test'
|
||||
);
|
||||
|
||||
$GLOBALS['db_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'db_priv'
|
||||
);
|
||||
$GLOBALS['col_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'col_priv'
|
||||
);
|
||||
$GLOBALS['table_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'table_priv'
|
||||
);
|
||||
$GLOBALS['proc_priv'] = PhpMyAdmin\Util::cacheGet(
|
||||
'proc_priv'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// defaults
|
||||
$GLOBALS['is_create_db_priv'] = false;
|
||||
$GLOBALS['is_reload_priv'] = false;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = array();
|
||||
$GLOBALS['dbs_to_test'] = $GLOBALS['dbi']->getSystemSchemas();
|
||||
$GLOBALS['proc_priv'] = false;
|
||||
$GLOBALS['db_priv'] = false;
|
||||
$GLOBALS['col_priv'] = false;
|
||||
$GLOBALS['table_priv'] = false;
|
||||
|
||||
$rs_usr = $GLOBALS['dbi']->tryQuery('SHOW GRANTS');
|
||||
|
||||
if (! $rs_usr) {
|
||||
return;
|
||||
}
|
||||
|
||||
$re0 = '(^|(\\\\\\\\)+|[^\\\\])'; // non-escaped wildcards
|
||||
$re1 = '(^|[^\\\\])(\\\)+'; // escaped wildcards
|
||||
|
||||
while ($row = $GLOBALS['dbi']->fetchRow($rs_usr)) {
|
||||
list(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow($row[0]);
|
||||
|
||||
if ($show_grants_dbname == '*') {
|
||||
if ($show_grants_str != 'USAGE') {
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
}
|
||||
} elseif ($GLOBALS['dbs_to_test'] !== false) {
|
||||
$GLOBALS['dbs_to_test'][] = $show_grants_dbname;
|
||||
}
|
||||
|
||||
if (
|
||||
mb_strpos($show_grants_str,'RELOAD') !== false
|
||||
) {
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
}
|
||||
|
||||
// check for the required privileges for adjust
|
||||
PMA_checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
);
|
||||
|
||||
/**
|
||||
* @todo if we find CREATE VIEW but not CREATE, do not offer
|
||||
* the create database dialog box
|
||||
*/
|
||||
if ($show_grants_str == 'ALL'
|
||||
|| $show_grants_str == 'ALL PRIVILEGES'
|
||||
|| $show_grants_str == 'CREATE'
|
||||
|| strpos($show_grants_str, 'CREATE,') !== false
|
||||
) {
|
||||
if ($show_grants_dbname == '*') {
|
||||
// a global CREATE privilege
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'][] = '*';
|
||||
// @todo we should not break here, cause GRANT ALL *.*
|
||||
// could be revoked by a later rule like GRANT SELECT ON db.*
|
||||
break;
|
||||
} else {
|
||||
// this array may contain wildcards
|
||||
$GLOBALS['dbs_where_create_table_allowed'][] = $show_grants_dbname;
|
||||
|
||||
$dbname_to_test = PhpMyAdmin\Util::backquote($show_grants_dbname);
|
||||
|
||||
if ($GLOBALS['is_create_db_priv']) {
|
||||
// no need for any more tests if we already know this
|
||||
continue;
|
||||
}
|
||||
|
||||
// does this db exist?
|
||||
if ((preg_match('/' . $re0 . '%|_/', $show_grants_dbname)
|
||||
&& ! preg_match('/\\\\%|\\\\_/', $show_grants_dbname))
|
||||
|| (! $GLOBALS['dbi']->tryQuery(
|
||||
'USE ' . preg_replace(
|
||||
'/' . $re1 . '(%|_)/', '\\1\\3', $dbname_to_test
|
||||
)
|
||||
)
|
||||
&& mb_substr($GLOBALS['dbi']->getError(), 1, 4) != 1044)
|
||||
) {
|
||||
/**
|
||||
* Do not handle the underscore wildcard
|
||||
* (this case must be rare anyway)
|
||||
*/
|
||||
$GLOBALS['db_to_create'] = preg_replace(
|
||||
'/' . $re0 . '%/', '\\1',
|
||||
$show_grants_dbname
|
||||
);
|
||||
$GLOBALS['db_to_create'] = preg_replace(
|
||||
'/' . $re1 . '(%|_)/', '\\1\\3',
|
||||
$GLOBALS['db_to_create']
|
||||
);
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
|
||||
/**
|
||||
* @todo collect $GLOBALS['db_to_create'] into an array,
|
||||
* to display a drop-down in the "Create database" dialog
|
||||
*/
|
||||
// we don't break, we want all possible databases
|
||||
//break;
|
||||
} // end if
|
||||
} // end elseif
|
||||
} // end if
|
||||
|
||||
} // end while
|
||||
|
||||
$GLOBALS['dbi']->freeResult($rs_usr);
|
||||
|
||||
// must also cacheUnset() them in
|
||||
// PhpMyAdmin\Plugins\Auth\AuthenticationCookie
|
||||
PhpMyAdmin\Util::cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv']);
|
||||
PhpMyAdmin\Util::cacheSet('is_reload_priv', $GLOBALS['is_reload_priv']);
|
||||
PhpMyAdmin\Util::cacheSet('db_to_create', $GLOBALS['db_to_create']);
|
||||
PhpMyAdmin\Util::cacheSet(
|
||||
'dbs_where_create_table_allowed',
|
||||
$GLOBALS['dbs_where_create_table_allowed']
|
||||
);
|
||||
PhpMyAdmin\Util::cacheSet('dbs_to_test', $GLOBALS['dbs_to_test']);
|
||||
|
||||
PhpMyAdmin\Util::cacheSet('proc_priv', $GLOBALS['proc_priv']);
|
||||
PhpMyAdmin\Util::cacheSet('table_priv', $GLOBALS['table_priv']);
|
||||
PhpMyAdmin\Util::cacheSet('col_priv', $GLOBALS['col_priv']);
|
||||
PhpMyAdmin\Util::cacheSet('db_priv', $GLOBALS['db_priv']);
|
||||
} // end function
|
||||
|
||||
list($username, $hostname) = $GLOBALS['dbi']->getCurrentUserAndHost();
|
||||
if ($username === '') { // MySQL is started with --skip-grant-tables
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = array('*');
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
} else {
|
||||
PMA_analyseShowGrant();
|
||||
}
|
||||
352
libraries/classes/BrowseForeigners.php
Normal file
352
libraries/classes/BrowseForeigners.php
Normal file
@ -0,0 +1,352 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Contains functions used by browse_foreigners.php
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\BrowseForeigners class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class BrowseForeigners
|
||||
{
|
||||
/**
|
||||
* Function to get html for one relational key
|
||||
*
|
||||
* @param integer $horizontal_count the current horizontal count
|
||||
* @param string $header table header
|
||||
* @param array $keys all the keys
|
||||
* @param integer $indexByKeyname index by keyname
|
||||
* @param array $descriptions descriptions
|
||||
* @param integer $indexByDescription index by description
|
||||
* @param string $current_value current value on the edit form
|
||||
*
|
||||
* @return string $html the generated html
|
||||
*/
|
||||
public static function getHtmlForOneKey($horizontal_count, $header, $keys,
|
||||
$indexByKeyname, $descriptions, $indexByDescription, $current_value
|
||||
) {
|
||||
$horizontal_count++;
|
||||
$output = '';
|
||||
|
||||
// whether the key name corresponds to the selected value in the form
|
||||
$rightKeynameIsSelected = false;
|
||||
$leftKeynameIsSelected = false;
|
||||
|
||||
if ($GLOBALS['cfg']['RepeatCells'] > 0
|
||||
&& $horizontal_count > $GLOBALS['cfg']['RepeatCells']
|
||||
) {
|
||||
$output .= $header;
|
||||
$horizontal_count = 0;
|
||||
}
|
||||
|
||||
// key names and descriptions for the left section,
|
||||
// sorted by key names
|
||||
$leftKeyname = $keys[$indexByKeyname];
|
||||
list(
|
||||
$leftDescription,
|
||||
$leftDescriptionTitle
|
||||
) = self::getDescriptionAndTitle($descriptions[$indexByKeyname]);
|
||||
|
||||
// key names and descriptions for the right section,
|
||||
// sorted by descriptions
|
||||
$rightKeyname = $keys[$indexByDescription];
|
||||
list(
|
||||
$rightDescription,
|
||||
$rightDescriptionTitle
|
||||
) = self::getDescriptionAndTitle($descriptions[$indexByDescription]);
|
||||
|
||||
$indexByDescription++;
|
||||
|
||||
if (! empty($current_value)) {
|
||||
$rightKeynameIsSelected = $rightKeyname == $current_value;
|
||||
$leftKeynameIsSelected = $leftKeyname == $current_value;
|
||||
}
|
||||
|
||||
$output .= '<tr class="noclick">';
|
||||
|
||||
$output .= self::getHtmlForColumnElement(
|
||||
'class="nowrap"', $leftKeynameIsSelected,
|
||||
$leftKeyname, $leftDescription,
|
||||
$leftDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= self::getHtmlForColumnElement(
|
||||
'', $leftKeynameIsSelected, $leftKeyname,
|
||||
$leftDescription, $leftDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= '<td width="20%">'
|
||||
. '<img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png" alt=""'
|
||||
. ' width="1" height="1" /></td>';
|
||||
|
||||
$output .= self::getHtmlForColumnElement(
|
||||
'', $rightKeynameIsSelected, $rightKeyname,
|
||||
$rightDescription, $rightDescriptionTitle
|
||||
);
|
||||
|
||||
$output .= self::getHtmlForColumnElement(
|
||||
'class="nowrap"', $rightKeynameIsSelected,
|
||||
$rightKeyname, $rightDescription,
|
||||
$rightDescriptionTitle
|
||||
);
|
||||
$output .= '</tr>';
|
||||
|
||||
return array($output, $horizontal_count, $indexByDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for relational field selection
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $field field
|
||||
* @param array $foreignData foreign column data
|
||||
* @param string $fieldkey field key
|
||||
* @param string $current_value current columns's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
|
||||
$fieldkey, $current_value
|
||||
) {
|
||||
$gotopage = self::getHtmlForGotoPage($foreignData);
|
||||
$showall = self::getHtmlForShowAll($foreignData);
|
||||
|
||||
$output = '<form class="ajax" '
|
||||
. 'id="browse_foreign_form" name="browse_foreign_from" '
|
||||
. 'action="browse_foreigners.php" method="post">'
|
||||
. '<fieldset>'
|
||||
. Url::getHiddenInputs($db, $table)
|
||||
. '<input type="hidden" name="field" value="' . htmlspecialchars($field)
|
||||
. '" />'
|
||||
. '<input type="hidden" name="fieldkey" value="'
|
||||
. (isset($fieldkey) ? htmlspecialchars($fieldkey) : '') . '" />';
|
||||
|
||||
if (isset($_REQUEST['rownumber'])) {
|
||||
$output .= '<input type="hidden" name="rownumber" value="'
|
||||
. htmlspecialchars($_REQUEST['rownumber']) . '" />';
|
||||
}
|
||||
$filter_value = (isset($_REQUEST['foreign_filter'])
|
||||
? htmlspecialchars($_REQUEST['foreign_filter'])
|
||||
: '');
|
||||
$output .= '<span class="formelement">'
|
||||
. '<label for="input_foreign_filter">' . __('Search:') . '</label>'
|
||||
. '<input type="text" name="foreign_filter" '
|
||||
. 'id="input_foreign_filter" '
|
||||
. 'value="' . $filter_value . '" data-old="' . $filter_value . '" '
|
||||
. '/>'
|
||||
. '<input type="submit" name="submit_foreign_filter" value="'
|
||||
. __('Go') . '" />'
|
||||
. '</span>'
|
||||
. '<span class="formelement">' . $gotopage . '</span>'
|
||||
. '<span class="formelement">' . $showall . '</span>'
|
||||
. '</fieldset>'
|
||||
. '</form>';
|
||||
|
||||
$output .= '<table width="100%" id="browse_foreign_table">';
|
||||
|
||||
if (!is_array($foreignData['disp_row'])) {
|
||||
$output .= '</tbody>'
|
||||
. '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
$header = '<tr>
|
||||
<th>' . __('Keyname') . '</th>
|
||||
<th>' . __('Description') . '</th>
|
||||
<td width="20%"></td>
|
||||
<th>' . __('Description') . '</th>
|
||||
<th>' . __('Keyname') . '</th>
|
||||
</tr>';
|
||||
|
||||
$output .= '<thead>' . $header . '</thead>' . "\n"
|
||||
. '<tfoot>' . $header . '</tfoot>' . "\n"
|
||||
. '<tbody>' . "\n";
|
||||
|
||||
$descriptions = array();
|
||||
$keys = array();
|
||||
foreach ($foreignData['disp_row'] as $relrow) {
|
||||
if ($foreignData['foreign_display'] != false) {
|
||||
$descriptions[] = $relrow[$foreignData['foreign_display']];
|
||||
} else {
|
||||
$descriptions[] = '';
|
||||
}
|
||||
|
||||
$keys[] = $relrow[$foreignData['foreign_field']];
|
||||
}
|
||||
|
||||
asort($keys);
|
||||
|
||||
$horizontal_count = 0;
|
||||
$indexByDescription = 0;
|
||||
|
||||
foreach ($keys as $indexByKeyname => $value) {
|
||||
list(
|
||||
$html,
|
||||
$horizontal_count,
|
||||
$indexByDescription
|
||||
) = self::getHtmlForOneKey(
|
||||
$horizontal_count, $header, $keys, $indexByKeyname,
|
||||
$descriptions, $indexByDescription, $current_value
|
||||
);
|
||||
$output .= $html;
|
||||
}
|
||||
|
||||
$output .= '</tbody>'
|
||||
. '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description (possibly truncated) and the title
|
||||
*
|
||||
* @param string $description the key name's description
|
||||
*
|
||||
* @return array the new description and title
|
||||
*/
|
||||
public static function getDescriptionAndTitle($description)
|
||||
{
|
||||
$limitChars = $GLOBALS['cfg']['LimitChars'];
|
||||
if (mb_strlen($description) <= $limitChars) {
|
||||
$description = htmlspecialchars(
|
||||
$description
|
||||
);
|
||||
$descriptionTitle = '';
|
||||
} else {
|
||||
$descriptionTitle = htmlspecialchars(
|
||||
$description
|
||||
);
|
||||
$description = htmlspecialchars(
|
||||
mb_substr(
|
||||
$description, 0, $limitChars
|
||||
)
|
||||
. '...'
|
||||
);
|
||||
}
|
||||
return array($description, $descriptionTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for each column element
|
||||
*
|
||||
* @param string $cssClass class="nowrap" or ''
|
||||
* @param bool $isSelected whether current equals form's value
|
||||
* @param string $keyname current key
|
||||
* @param string $description current value
|
||||
* @param string $title current title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForColumnElement($cssClass, $isSelected, $keyname,
|
||||
$description, $title
|
||||
) {
|
||||
$keyname = htmlspecialchars($keyname);
|
||||
$output = '<td';
|
||||
if (! empty($cssClass)) {
|
||||
$output .= ' ' . $cssClass;
|
||||
}
|
||||
$output .= '>'
|
||||
. ($isSelected ? '<strong>' : '')
|
||||
. '<a class="foreign_value" data-key="' . $keyname . '" '
|
||||
. 'href="#" title="' . __('Use this value')
|
||||
. ($title != ''
|
||||
? ': ' . $title
|
||||
: '')
|
||||
. '">';
|
||||
if ($cssClass !== '') {
|
||||
$output .= $keyname;
|
||||
} else {
|
||||
$output .= $description;
|
||||
}
|
||||
|
||||
$output .= '</a>' . ($isSelected ? '</strong>' : '') . '</td>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for show all case
|
||||
*
|
||||
* @param array $foreignData foreign data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForShowAll($foreignData)
|
||||
{
|
||||
$showall = '';
|
||||
if (is_array($foreignData['disp_row'])) {
|
||||
if ($GLOBALS['cfg']['ShowAll']
|
||||
&& ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows'])
|
||||
) {
|
||||
$showall = '<input type="submit" id="foreign_showAll" '
|
||||
. 'name="foreign_showAll" '
|
||||
. 'value="' . __('Show all') . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
return $showall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get html for the goto page option
|
||||
*
|
||||
* @param array $foreignData foreign data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHtmlForGotoPage($foreignData)
|
||||
{
|
||||
$gotopage = '';
|
||||
isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
|
||||
if (!is_array($foreignData['disp_row'])) {
|
||||
return $gotopage;
|
||||
}
|
||||
|
||||
$session_max_rows = $GLOBALS['cfg']['MaxRows'];
|
||||
$pageNow = @floor($pos / $session_max_rows) + 1;
|
||||
$nbTotalPage = @ceil($foreignData['the_total'] / $session_max_rows);
|
||||
|
||||
if ($foreignData['the_total'] > $GLOBALS['cfg']['MaxRows']) {
|
||||
$gotopage = Util::pageselector(
|
||||
'pos',
|
||||
$session_max_rows,
|
||||
$pageNow,
|
||||
$nbTotalPage,
|
||||
200,
|
||||
5,
|
||||
5,
|
||||
20,
|
||||
10,
|
||||
__('Page number:')
|
||||
);
|
||||
}
|
||||
|
||||
return $gotopage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get foreign limit
|
||||
*
|
||||
* @param string $foreign_showAll foreign navigation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getForeignLimit($foreign_showAll)
|
||||
{
|
||||
if (isset($foreign_showAll) && $foreign_showAll == __('Show all')) {
|
||||
return null;
|
||||
}
|
||||
isset($_REQUEST['pos']) ? $pos = $_REQUEST['pos'] : $pos = 0;
|
||||
return 'LIMIT ' . $pos . ', ' . intval($GLOBALS['cfg']['MaxRows']) . ' ';
|
||||
}
|
||||
}
|
||||
310
libraries/classes/CheckUserPrivileges.php
Normal file
310
libraries/classes/CheckUserPrivileges.php
Normal file
@ -0,0 +1,310 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Get user's global privileges and some db-specific privileges
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\CheckUserPrivileges class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class CheckUserPrivileges
|
||||
{
|
||||
/**
|
||||
* Extracts details from a result row of a SHOW GRANT query
|
||||
*
|
||||
* @param string $row grant row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getItemsFromShowGrantsRow($row)
|
||||
{
|
||||
$db_name_offset = mb_strpos($row, ' ON ') + 4;
|
||||
$show_grants_dbname = mb_substr(
|
||||
$row, $db_name_offset,
|
||||
mb_strpos($row, '.', $db_name_offset) - $db_name_offset
|
||||
);
|
||||
|
||||
$show_grants_dbname = Util::unQuote($show_grants_dbname, '`');
|
||||
|
||||
$show_grants_str = mb_substr(
|
||||
$row,
|
||||
6,
|
||||
(mb_strpos($row, ' ON ') - 6)
|
||||
);
|
||||
|
||||
// extrac table from GRANT sytax
|
||||
$tblname_start_offset = mb_strpos($row, '.') + 1;
|
||||
$tblname_end_offset = mb_strpos($row, ' TO ');
|
||||
|
||||
$show_grants_tblname = mb_substr(
|
||||
$row, $tblname_start_offset,
|
||||
$tblname_end_offset - $tblname_start_offset
|
||||
);
|
||||
$show_grants_tblname = Util::unQuote($show_grants_tblname, '`');
|
||||
|
||||
return array(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has required privileges for
|
||||
* performing 'Adjust privileges' operations
|
||||
*
|
||||
* @param string $show_grants_str string containing grants for user
|
||||
* @param string $show_grants_dbname name of db extracted from grant string
|
||||
* @param string $show_grants_tblname name of table extracted from grant string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) {
|
||||
// '... ALL PRIVILEGES ON *.* ...' OR '... ALL PRIVILEGES ON `mysql`.* ..'
|
||||
// OR
|
||||
// SELECT, INSERT, UPDATE, DELETE .... ON *.* OR `mysql`.*
|
||||
if ($show_grants_str == 'ALL'
|
||||
|| $show_grants_str == 'ALL PRIVILEGES'
|
||||
|| (mb_strpos(
|
||||
$show_grants_str, 'SELECT, INSERT, UPDATE, DELETE'
|
||||
) !== false)
|
||||
) {
|
||||
if ($show_grants_dbname == '*'
|
||||
&& $show_grants_tblname == '*'
|
||||
) {
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
|
||||
if ($show_grants_str == 'ALL PRIVILEGES'
|
||||
|| $show_grants_str == 'ALL'
|
||||
) {
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check for specific tables in `mysql` db
|
||||
// Ex. '... ALL PRIVILEGES on `mysql`.`columns_priv` .. '
|
||||
if ($show_grants_dbname == 'mysql') {
|
||||
switch ($show_grants_tblname) {
|
||||
case "columns_priv":
|
||||
$GLOBALS['col_priv'] = true;
|
||||
break;
|
||||
case "db":
|
||||
$GLOBALS['db_priv'] = true;
|
||||
break;
|
||||
case "procs_priv":
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
break;
|
||||
case "tables_priv":
|
||||
$GLOBALS['table_priv'] = true;
|
||||
break;
|
||||
case "*":
|
||||
$GLOBALS['col_priv'] = true;
|
||||
$GLOBALS['db_priv'] = true;
|
||||
$GLOBALS['proc_priv'] = true;
|
||||
$GLOBALS['table_priv'] = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets privilege information extracted from SHOW GRANTS result
|
||||
*
|
||||
* Detection for some CREATE privilege.
|
||||
*
|
||||
* Since MySQL 4.1.2, we can easily detect current user's grants using $userlink
|
||||
* (no control user needed) and we don't have to try any other method for
|
||||
* detection
|
||||
*
|
||||
* @todo fix to get really all privileges, not only explicitly defined for this user
|
||||
* from MySQL manual: (https://dev.mysql.com/doc/refman/5.0/en/show-grants.html)
|
||||
* SHOW GRANTS displays only the privileges granted explicitly to the named
|
||||
* account. Other privileges might be available to the account, but they are not
|
||||
* displayed. For example, if an anonymous account exists, the named account
|
||||
* might be able to use its privileges, but SHOW GRANTS will not display them.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function analyseShowGrant()
|
||||
{
|
||||
if (Util::cacheExists('is_create_db_priv')) {
|
||||
$GLOBALS['is_create_db_priv'] = Util::cacheGet(
|
||||
'is_create_db_priv'
|
||||
);
|
||||
$GLOBALS['is_reload_priv'] = Util::cacheGet(
|
||||
'is_reload_priv'
|
||||
);
|
||||
$GLOBALS['db_to_create'] = Util::cacheGet(
|
||||
'db_to_create'
|
||||
);
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = Util::cacheGet(
|
||||
'dbs_where_create_table_allowed'
|
||||
);
|
||||
$GLOBALS['dbs_to_test'] = Util::cacheGet(
|
||||
'dbs_to_test'
|
||||
);
|
||||
|
||||
$GLOBALS['db_priv'] = Util::cacheGet(
|
||||
'db_priv'
|
||||
);
|
||||
$GLOBALS['col_priv'] = Util::cacheGet(
|
||||
'col_priv'
|
||||
);
|
||||
$GLOBALS['table_priv'] = Util::cacheGet(
|
||||
'table_priv'
|
||||
);
|
||||
$GLOBALS['proc_priv'] = Util::cacheGet(
|
||||
'proc_priv'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// defaults
|
||||
$GLOBALS['is_create_db_priv'] = false;
|
||||
$GLOBALS['is_reload_priv'] = false;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'] = array();
|
||||
$GLOBALS['dbs_to_test'] = $GLOBALS['dbi']->getSystemSchemas();
|
||||
$GLOBALS['proc_priv'] = false;
|
||||
$GLOBALS['db_priv'] = false;
|
||||
$GLOBALS['col_priv'] = false;
|
||||
$GLOBALS['table_priv'] = false;
|
||||
|
||||
$rs_usr = $GLOBALS['dbi']->tryQuery('SHOW GRANTS');
|
||||
|
||||
if (! $rs_usr) {
|
||||
return;
|
||||
}
|
||||
|
||||
$re0 = '(^|(\\\\\\\\)+|[^\\\\])'; // non-escaped wildcards
|
||||
$re1 = '(^|[^\\\\])(\\\)+'; // escaped wildcards
|
||||
|
||||
while ($row = $GLOBALS['dbi']->fetchRow($rs_usr)) {
|
||||
list(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = self::getItemsFromShowGrantsRow($row[0]);
|
||||
|
||||
if ($show_grants_dbname == '*') {
|
||||
if ($show_grants_str != 'USAGE') {
|
||||
$GLOBALS['dbs_to_test'] = false;
|
||||
}
|
||||
} elseif ($GLOBALS['dbs_to_test'] !== false) {
|
||||
$GLOBALS['dbs_to_test'][] = $show_grants_dbname;
|
||||
}
|
||||
|
||||
if (
|
||||
mb_strpos($show_grants_str,'RELOAD') !== false
|
||||
) {
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
}
|
||||
|
||||
// check for the required privileges for adjust
|
||||
self::checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
);
|
||||
|
||||
/**
|
||||
* @todo if we find CREATE VIEW but not CREATE, do not offer
|
||||
* the create database dialog box
|
||||
*/
|
||||
if ($show_grants_str == 'ALL'
|
||||
|| $show_grants_str == 'ALL PRIVILEGES'
|
||||
|| $show_grants_str == 'CREATE'
|
||||
|| strpos($show_grants_str, 'CREATE,') !== false
|
||||
) {
|
||||
if ($show_grants_dbname == '*') {
|
||||
// a global CREATE privilege
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
$GLOBALS['is_reload_priv'] = true;
|
||||
$GLOBALS['db_to_create'] = '';
|
||||
$GLOBALS['dbs_where_create_table_allowed'][] = '*';
|
||||
// @todo we should not break here, cause GRANT ALL *.*
|
||||
// could be revoked by a later rule like GRANT SELECT ON db.*
|
||||
break;
|
||||
} else {
|
||||
// this array may contain wildcards
|
||||
$GLOBALS['dbs_where_create_table_allowed'][] = $show_grants_dbname;
|
||||
|
||||
$dbname_to_test = Util::backquote($show_grants_dbname);
|
||||
|
||||
if ($GLOBALS['is_create_db_priv']) {
|
||||
// no need for any more tests if we already know this
|
||||
continue;
|
||||
}
|
||||
|
||||
// does this db exist?
|
||||
if ((preg_match('/' . $re0 . '%|_/', $show_grants_dbname)
|
||||
&& ! preg_match('/\\\\%|\\\\_/', $show_grants_dbname))
|
||||
|| (! $GLOBALS['dbi']->tryQuery(
|
||||
'USE ' . preg_replace(
|
||||
'/' . $re1 . '(%|_)/', '\\1\\3', $dbname_to_test
|
||||
)
|
||||
)
|
||||
&& mb_substr($GLOBALS['dbi']->getError(), 1, 4) != 1044)
|
||||
) {
|
||||
/**
|
||||
* Do not handle the underscore wildcard
|
||||
* (this case must be rare anyway)
|
||||
*/
|
||||
$GLOBALS['db_to_create'] = preg_replace(
|
||||
'/' . $re0 . '%/', '\\1',
|
||||
$show_grants_dbname
|
||||
);
|
||||
$GLOBALS['db_to_create'] = preg_replace(
|
||||
'/' . $re1 . '(%|_)/', '\\1\\3',
|
||||
$GLOBALS['db_to_create']
|
||||
);
|
||||
$GLOBALS['is_create_db_priv'] = true;
|
||||
|
||||
/**
|
||||
* @todo collect $GLOBALS['db_to_create'] into an array,
|
||||
* to display a drop-down in the "Create database" dialog
|
||||
*/
|
||||
// we don't break, we want all possible databases
|
||||
//break;
|
||||
} // end if
|
||||
} // end elseif
|
||||
} // end if
|
||||
|
||||
} // end while
|
||||
|
||||
$GLOBALS['dbi']->freeResult($rs_usr);
|
||||
|
||||
// must also cacheUnset() them in
|
||||
// PhpMyAdmin\Plugins\Auth\AuthenticationCookie
|
||||
Util::cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv']);
|
||||
Util::cacheSet('is_reload_priv', $GLOBALS['is_reload_priv']);
|
||||
Util::cacheSet('db_to_create', $GLOBALS['db_to_create']);
|
||||
Util::cacheSet(
|
||||
'dbs_where_create_table_allowed',
|
||||
$GLOBALS['dbs_where_create_table_allowed']
|
||||
);
|
||||
Util::cacheSet('dbs_to_test', $GLOBALS['dbs_to_test']);
|
||||
|
||||
Util::cacheSet('proc_priv', $GLOBALS['proc_priv']);
|
||||
Util::cacheSet('table_priv', $GLOBALS['table_priv']);
|
||||
Util::cacheSet('col_priv', $GLOBALS['col_priv']);
|
||||
Util::cacheSet('db_priv', $GLOBALS['db_priv']);
|
||||
} // end function
|
||||
}
|
||||
@ -57,7 +57,7 @@ class ServerDatabasesController extends Controller
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
include_once 'libraries/check_user_privileges.lib.php';
|
||||
include_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ use PhpMyAdmin\CentralColumns;
|
||||
use PhpMyAdmin\Config\PageSettings;
|
||||
use PhpMyAdmin\Controllers\TableController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\CreateAddField;
|
||||
use PhpMyAdmin\Index;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Relation;
|
||||
@ -112,7 +113,7 @@ class TableStructureController extends TableController
|
||||
/**
|
||||
* Function implementations for this script
|
||||
*/
|
||||
include_once 'libraries/check_user_privileges.lib.php';
|
||||
include_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles(
|
||||
array(
|
||||
@ -512,7 +513,7 @@ class TableStructureController extends TableController
|
||||
/**
|
||||
* Form for changing properties.
|
||||
*/
|
||||
include_once 'libraries/check_user_privileges.lib.php';
|
||||
include_once 'libraries/check_user_privileges.inc.php';
|
||||
include 'libraries/tbl_columns_definition_form.inc.php';
|
||||
}
|
||||
|
||||
@ -710,10 +711,8 @@ class TableStructureController extends TableController
|
||||
*/
|
||||
protected function updatePartitioning()
|
||||
{
|
||||
include_once 'libraries/create_addfield.lib.php';
|
||||
|
||||
$sql_query = "ALTER TABLE " . Util::backquote($this->table) . " "
|
||||
. PMA_getPartitionsDefinition();
|
||||
. CreateAddField::getPartitionsDefinition();
|
||||
|
||||
// Execute alter query
|
||||
$result = $this->dbi->tryQuery($sql_query);
|
||||
|
||||
505
libraries/classes/CreateAddField.php
Normal file
505
libraries/classes/CreateAddField.php
Normal file
@ -0,0 +1,505 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* set of functions for tbl_create.php and tbl_addfield.php
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Index;
|
||||
use PhpMyAdmin\Table;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\CreateAddField class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class CreateAddField
|
||||
{
|
||||
/**
|
||||
* Transforms the radio button field_key into 4 arrays
|
||||
*
|
||||
* @return array An array of arrays which represents column keys for each index type
|
||||
*/
|
||||
public static function getIndexedColumns()
|
||||
{
|
||||
$field_cnt = count($_REQUEST['field_name']);
|
||||
$field_primary = json_decode($_REQUEST['primary_indexes'], true);
|
||||
$field_index = json_decode($_REQUEST['indexes'], true);
|
||||
$field_unique = json_decode($_REQUEST['unique_indexes'], true);
|
||||
$field_fulltext = json_decode($_REQUEST['fulltext_indexes'], true);
|
||||
$field_spatial = json_decode($_REQUEST['spatial_indexes'], true);
|
||||
|
||||
return array(
|
||||
$field_cnt, $field_primary, $field_index, $field_unique,
|
||||
$field_fulltext, $field_spatial
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate the column creation statement according to the table creation or
|
||||
* add columns to a existing table
|
||||
*
|
||||
* @param int $field_cnt number of columns
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return array $definitions An array of initial sql statements
|
||||
* according to the request
|
||||
*/
|
||||
public static function buildColumnCreationStatement(
|
||||
$field_cnt, $is_create_tbl = true
|
||||
) {
|
||||
$definitions = array();
|
||||
for ($i = 0; $i < $field_cnt; ++$i) {
|
||||
// '0' is also empty for php :-(
|
||||
if (empty($_REQUEST['field_name'][$i])
|
||||
&& $_REQUEST['field_name'][$i] != '0'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$definition = self::getStatementPrefix($is_create_tbl) .
|
||||
Table::generateFieldSpec(
|
||||
trim($_REQUEST['field_name'][$i]),
|
||||
$_REQUEST['field_type'][$i],
|
||||
$_REQUEST['field_length'][$i],
|
||||
$_REQUEST['field_attribute'][$i],
|
||||
isset($_REQUEST['field_collation'][$i])
|
||||
? $_REQUEST['field_collation'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_null'][$i])
|
||||
? $_REQUEST['field_null'][$i]
|
||||
: 'NOT NULL',
|
||||
$_REQUEST['field_default_type'][$i],
|
||||
$_REQUEST['field_default_value'][$i],
|
||||
isset($_REQUEST['field_extra'][$i])
|
||||
? $_REQUEST['field_extra'][$i]
|
||||
: false,
|
||||
isset($_REQUEST['field_comments'][$i])
|
||||
? $_REQUEST['field_comments'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_virtuality'][$i])
|
||||
? $_REQUEST['field_virtuality'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_expression'][$i])
|
||||
? $_REQUEST['field_expression'][$i]
|
||||
: ''
|
||||
);
|
||||
|
||||
$definition .= self::setColumnCreationStatementSuffix($i, $is_create_tbl);
|
||||
$definitions[] = $definition;
|
||||
} // end for
|
||||
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column creation suffix according to requested position of the new column
|
||||
*
|
||||
* @param int $current_field_num current column number
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string $sql_suffix suffix
|
||||
*/
|
||||
public static function setColumnCreationStatementSuffix($current_field_num,
|
||||
$is_create_tbl = true
|
||||
) {
|
||||
// no suffix is needed if request is a table creation
|
||||
$sql_suffix = ' ';
|
||||
if ($is_create_tbl) {
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
if ((string) $_REQUEST['field_where'] === 'last') {
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
// Only the first field can be added somewhere other than at the end
|
||||
if ((int) $current_field_num === 0) {
|
||||
if ((string) $_REQUEST['field_where'] === 'first') {
|
||||
$sql_suffix .= ' FIRST';
|
||||
} else {
|
||||
$sql_suffix .= ' AFTER '
|
||||
. Util::backquote($_REQUEST['after_field']);
|
||||
}
|
||||
} else {
|
||||
$sql_suffix .= ' AFTER '
|
||||
. Util::backquote(
|
||||
$_REQUEST['field_name'][$current_field_num - 1]
|
||||
);
|
||||
}
|
||||
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create relevant index statements
|
||||
*
|
||||
* @param array $index an array of index columns
|
||||
* @param string $index_choice index choice that which represents
|
||||
* the index type of $indexed_fields
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return array an array of sql statements for indexes
|
||||
*/
|
||||
public static function buildIndexStatements($index, $index_choice,
|
||||
$is_create_tbl = true
|
||||
) {
|
||||
$statement = array();
|
||||
if (!count($index)) {
|
||||
return $statement;
|
||||
}
|
||||
|
||||
$sql_query = self::getStatementPrefix($is_create_tbl)
|
||||
. ' ' . $index_choice;
|
||||
|
||||
if (! empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY') {
|
||||
$sql_query .= ' ' . Util::backquote($index['Key_name']);
|
||||
}
|
||||
|
||||
$index_fields = array();
|
||||
foreach ($index['columns'] as $key => $column) {
|
||||
$index_fields[$key] = Util::backquote(
|
||||
$_REQUEST['field_name'][$column['col_index']]
|
||||
);
|
||||
if ($column['size']) {
|
||||
$index_fields[$key] .= '(' . $column['size'] . ')';
|
||||
}
|
||||
} // end while
|
||||
|
||||
$sql_query .= ' (' . implode(', ', $index_fields) . ')';
|
||||
|
||||
$keyBlockSizes = $index['Key_block_size'];
|
||||
if (! empty($keyBlockSizes)) {
|
||||
$sql_query .= " KEY_BLOCK_SIZE = "
|
||||
. $GLOBALS['dbi']->escapeString($keyBlockSizes);
|
||||
}
|
||||
|
||||
// specifying index type is allowed only for primary, unique and index only
|
||||
$type = $index['Index_type'];
|
||||
if ($index['Index_choice'] != 'SPATIAL'
|
||||
&& $index['Index_choice'] != 'FULLTEXT'
|
||||
&& in_array($type, Index::getIndexTypes())
|
||||
) {
|
||||
$sql_query .= ' USING ' . $type;
|
||||
}
|
||||
|
||||
$parser = $index['Parser'];
|
||||
if ($index['Index_choice'] == 'FULLTEXT' && ! empty($parser)) {
|
||||
$sql_query .= " WITH PARSER " . $GLOBALS['dbi']->escapeString($parser);
|
||||
}
|
||||
|
||||
$comment = $index['Index_comment'];
|
||||
if (! empty($comment)) {
|
||||
$sql_query .= " COMMENT '" . $GLOBALS['dbi']->escapeString($comment)
|
||||
. "'";
|
||||
}
|
||||
|
||||
$statement[] = $sql_query;
|
||||
|
||||
return $statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statement prefix for the self::buildColumnCreationStatement()
|
||||
*
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string $sql_prefix prefix
|
||||
*/
|
||||
public static function getStatementPrefix($is_create_tbl = true)
|
||||
{
|
||||
$sql_prefix = " ";
|
||||
if (! $is_create_tbl) {
|
||||
$sql_prefix = ' ADD ';
|
||||
}
|
||||
return $sql_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge index definitions for one type of index
|
||||
*
|
||||
* @param array $definitions the index definitions to merge to
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
* @param array $indexed_columns the columns for one type of index
|
||||
* @param string $index_keyword the index keyword to use in the definition
|
||||
*
|
||||
* @return array $index_definitions
|
||||
*/
|
||||
public static function mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $indexed_columns, $index_keyword
|
||||
) {
|
||||
foreach ($indexed_columns as $index) {
|
||||
$statements = self::buildIndexStatements(
|
||||
$index, " " . $index_keyword . " ", $is_create_tbl
|
||||
);
|
||||
$definitions = array_merge($definitions, $statements);
|
||||
}
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sql statement according to the column and index specifications as
|
||||
* requested
|
||||
*
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string sql statement
|
||||
*/
|
||||
public static function getColumnCreationStatements($is_create_tbl = true)
|
||||
{
|
||||
$sql_statement = "";
|
||||
list($field_cnt, $field_primary, $field_index,
|
||||
$field_unique, $field_fulltext, $field_spatial
|
||||
) = self::getIndexedColumns();
|
||||
$definitions = self::buildColumnCreationStatement(
|
||||
$field_cnt, $is_create_tbl
|
||||
);
|
||||
|
||||
// Builds the PRIMARY KEY statements
|
||||
$primary_key_statements = self::buildIndexStatements(
|
||||
isset($field_primary[0]) ? $field_primary[0] : array(),
|
||||
" PRIMARY KEY ",
|
||||
$is_create_tbl
|
||||
);
|
||||
$definitions = array_merge($definitions, $primary_key_statements);
|
||||
|
||||
// Builds the INDEX statements
|
||||
$definitions = self::mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_index, "INDEX"
|
||||
);
|
||||
|
||||
// Builds the UNIQUE statements
|
||||
$definitions = self::mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_unique, "UNIQUE"
|
||||
);
|
||||
|
||||
// Builds the FULLTEXT statements
|
||||
$definitions = self::mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_fulltext, "FULLTEXT"
|
||||
);
|
||||
|
||||
// Builds the SPATIAL statements
|
||||
$definitions = self::mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_spatial, "SPATIAL"
|
||||
);
|
||||
|
||||
if (count($definitions)) {
|
||||
$sql_statement = implode(', ', $definitions);
|
||||
}
|
||||
$sql_statement = preg_replace('@, $@', '', $sql_statement);
|
||||
|
||||
return $sql_statement;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the partitioning clause
|
||||
*
|
||||
* @return string partitioning clause
|
||||
*/
|
||||
public static function getPartitionsDefinition()
|
||||
{
|
||||
$sql_query = "";
|
||||
if (! empty($_REQUEST['partition_by'])
|
||||
&& ! empty($_REQUEST['partition_expr'])
|
||||
&& ! empty($_REQUEST['partition_count'])
|
||||
&& $_REQUEST['partition_count'] > 1
|
||||
) {
|
||||
$sql_query .= " PARTITION BY " . $_REQUEST['partition_by']
|
||||
. " (" . $_REQUEST['partition_expr'] . ")"
|
||||
. " PARTITIONS " . $_REQUEST['partition_count'];
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['subpartition_by'])
|
||||
&& ! empty($_REQUEST['subpartition_expr'])
|
||||
&& ! empty($_REQUEST['subpartition_count'])
|
||||
&& $_REQUEST['subpartition_count'] > 1
|
||||
) {
|
||||
$sql_query .= " SUBPARTITION BY " . $_REQUEST['subpartition_by']
|
||||
. " (" . $_REQUEST['subpartition_expr'] . ")"
|
||||
. " SUBPARTITIONS " . $_REQUEST['subpartition_count'];
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['partitions'])) {
|
||||
$i = 0;
|
||||
$partitions = array();
|
||||
foreach ($_REQUEST['partitions'] as $partition) {
|
||||
$partitions[] = self::getPartitionDefinition($partition);
|
||||
$i++;
|
||||
}
|
||||
$sql_query .= " (" . implode(", ", $partitions) . ")";
|
||||
}
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the definition of a partition/subpartition
|
||||
*
|
||||
* @param array $partition array of partition/subpartition detiails
|
||||
* @param boolean $isSubPartition whether a subpartition
|
||||
*
|
||||
* @return string partition/subpartition definition
|
||||
*/
|
||||
public static function getPartitionDefinition($partition, $isSubPartition = false)
|
||||
{
|
||||
$sql_query = " " . ($isSubPartition ? "SUB" : "") . "PARTITION ";
|
||||
$sql_query .= $partition['name'];
|
||||
|
||||
if (! empty($partition['value_type'])) {
|
||||
$sql_query .= " VALUES " . $partition['value_type'];
|
||||
|
||||
if ($partition['value_type'] != 'LESS THAN MAXVALUE') {
|
||||
$sql_query .= " (" . $partition['value'] . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($partition['engine'])) {
|
||||
$sql_query .= " ENGINE = " . $partition['engine'];
|
||||
}
|
||||
if (! empty($partition['comment'])) {
|
||||
$sql_query .= " COMMENT = '" . $partition['comment'] . "'";
|
||||
}
|
||||
if (! empty($partition['data_directory'])) {
|
||||
$sql_query .= " DATA DIRECTORY = '" . $partition['data_directory'] . "'";
|
||||
}
|
||||
if (! empty($partition['index_directory'])) {
|
||||
$sql_query .= " INDEX_DIRECTORY = '" . $partition['index_directory'] . "'";
|
||||
}
|
||||
if (! empty($partition['max_rows'])) {
|
||||
$sql_query .= " MAX_ROWS = " . $partition['max_rows'];
|
||||
}
|
||||
if (! empty($partition['min_rows'])) {
|
||||
$sql_query .= " MIN_ROWS = " . $partition['min_rows'];
|
||||
}
|
||||
if (! empty($partition['tablespace'])) {
|
||||
$sql_query .= " TABLESPACE = " . $partition['tablespace'];
|
||||
}
|
||||
if (! empty($partition['node_group'])) {
|
||||
$sql_query .= " NODEGROUP = " . $partition['node_group'];
|
||||
}
|
||||
|
||||
if (! empty($partition['subpartitions'])) {
|
||||
$j = 0;
|
||||
$subpartitions = array();
|
||||
foreach ($partition['subpartitions'] as $subpartition) {
|
||||
$subpartitions[] = self::getPartitionDefinition(
|
||||
$subpartition,
|
||||
true
|
||||
);
|
||||
$j++;
|
||||
}
|
||||
$sql_query .= " (" . implode(", ", $subpartitions) . ")";
|
||||
}
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get table creation sql query
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getTableCreationQuery($db, $table)
|
||||
{
|
||||
// get column addition statements
|
||||
$sql_statement = self::getColumnCreationStatements(true);
|
||||
|
||||
// Builds the 'create table' statement
|
||||
$sql_query = 'CREATE TABLE ' . Util::backquote($db) . '.'
|
||||
. Util::backquote(trim($table)) . ' (' . $sql_statement . ')';
|
||||
|
||||
// Adds table type, character set, comments and partition definition
|
||||
if (!empty($_REQUEST['tbl_storage_engine'])
|
||||
&& ($_REQUEST['tbl_storage_engine'] != 'Default')
|
||||
) {
|
||||
$sql_query .= ' ENGINE = ' . $_REQUEST['tbl_storage_engine'];
|
||||
}
|
||||
if (!empty($_REQUEST['tbl_collation'])) {
|
||||
$sql_query .= Util::getCharsetQueryPart($_REQUEST['tbl_collation']);
|
||||
}
|
||||
if (! empty($_REQUEST['connection'])
|
||||
&& ! empty($_REQUEST['tbl_storage_engine'])
|
||||
&& $_REQUEST['tbl_storage_engine'] == 'FEDERATED'
|
||||
) {
|
||||
$sql_query .= " CONNECTION = '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['connection']) . "'";
|
||||
}
|
||||
if (!empty($_REQUEST['comment'])) {
|
||||
$sql_query .= ' COMMENT = \''
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\'';
|
||||
}
|
||||
$sql_query .= self::getPartitionsDefinition();
|
||||
$sql_query .= ';';
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the number of fields for the table creation form
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getNumberOfFieldsFromRequest()
|
||||
{
|
||||
if (isset($_REQUEST['submit_num_fields'])) { // adding new fields
|
||||
$num_fields = intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']);
|
||||
} elseif (isset($_REQUEST['orig_num_fields'])) { // retaining existing fields
|
||||
$num_fields = intval($_REQUEST['orig_num_fields']);
|
||||
} elseif (isset($_REQUEST['num_fields'])
|
||||
&& intval($_REQUEST['num_fields']) > 0
|
||||
) { // new table with specified number of fields
|
||||
$num_fields = intval($_REQUEST['num_fields']);
|
||||
} else { // new table with unspecified number of fields
|
||||
$num_fields = 4;
|
||||
}
|
||||
|
||||
// Limit to 4096 fields (MySQL maximal value)
|
||||
return min($num_fields, 4096);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to execute the column creation statement
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $err_url error page url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function tryColumnCreationQuery($db, $table, $err_url)
|
||||
{
|
||||
// get column addition statements
|
||||
$sql_statement = self::getColumnCreationStatements(false);
|
||||
|
||||
// To allow replication, we first select the db to use and then run queries
|
||||
// on this db.
|
||||
if (!($GLOBALS['dbi']->selectDb($db))) {
|
||||
Util::mysqlDie(
|
||||
$GLOBALS['dbi']->getError(),
|
||||
'USE ' . Util::backquote($db), false,
|
||||
$err_url
|
||||
);
|
||||
}
|
||||
$sql_query = 'ALTER TABLE ' .
|
||||
Util::backquote($table) . ' ' . $sql_statement . ';';
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
Core::previewSQL($sql_query);
|
||||
}
|
||||
return array($GLOBALS['dbi']->tryQuery($sql_query) , $sql_query);
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,7 @@ namespace PhpMyAdmin\Display;
|
||||
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
require_once './libraries/check_user_privileges.lib.php';
|
||||
require_once './libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Display\CreateTable class
|
||||
|
||||
@ -1002,7 +1002,6 @@ class Export
|
||||
$GLOBALS['single_table'] = $_REQUEST['single_table'];
|
||||
}
|
||||
|
||||
include_once './libraries/file_listing.lib.php';
|
||||
include_once './libraries/plugin_interface.lib.php';
|
||||
|
||||
/* Scan for plugins */
|
||||
|
||||
@ -650,7 +650,6 @@ class Import
|
||||
public static function getImportDisplay($import_type, $db, $table, $max_upload_size)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
include_once './libraries/file_listing.lib.php';
|
||||
include_once './libraries/plugin_interface.lib.php';
|
||||
|
||||
list(
|
||||
|
||||
106
libraries/classes/FileListing.php
Normal file
106
libraries/classes/FileListing.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for listing directories
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\FileListing class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class FileListing
|
||||
{
|
||||
/**
|
||||
* Returns array of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $expression regular expression to match files
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
public static function getDirContent($dir, $expression = '')
|
||||
{
|
||||
if (!@file_exists($dir) || !($handle = @opendir($dir))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if (substr($dir, -1) != '/') {
|
||||
$dir .= '/';
|
||||
}
|
||||
while ($file = @readdir($handle)) {
|
||||
if (@is_file($dir . $file)
|
||||
&& ! @is_link($dir . $file)
|
||||
&& ($expression == '' || preg_match($expression, $file))
|
||||
) {
|
||||
$result[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
asort($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $extensions regular expression to match files
|
||||
* @param string $active currently active choice
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
public static function getFileSelectOptions($dir, $extensions = '', $active = '')
|
||||
{
|
||||
$list = self::getDirContent($dir, $extensions);
|
||||
if ($list === false) {
|
||||
return false;
|
||||
}
|
||||
$result = '';
|
||||
foreach ($list as $val) {
|
||||
$result .= '<option value="' . htmlspecialchars($val) . '"';
|
||||
if ($val == $active) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently supported decompressions.
|
||||
*
|
||||
* @return string separated list of extensions usable in self::getDirContent
|
||||
*/
|
||||
public static function supportedDecompressions()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$compressions = '';
|
||||
|
||||
if ($cfg['GZipDump'] && @function_exists('gzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'gz';
|
||||
}
|
||||
if ($cfg['BZipDump'] && @function_exists('bzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'bz2';
|
||||
}
|
||||
if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'zip';
|
||||
}
|
||||
|
||||
return $compressions;
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ use PhpMyAdmin\Util;
|
||||
* We need to know something about user
|
||||
*/
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
require_once './libraries/check_user_privileges.lib.php';
|
||||
require_once './libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Import class
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\FileListing;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\TransformationsPlugin;
|
||||
use PhpMyAdmin\Relation;
|
||||
@ -1237,7 +1238,7 @@ class InsertEdit
|
||||
*/
|
||||
public static function getSelectOptionForUpload($vkey, $column)
|
||||
{
|
||||
$files = PMA_getFileSelectOptions(
|
||||
$files = FileListing::getFileSelectOptions(
|
||||
Util::userDir($GLOBALS['cfg']['UploadDir'])
|
||||
);
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ namespace PhpMyAdmin;
|
||||
use PhpMyAdmin\ListAbstract;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
require_once './libraries/check_user_privileges.lib.php';
|
||||
require_once './libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* handles database lists
|
||||
|
||||
@ -17,7 +17,7 @@ use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Util;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* Displays a collapsible of database objects in the navigation frame
|
||||
|
||||
@ -10,7 +10,7 @@ namespace PhpMyAdmin\Navigation\Nodes;
|
||||
use PhpMyAdmin\Navigation\NodeFactory;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
require_once './libraries/check_user_privileges.lib.php';
|
||||
require_once './libraries/check_user_privileges.inc.php';
|
||||
|
||||
/**
|
||||
* Represents a container for database nodes in the navigation tree
|
||||
|
||||
@ -9,6 +9,7 @@ namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\FileListing;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\ImportPlugin;
|
||||
use PhpMyAdmin\Response;
|
||||
@ -3385,14 +3386,14 @@ class Util
|
||||
}
|
||||
|
||||
$matcher = '@\.(' . $extensions . ')(\.('
|
||||
. PMA_supportedDecompressions() . '))?$@';
|
||||
. FileListing::supportedDecompressions() . '))?$@';
|
||||
|
||||
$active = (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed']
|
||||
&& isset($GLOBALS['local_import_file']))
|
||||
? $GLOBALS['local_import_file']
|
||||
: '';
|
||||
|
||||
$files = PMA_getFileSelectOptions(
|
||||
$files = FileListing::getFileSelectOptions(
|
||||
self::userDir($uploaddir),
|
||||
$matcher,
|
||||
$active
|
||||
|
||||
@ -1,495 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* set of functions for tbl_create.php and tbl_addfield.php
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Table;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Transforms the radio button field_key into 4 arrays
|
||||
*
|
||||
* @return array An array of arrays which represents column keys for each index type
|
||||
*/
|
||||
function PMA_getIndexedColumns()
|
||||
{
|
||||
$field_cnt = count($_REQUEST['field_name']);
|
||||
$field_primary = json_decode($_REQUEST['primary_indexes'], true);
|
||||
$field_index = json_decode($_REQUEST['indexes'], true);
|
||||
$field_unique = json_decode($_REQUEST['unique_indexes'], true);
|
||||
$field_fulltext = json_decode($_REQUEST['fulltext_indexes'], true);
|
||||
$field_spatial = json_decode($_REQUEST['spatial_indexes'], true);
|
||||
|
||||
return array(
|
||||
$field_cnt, $field_primary, $field_index, $field_unique,
|
||||
$field_fulltext, $field_spatial
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate the column creation statement according to the table creation or
|
||||
* add columns to a existing table
|
||||
*
|
||||
* @param int $field_cnt number of columns
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return array $definitions An array of initial sql statements
|
||||
* according to the request
|
||||
*/
|
||||
function PMA_buildColumnCreationStatement(
|
||||
$field_cnt, $is_create_tbl = true
|
||||
) {
|
||||
$definitions = array();
|
||||
for ($i = 0; $i < $field_cnt; ++$i) {
|
||||
// '0' is also empty for php :-(
|
||||
if (empty($_REQUEST['field_name'][$i])
|
||||
&& $_REQUEST['field_name'][$i] != '0'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$definition = PMA_getStatementPrefix($is_create_tbl) .
|
||||
Table::generateFieldSpec(
|
||||
trim($_REQUEST['field_name'][$i]),
|
||||
$_REQUEST['field_type'][$i],
|
||||
$_REQUEST['field_length'][$i],
|
||||
$_REQUEST['field_attribute'][$i],
|
||||
isset($_REQUEST['field_collation'][$i])
|
||||
? $_REQUEST['field_collation'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_null'][$i])
|
||||
? $_REQUEST['field_null'][$i]
|
||||
: 'NOT NULL',
|
||||
$_REQUEST['field_default_type'][$i],
|
||||
$_REQUEST['field_default_value'][$i],
|
||||
isset($_REQUEST['field_extra'][$i])
|
||||
? $_REQUEST['field_extra'][$i]
|
||||
: false,
|
||||
isset($_REQUEST['field_comments'][$i])
|
||||
? $_REQUEST['field_comments'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_virtuality'][$i])
|
||||
? $_REQUEST['field_virtuality'][$i]
|
||||
: '',
|
||||
isset($_REQUEST['field_expression'][$i])
|
||||
? $_REQUEST['field_expression'][$i]
|
||||
: ''
|
||||
);
|
||||
|
||||
$definition .= PMA_setColumnCreationStatementSuffix($i, $is_create_tbl);
|
||||
$definitions[] = $definition;
|
||||
} // end for
|
||||
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set column creation suffix according to requested position of the new column
|
||||
*
|
||||
* @param int $current_field_num current column number
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string $sql_suffix suffix
|
||||
*/
|
||||
function PMA_setColumnCreationStatementSuffix($current_field_num,
|
||||
$is_create_tbl = true
|
||||
) {
|
||||
// no suffix is needed if request is a table creation
|
||||
$sql_suffix = ' ';
|
||||
if ($is_create_tbl) {
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
if ((string) $_REQUEST['field_where'] === 'last') {
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
// Only the first field can be added somewhere other than at the end
|
||||
if ((int) $current_field_num === 0) {
|
||||
if ((string) $_REQUEST['field_where'] === 'first') {
|
||||
$sql_suffix .= ' FIRST';
|
||||
} else {
|
||||
$sql_suffix .= ' AFTER '
|
||||
. PhpMyAdmin\Util::backquote($_REQUEST['after_field']);
|
||||
}
|
||||
} else {
|
||||
$sql_suffix .= ' AFTER '
|
||||
. PhpMyAdmin\Util::backquote(
|
||||
$_REQUEST['field_name'][$current_field_num - 1]
|
||||
);
|
||||
}
|
||||
|
||||
return $sql_suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create relevant index statements
|
||||
*
|
||||
* @param array $index an array of index columns
|
||||
* @param string $index_choice index choice that which represents
|
||||
* the index type of $indexed_fields
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return array an array of sql statements for indexes
|
||||
*/
|
||||
function PMA_buildIndexStatements($index, $index_choice,
|
||||
$is_create_tbl = true
|
||||
) {
|
||||
$statement = array();
|
||||
if (!count($index)) {
|
||||
return $statement;
|
||||
}
|
||||
|
||||
$sql_query = PMA_getStatementPrefix($is_create_tbl)
|
||||
. ' ' . $index_choice;
|
||||
|
||||
if (! empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY') {
|
||||
$sql_query .= ' ' . PhpMyAdmin\Util::backquote($index['Key_name']);
|
||||
}
|
||||
|
||||
$index_fields = array();
|
||||
foreach ($index['columns'] as $key => $column) {
|
||||
$index_fields[$key] = PhpMyAdmin\Util::backquote(
|
||||
$_REQUEST['field_name'][$column['col_index']]
|
||||
);
|
||||
if ($column['size']) {
|
||||
$index_fields[$key] .= '(' . $column['size'] . ')';
|
||||
}
|
||||
} // end while
|
||||
|
||||
$sql_query .= ' (' . implode(', ', $index_fields) . ')';
|
||||
|
||||
$keyBlockSizes = $index['Key_block_size'];
|
||||
if (! empty($keyBlockSizes)) {
|
||||
$sql_query .= " KEY_BLOCK_SIZE = "
|
||||
. $GLOBALS['dbi']->escapeString($keyBlockSizes);
|
||||
}
|
||||
|
||||
// specifying index type is allowed only for primary, unique and index only
|
||||
$type = $index['Index_type'];
|
||||
if ($index['Index_choice'] != 'SPATIAL'
|
||||
&& $index['Index_choice'] != 'FULLTEXT'
|
||||
&& in_array($type, PhpMyAdmin\Index::getIndexTypes())
|
||||
) {
|
||||
$sql_query .= ' USING ' . $type;
|
||||
}
|
||||
|
||||
$parser = $index['Parser'];
|
||||
if ($index['Index_choice'] == 'FULLTEXT' && ! empty($parser)) {
|
||||
$sql_query .= " WITH PARSER " . $GLOBALS['dbi']->escapeString($parser);
|
||||
}
|
||||
|
||||
$comment = $index['Index_comment'];
|
||||
if (! empty($comment)) {
|
||||
$sql_query .= " COMMENT '" . $GLOBALS['dbi']->escapeString($comment)
|
||||
. "'";
|
||||
}
|
||||
|
||||
$statement[] = $sql_query;
|
||||
|
||||
return $statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statement prefix for the PMA_buildColumnCreationStatement()
|
||||
*
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string $sql_prefix prefix
|
||||
*/
|
||||
function PMA_getStatementPrefix($is_create_tbl = true)
|
||||
{
|
||||
$sql_prefix = " ";
|
||||
if (! $is_create_tbl) {
|
||||
$sql_prefix = ' ADD ';
|
||||
}
|
||||
return $sql_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge index definitions for one type of index
|
||||
*
|
||||
* @param array $definitions the index definitions to merge to
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
* @param array $indexed_columns the columns for one type of index
|
||||
* @param string $index_keyword the index keyword to use in the definition
|
||||
*
|
||||
* @return array $index_definitions
|
||||
*/
|
||||
function PMA_mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $indexed_columns, $index_keyword
|
||||
) {
|
||||
foreach ($indexed_columns as $index) {
|
||||
$statements = PMA_buildIndexStatements(
|
||||
$index, " " . $index_keyword . " ", $is_create_tbl
|
||||
);
|
||||
$definitions = array_merge($definitions, $statements);
|
||||
}
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sql statement according to the column and index specifications as
|
||||
* requested
|
||||
*
|
||||
* @param boolean $is_create_tbl true if requirement is to get the statement
|
||||
* for table creation
|
||||
*
|
||||
* @return string sql statement
|
||||
*/
|
||||
function PMA_getColumnCreationStatements($is_create_tbl = true)
|
||||
{
|
||||
$sql_statement = "";
|
||||
list($field_cnt, $field_primary, $field_index,
|
||||
$field_unique, $field_fulltext, $field_spatial
|
||||
) = PMA_getIndexedColumns();
|
||||
$definitions = PMA_buildColumnCreationStatement(
|
||||
$field_cnt, $is_create_tbl
|
||||
);
|
||||
|
||||
// Builds the PRIMARY KEY statements
|
||||
$primary_key_statements = PMA_buildIndexStatements(
|
||||
isset($field_primary[0]) ? $field_primary[0] : array(),
|
||||
" PRIMARY KEY ",
|
||||
$is_create_tbl
|
||||
);
|
||||
$definitions = array_merge($definitions, $primary_key_statements);
|
||||
|
||||
// Builds the INDEX statements
|
||||
$definitions = PMA_mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_index, "INDEX"
|
||||
);
|
||||
|
||||
// Builds the UNIQUE statements
|
||||
$definitions = PMA_mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_unique, "UNIQUE"
|
||||
);
|
||||
|
||||
// Builds the FULLTEXT statements
|
||||
$definitions = PMA_mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_fulltext, "FULLTEXT"
|
||||
);
|
||||
|
||||
// Builds the SPATIAL statements
|
||||
$definitions = PMA_mergeIndexStatements(
|
||||
$definitions, $is_create_tbl, $field_spatial, "SPATIAL"
|
||||
);
|
||||
|
||||
if (count($definitions)) {
|
||||
$sql_statement = implode(', ', $definitions);
|
||||
}
|
||||
$sql_statement = preg_replace('@, $@', '', $sql_statement);
|
||||
|
||||
return $sql_statement;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the partitioning clause
|
||||
*
|
||||
* @return string partitioning clause
|
||||
*/
|
||||
function PMA_getPartitionsDefinition()
|
||||
{
|
||||
$sql_query = "";
|
||||
if (! empty($_REQUEST['partition_by'])
|
||||
&& ! empty($_REQUEST['partition_expr'])
|
||||
&& ! empty($_REQUEST['partition_count'])
|
||||
&& $_REQUEST['partition_count'] > 1
|
||||
) {
|
||||
$sql_query .= " PARTITION BY " . $_REQUEST['partition_by']
|
||||
. " (" . $_REQUEST['partition_expr'] . ")"
|
||||
. " PARTITIONS " . $_REQUEST['partition_count'];
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['subpartition_by'])
|
||||
&& ! empty($_REQUEST['subpartition_expr'])
|
||||
&& ! empty($_REQUEST['subpartition_count'])
|
||||
&& $_REQUEST['subpartition_count'] > 1
|
||||
) {
|
||||
$sql_query .= " SUBPARTITION BY " . $_REQUEST['subpartition_by']
|
||||
. " (" . $_REQUEST['subpartition_expr'] . ")"
|
||||
. " SUBPARTITIONS " . $_REQUEST['subpartition_count'];
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['partitions'])) {
|
||||
$i = 0;
|
||||
$partitions = array();
|
||||
foreach ($_REQUEST['partitions'] as $partition) {
|
||||
$partitions[] = PMA_getPartitionDefinition($partition);
|
||||
$i++;
|
||||
}
|
||||
$sql_query .= " (" . implode(", ", $partitions) . ")";
|
||||
}
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the definition of a partition/subpartition
|
||||
*
|
||||
* @param array $partition array of partition/subpartition detiails
|
||||
* @param boolean $isSubPartition whether a subpartition
|
||||
*
|
||||
* @return string partition/subpartition definition
|
||||
*/
|
||||
function PMA_getPartitionDefinition($partition, $isSubPartition = false)
|
||||
{
|
||||
$sql_query = " " . ($isSubPartition ? "SUB" : "") . "PARTITION ";
|
||||
$sql_query .= $partition['name'];
|
||||
|
||||
if (! empty($partition['value_type'])) {
|
||||
$sql_query .= " VALUES " . $partition['value_type'];
|
||||
|
||||
if ($partition['value_type'] != 'LESS THAN MAXVALUE') {
|
||||
$sql_query .= " (" . $partition['value'] . ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($partition['engine'])) {
|
||||
$sql_query .= " ENGINE = " . $partition['engine'];
|
||||
}
|
||||
if (! empty($partition['comment'])) {
|
||||
$sql_query .= " COMMENT = '" . $partition['comment'] . "'";
|
||||
}
|
||||
if (! empty($partition['data_directory'])) {
|
||||
$sql_query .= " DATA DIRECTORY = '" . $partition['data_directory'] . "'";
|
||||
}
|
||||
if (! empty($partition['index_directory'])) {
|
||||
$sql_query .= " INDEX_DIRECTORY = '" . $partition['index_directory'] . "'";
|
||||
}
|
||||
if (! empty($partition['max_rows'])) {
|
||||
$sql_query .= " MAX_ROWS = " . $partition['max_rows'];
|
||||
}
|
||||
if (! empty($partition['min_rows'])) {
|
||||
$sql_query .= " MIN_ROWS = " . $partition['min_rows'];
|
||||
}
|
||||
if (! empty($partition['tablespace'])) {
|
||||
$sql_query .= " TABLESPACE = " . $partition['tablespace'];
|
||||
}
|
||||
if (! empty($partition['node_group'])) {
|
||||
$sql_query .= " NODEGROUP = " . $partition['node_group'];
|
||||
}
|
||||
|
||||
if (! empty($partition['subpartitions'])) {
|
||||
$j = 0;
|
||||
$subpartitions = array();
|
||||
foreach ($partition['subpartitions'] as $subpartition) {
|
||||
$subpartitions[] = PMA_getPartitionDefinition(
|
||||
$subpartition,
|
||||
true
|
||||
);
|
||||
$j++;
|
||||
}
|
||||
$sql_query .= " (" . implode(", ", $subpartitions) . ")";
|
||||
}
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get table creation sql query
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getTableCreationQuery($db, $table)
|
||||
{
|
||||
// get column addition statements
|
||||
$sql_statement = PMA_getColumnCreationStatements(true);
|
||||
|
||||
// Builds the 'create table' statement
|
||||
$sql_query = 'CREATE TABLE ' . PhpMyAdmin\Util::backquote($db) . '.'
|
||||
. PhpMyAdmin\Util::backquote(trim($table)) . ' (' . $sql_statement . ')';
|
||||
|
||||
// Adds table type, character set, comments and partition definition
|
||||
if (!empty($_REQUEST['tbl_storage_engine'])
|
||||
&& ($_REQUEST['tbl_storage_engine'] != 'Default')
|
||||
) {
|
||||
$sql_query .= ' ENGINE = ' . $_REQUEST['tbl_storage_engine'];
|
||||
}
|
||||
if (!empty($_REQUEST['tbl_collation'])) {
|
||||
$sql_query .= Util::getCharsetQueryPart($_REQUEST['tbl_collation']);
|
||||
}
|
||||
if (! empty($_REQUEST['connection'])
|
||||
&& ! empty($_REQUEST['tbl_storage_engine'])
|
||||
&& $_REQUEST['tbl_storage_engine'] == 'FEDERATED'
|
||||
) {
|
||||
$sql_query .= " CONNECTION = '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['connection']) . "'";
|
||||
}
|
||||
if (!empty($_REQUEST['comment'])) {
|
||||
$sql_query .= ' COMMENT = \''
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\'';
|
||||
}
|
||||
$sql_query .= PMA_getPartitionsDefinition();
|
||||
$sql_query .= ';';
|
||||
|
||||
return $sql_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the number of fields for the table creation form
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function PMA_getNumberOfFieldsFromRequest()
|
||||
{
|
||||
if (isset($_REQUEST['submit_num_fields'])) { // adding new fields
|
||||
$num_fields = intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']);
|
||||
} elseif (isset($_REQUEST['orig_num_fields'])) { // retaining existing fields
|
||||
$num_fields = intval($_REQUEST['orig_num_fields']);
|
||||
} elseif (isset($_REQUEST['num_fields'])
|
||||
&& intval($_REQUEST['num_fields']) > 0
|
||||
) { // new table with specified number of fields
|
||||
$num_fields = intval($_REQUEST['num_fields']);
|
||||
} else { // new table with unspecified number of fields
|
||||
$num_fields = 4;
|
||||
}
|
||||
|
||||
// Limit to 4096 fields (MySQL maximal value)
|
||||
return min($num_fields, 4096);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to execute the column creation statement
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $err_url error page url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function PMA_tryColumnCreationQuery($db, $table, $err_url)
|
||||
{
|
||||
// get column addition statements
|
||||
$sql_statement = PMA_getColumnCreationStatements(false);
|
||||
|
||||
// To allow replication, we first select the db to use and then run queries
|
||||
// on this db.
|
||||
if (!($GLOBALS['dbi']->selectDb($db))) {
|
||||
PhpMyAdmin\Util::mysqlDie(
|
||||
$GLOBALS['dbi']->getError(),
|
||||
'USE ' . PhpMyAdmin\Util::backquote($db), false,
|
||||
$err_url
|
||||
);
|
||||
}
|
||||
$sql_query = 'ALTER TABLE ' .
|
||||
PhpMyAdmin\Util::backquote($table) . ' ' . $sql_statement . ';';
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
Core::previewSQL($sql_query);
|
||||
}
|
||||
return array($GLOBALS['dbi']->tryQuery($sql_query) , $sql_query);
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for listing directories
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns array of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $expression regular expression to match files
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
function PMA_getDirContent($dir, $expression = '')
|
||||
{
|
||||
if (!@file_exists($dir) || !($handle = @opendir($dir))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if (substr($dir, -1) != '/') {
|
||||
$dir .= '/';
|
||||
}
|
||||
while ($file = @readdir($handle)) {
|
||||
if (@is_file($dir . $file)
|
||||
&& ! @is_link($dir . $file)
|
||||
&& ($expression == '' || preg_match($expression, $file))
|
||||
) {
|
||||
$result[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
asort($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $extensions regular expression to match files
|
||||
* @param string $active currently active choice
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
|
||||
{
|
||||
$list = PMA_getDirContent($dir, $extensions);
|
||||
if ($list === false) {
|
||||
return false;
|
||||
}
|
||||
$result = '';
|
||||
foreach ($list as $val) {
|
||||
$result .= '<option value="' . htmlspecialchars($val) . '"';
|
||||
if ($val == $active) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently supported decompressions.
|
||||
*
|
||||
* @return string separated list of extensions usable in PMA_getDirContent
|
||||
*/
|
||||
function PMA_supportedDecompressions()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$compressions = '';
|
||||
|
||||
if ($cfg['GZipDump'] && @function_exists('gzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'gz';
|
||||
}
|
||||
if ($cfg['BZipDump'] && @function_exists('bzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'bz2';
|
||||
}
|
||||
if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'zip';
|
||||
}
|
||||
|
||||
return $compressions;
|
||||
}
|
||||
@ -18,11 +18,6 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once './libraries/file_listing.lib.php'; // used for file listing
|
||||
|
||||
/**
|
||||
* return HTML for the sql query boxes
|
||||
*
|
||||
|
||||
@ -22,7 +22,7 @@ require_once 'libraries/common.inc.php';
|
||||
/**
|
||||
* functions implementation for this script
|
||||
*/
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
$cfgRelation = Relation::getRelationsParam();
|
||||
|
||||
|
||||
2
sql.php
2
sql.php
@ -17,7 +17,7 @@ use PhpMyAdmin\Util;
|
||||
* Gets some core libraries
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
PageSettings::showGroup('Browse');
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\CreateAddField;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use PhpMyAdmin\Url;
|
||||
@ -62,9 +63,7 @@ if (isset($_REQUEST['do_save_data'])) {
|
||||
//tbl_structure.php below
|
||||
unset($_REQUEST['do_save_data']);
|
||||
|
||||
include_once 'libraries/create_addfield.lib.php';
|
||||
|
||||
list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
|
||||
list($result, $sql_query) = CreateAddField::tryColumnCreationQuery($db, $table, $err_url);
|
||||
|
||||
if ($result === true) {
|
||||
// Update comment table for mime types [MIME]
|
||||
|
||||
@ -37,10 +37,6 @@ list(
|
||||
if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
|
||||
$rows = array_fill(0, count($unsaved_values), false);
|
||||
}
|
||||
/**
|
||||
* file listing
|
||||
*/
|
||||
require_once 'libraries/file_listing.lib.php';
|
||||
|
||||
/**
|
||||
* Defines the url to return to in case of error in a sql statement
|
||||
|
||||
@ -7,22 +7,23 @@
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\CreateAddField;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Get some core libraries
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/create_addfield.lib.php';
|
||||
|
||||
// Check parameters
|
||||
PhpMyAdmin\Util::checkParameters(array('db'));
|
||||
Util::checkParameters(array('db'));
|
||||
|
||||
/* Check if database name is empty */
|
||||
if (strlen($db) === 0) {
|
||||
PhpMyAdmin\Util::mysqlDie(
|
||||
Util::mysqlDie(
|
||||
__('The database name is empty!'), '', false, 'index.php'
|
||||
);
|
||||
}
|
||||
@ -31,7 +32,7 @@ if (strlen($db) === 0) {
|
||||
* Selects the database to work with
|
||||
*/
|
||||
if (!$GLOBALS['dbi']->selectDb($db)) {
|
||||
PhpMyAdmin\Util::mysqlDie(
|
||||
Util::mysqlDie(
|
||||
sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
|
||||
'',
|
||||
false,
|
||||
@ -41,7 +42,7 @@ if (!$GLOBALS['dbi']->selectDb($db)) {
|
||||
|
||||
if ($GLOBALS['dbi']->getColumns($db, $table)) {
|
||||
// table exists already
|
||||
PhpMyAdmin\Util::mysqlDie(
|
||||
Util::mysqlDie(
|
||||
sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
|
||||
'',
|
||||
false,
|
||||
@ -51,7 +52,7 @@ if ($GLOBALS['dbi']->getColumns($db, $table)) {
|
||||
|
||||
// for libraries/tbl_columns_definition_form.inc.php
|
||||
// check number of fields to be created
|
||||
$num_fields = PMA_getNumberOfFieldsFromRequest();
|
||||
$num_fields = CreateAddField::getNumberOfFieldsFromRequest();
|
||||
|
||||
$action = 'tbl_create.php';
|
||||
|
||||
@ -59,7 +60,7 @@ $action = 'tbl_create.php';
|
||||
* The form used to define the structure of the table has been submitted
|
||||
*/
|
||||
if (isset($_REQUEST['do_save_data'])) {
|
||||
$sql_query = PMA_getTableCreationQuery($db, $table);
|
||||
$sql_query = CreateAddField::getTableCreationQuery($db, $table);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_REQUEST['preview_sql'])) {
|
||||
|
||||
@ -22,7 +22,7 @@ require_once 'libraries/common.inc.php';
|
||||
/**
|
||||
* functions implementation for this script
|
||||
*/
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
$pma_table = new Table($GLOBALS['table'], $GLOBALS['db']);
|
||||
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for libraries/browse_foreigners.lib.php
|
||||
* Tests for PhpMyAdmin\BrowseForeigners
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/browse_foreigners.lib.php';
|
||||
use PhpMyAdmin\BrowseForeigners;
|
||||
|
||||
/**
|
||||
* Tests for libraries/browse_foreigners.lib.php
|
||||
* Tests for PhpMyAdmin\BrowseForeigners
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
class BrowseForeignersTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Setup for test cases
|
||||
@ -29,43 +27,43 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getForeignLimit
|
||||
* Test for BrowseForeigners::getForeignLimit
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetForeignLimit()
|
||||
{
|
||||
$this->assertNull(
|
||||
PMA_getForeignLimit('Show all')
|
||||
BrowseForeigners::getForeignLimit('Show all')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'LIMIT 0, 25 ',
|
||||
PMA_getForeignLimit(null)
|
||||
BrowseForeigners::getForeignLimit(null)
|
||||
);
|
||||
|
||||
$_REQUEST['pos'] = 10;
|
||||
|
||||
$this->assertEquals(
|
||||
'LIMIT 10, 25 ',
|
||||
PMA_getForeignLimit(null)
|
||||
BrowseForeigners::getForeignLimit(null)
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['MaxRows'] = 50;
|
||||
|
||||
$this->assertEquals(
|
||||
'LIMIT 10, 50 ',
|
||||
PMA_getForeignLimit(null)
|
||||
BrowseForeigners::getForeignLimit(null)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'LIMIT 10, 50 ',
|
||||
PMA_getForeignLimit('xyz')
|
||||
BrowseForeigners::getForeignLimit('xyz')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForShowAll
|
||||
* Test for BrowseForeigners::getHtmlForShowAll
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -73,7 +71,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
PMA_getHtmlForShowAll(null)
|
||||
BrowseForeigners::getHtmlForShowAll(null)
|
||||
);
|
||||
|
||||
$foreignData = array();
|
||||
@ -82,7 +80,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
PMA_getHtmlForShowAll($foreignData)
|
||||
BrowseForeigners::getHtmlForShowAll($foreignData)
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['ShowAll'] = true;
|
||||
@ -90,7 +88,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
PMA_getHtmlForShowAll($foreignData)
|
||||
BrowseForeigners::getHtmlForShowAll($foreignData)
|
||||
);
|
||||
|
||||
$foreignData['the_total'] = 30;
|
||||
@ -99,12 +97,12 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
'<input type="submit" id="foreign_showAll" '
|
||||
. 'name="foreign_showAll" '
|
||||
. 'value="' . 'Show all' . '" />',
|
||||
PMA_getHtmlForShowAll($foreignData)
|
||||
BrowseForeigners::getHtmlForShowAll($foreignData)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForGotoPage
|
||||
* Test for BrowseForeigners::getHtmlForGotoPage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -112,7 +110,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->assertEquals(
|
||||
'',
|
||||
PMA_getHtmlForGotoPage(null)
|
||||
BrowseForeigners::getHtmlForGotoPage(null)
|
||||
);
|
||||
|
||||
$_REQUEST['pos'] = 15;
|
||||
@ -122,11 +120,11 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
'',
|
||||
PMA_getHtmlForGotoPage($foreignData)
|
||||
BrowseForeigners::getHtmlForGotoPage($foreignData)
|
||||
);
|
||||
|
||||
$foreignData['the_total'] = 30;
|
||||
$result = PMA_getHtmlForGotoPage($foreignData);
|
||||
$result = BrowseForeigners::getHtmlForGotoPage($foreignData);
|
||||
|
||||
$this->assertStringStartsWith(
|
||||
'Page number:',
|
||||
@ -156,7 +154,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForColumnElement
|
||||
* Test for BrowseForeigners::getHtmlForColumnElement
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -167,7 +165,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
$keyname = '';
|
||||
$description = 'foo';
|
||||
$title = '';
|
||||
$result = PMA_getHtmlForColumnElement(
|
||||
$result = BrowseForeigners::getHtmlForColumnElement(
|
||||
$cssClass, $isSelected, $keyname,
|
||||
$description, $title
|
||||
);
|
||||
@ -187,7 +185,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
$isSelected = true;
|
||||
$keyname = 'bar';
|
||||
$title = 'foo';
|
||||
$result = PMA_getHtmlForColumnElement(
|
||||
$result = BrowseForeigners::getHtmlForColumnElement(
|
||||
$cssClass, $isSelected, $keyname,
|
||||
$description, $title
|
||||
);
|
||||
@ -210,7 +208,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getDescriptionAndTitle
|
||||
* Test for BrowseForeigners::getDescriptionAndTitle
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -221,19 +219,19 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(
|
||||
array('foobar<baz', ''),
|
||||
PMA_getDescriptionAndTitle($desc)
|
||||
BrowseForeigners::getDescriptionAndTitle($desc)
|
||||
);
|
||||
|
||||
$GLOBALS['cfg']['LimitChars'] = 5;
|
||||
|
||||
$this->assertEquals(
|
||||
array('fooba...', 'foobar<baz'),
|
||||
PMA_getDescriptionAndTitle($desc)
|
||||
BrowseForeigners::getDescriptionAndTitle($desc)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_getHtmlForRelationalFieldSelection
|
||||
* Test for BrowseForeigners::getHtmlForRelationalFieldSelection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -248,7 +246,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
$current_value = '';
|
||||
$_REQUEST['rownumber'] = 1;
|
||||
$_REQUEST['foreign_filter'] = '5';
|
||||
$result = PMA_getHtmlForRelationalFieldSelection(
|
||||
$result = BrowseForeigners::getHtmlForRelationalFieldSelection(
|
||||
$db, $table, $field, $foreignData, $fieldkey, $current_value
|
||||
);
|
||||
|
||||
@ -315,7 +313,7 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase
|
||||
$foreignData['disp_row'] = array();
|
||||
$foreignData['the_total'] = 5;
|
||||
$GLOBALS['cfg']['ShowAll'] = false;
|
||||
$result = PMA_getHtmlForRelationalFieldSelection(
|
||||
$result = BrowseForeigners::getHtmlForRelationalFieldSelection(
|
||||
$db, $table, $field, $foreignData, $fieldkey, $current_value
|
||||
);
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for check_user_privileges.lib.php
|
||||
* tests for PhpMyAdmin\CheckUserPrivileges
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests;
|
||||
|
||||
use PhpMyAdmin\CheckUserPrivileges;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
|
||||
/**
|
||||
* tests for check_user_privileges.lib.php
|
||||
* tests for PhpMyAdmin\CheckUserPrivileges
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
class CheckUserPrivilegesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* prepares environment for tests
|
||||
*
|
||||
@ -29,7 +29,6 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
$GLOBALS['col_priv'] = false;
|
||||
$GLOBALS['db_priv'] = false;
|
||||
$GLOBALS['proc_priv'] = false;
|
||||
@ -48,7 +47,7 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
@ -75,7 +74,7 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
@ -102,7 +101,7 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
@ -125,7 +124,7 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
/**
|
||||
* Test for PMA_checkRequiredPrivilegesForAdjust
|
||||
* Test for CheckUserPrivileges::checkRequiredPrivilegesForAdjust
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -138,12 +137,12 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
// call the to-be-tested function
|
||||
PMA_checkRequiredPrivilegesForAdjust(
|
||||
CheckUserPrivileges::checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
@ -179,12 +178,12 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
// call the to-be-tested function
|
||||
PMA_checkRequiredPrivilegesForAdjust(
|
||||
CheckUserPrivileges::checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
@ -220,12 +219,12 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
// call the to-be-tested function
|
||||
PMA_checkRequiredPrivilegesForAdjust(
|
||||
CheckUserPrivileges::checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
@ -261,12 +260,12 @@ class PMA_CheckUserPrivileges_Test extends PHPUnit_Framework_TestCase
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
) = PMA_getItemsFromShowGrantsRow(
|
||||
) = CheckUserPrivileges::getItemsFromShowGrantsRow(
|
||||
$show_grants_full_row
|
||||
);
|
||||
|
||||
// call the to-be-tested function
|
||||
PMA_checkRequiredPrivilegesForAdjust(
|
||||
CheckUserPrivileges::checkRequiredPrivilegesForAdjust(
|
||||
$show_grants_str,
|
||||
$show_grants_dbname,
|
||||
$show_grants_tblname
|
||||
@ -14,7 +14,7 @@ use PhpMyAdmin\Util;
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
|
||||
@ -1214,7 +1214,7 @@ class InsertEditTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* This condition should be tested, however, it gives an undefined function
|
||||
* PMA_getFileSelectOptions error:
|
||||
* PhpMyAdmin\FileListing::getFileSelectOptions error:
|
||||
* $GLOBALS['cfg']['UploadDir'] = true;
|
||||
*
|
||||
*/
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Navigation\NavigationTree;
|
||||
use PhpMyAdmin\Theme;
|
||||
@ -16,7 +16,7 @@ use PhpMyAdmin\Theme;
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
require_once 'libraries/check_user_privileges.lib.php';
|
||||
require_once 'libraries/check_user_privileges.inc.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportCsv;
|
||||
use PhpMyAdmin\Theme;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportLdi;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
*/
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportMediawiki;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportOds;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportShp;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportSql;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
* since 'check_user_privileges.inc.php' will use it globally
|
||||
*/
|
||||
use PhpMyAdmin\Plugins\Import\ImportXml;
|
||||
use PhpMyAdmin\File;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user