From 62f53a1cd93e0bc8fb506a97f95faa30a2db7ffe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 11:09:03 -0300
Subject: [PATCH 01/11] Rename information_schema_relations.lib.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Rename libraries/information_schema_relations.lib.php to libraries/information_schema_relations.inc.php
Signed-off-by: Maurício Meneghini Fauth
---
libraries/classes/Relation.php | 2 +-
...a_relations.lib.php => information_schema_relations.inc.php} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename libraries/{information_schema_relations.lib.php => information_schema_relations.inc.php} (100%)
diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php
index 02442b6bbd..d7461da935 100644
--- a/libraries/classes/Relation.php
+++ b/libraries/classes/Relation.php
@@ -807,7 +807,7 @@ class Relation
) {
if ($isInformationSchema) {
$relations_key = 'information_schema_relations';
- include_once './libraries/information_schema_relations.lib.php';
+ include_once './libraries/information_schema_relations.inc.php';
} else {
$relations_key = 'mysql_relations';
include_once './libraries/mysql_relations.lib.php';
diff --git a/libraries/information_schema_relations.lib.php b/libraries/information_schema_relations.inc.php
similarity index 100%
rename from libraries/information_schema_relations.lib.php
rename to libraries/information_schema_relations.inc.php
From 7bd3a54cbb572c4e50b6a805c9fcea4c223a1131 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 12:01:57 -0300
Subject: [PATCH 02/11] Refactor ip_allow_deny functions to static methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
libraries/classes/IpAllowDeny.php | 310 ++++++++++++++++++
libraries/common.inc.php | 17 +-
libraries/ip_allow_deny.lib.php | 303 -----------------
.../IpAllowDenyTest.php} | 54 +--
4 files changed, 343 insertions(+), 341 deletions(-)
create mode 100644 libraries/classes/IpAllowDeny.php
delete mode 100644 libraries/ip_allow_deny.lib.php
rename test/{libraries/PMA_ip_allow_deny_test.php => classes/IpAllowDenyTest.php} (81%)
diff --git a/libraries/classes/IpAllowDeny.php b/libraries/classes/IpAllowDeny.php
new file mode 100644
index 0000000000..790db16e0c
--- /dev/null
+++ b/libraries/classes/IpAllowDeny.php
@@ -0,0 +1,310 @@
+ -1
+ || mb_strpos($ipToTest, ':') > -1
+ ) {
+ // assume IPv6
+ $result = self::ipv6MaskTest($testRange, $ipToTest);
+ } else {
+ $result = self::ipv4MaskTest($testRange, $ipToTest);
+ }
+
+ return $result;
+ } // end of the "self::ipMaskTest()" function
+
+ /**
+ * Based on IP Pattern Matcher
+ * Originally by J.Adams
+ * Found on
+ * Modified for phpMyAdmin
+ *
+ * Matches:
+ * xxx.xxx.xxx.xxx (exact)
+ * xxx.xxx.xxx.[yyy-zzz] (range)
+ * xxx.xxx.xxx.xxx/nn (CIDR)
+ *
+ * Does not match:
+ * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported)
+ *
+ * @param string $testRange string of IP range to match
+ * @param string $ipToTest string of IP to test against range
+ *
+ * @return boolean whether the IP mask matches
+ *
+ * @access public
+ */
+ public static function ipv4MaskTest($testRange, $ipToTest)
+ {
+ $result = true;
+ $match = preg_match(
+ '|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)|',
+ $testRange,
+ $regs
+ );
+ if ($match) {
+ // performs a mask match
+ $ipl = ip2long($ipToTest);
+ $rangel = ip2long(
+ $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]
+ );
+
+ $maskl = 0;
+
+ for ($i = 0; $i < 31; $i++) {
+ if ($i < $regs[5] - 1) {
+ $maskl = $maskl + pow(2, (30 - $i));
+ } // end if
+ } // end for
+
+ if (($maskl & $rangel) == ($maskl & $ipl)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ // range based
+ $maskocts = explode('.', $testRange);
+ $ipocts = explode('.', $ipToTest);
+
+ // perform a range match
+ for ($i = 0; $i < 4; $i++) {
+ if (preg_match('|\[([0-9]+)\-([0-9]+)\]|', $maskocts[$i], $regs)) {
+ if (($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) {
+ $result = false;
+ } // end if
+ } else {
+ if ($maskocts[$i] <> $ipocts[$i]) {
+ $result = false;
+ } // end if
+ } // end if/else
+ } //end for
+
+ return $result;
+ } // end of the "self::ipv4MaskTest()" function
+
+ /**
+ * IPv6 matcher
+ * CIDR section taken from https://stackoverflow.com/a/10086404
+ * Modified for phpMyAdmin
+ *
+ * Matches:
+ * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
+ * (exact)
+ * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:[yyyy-zzzz]
+ * (range, only at end of IP - no subnets)
+ * xxxx:xxxx:xxxx:xxxx/nn
+ * (CIDR)
+ *
+ * Does not match:
+ * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx[yyy-zzz]
+ * (range, partial octets not supported)
+ *
+ * @param string $test_range string of IP range to match
+ * @param string $ip_to_test string of IP to test against range
+ *
+ * @return boolean whether the IP mask matches
+ *
+ * @access public
+ */
+ public static function ipv6MaskTest($test_range, $ip_to_test)
+ {
+ $result = true;
+
+ // convert to lowercase for easier comparison
+ $test_range = mb_strtolower($test_range);
+ $ip_to_test = mb_strtolower($ip_to_test);
+
+ $is_cidr = mb_strpos($test_range, '/') > -1;
+ $is_range = mb_strpos($test_range, '[') > -1;
+ $is_single = ! $is_cidr && ! $is_range;
+
+ $ip_hex = bin2hex(inet_pton($ip_to_test));
+
+ if ($is_single) {
+ $range_hex = bin2hex(inet_pton($test_range));
+ $result = hash_equals($ip_hex, $range_hex);
+ return $result;
+ }
+
+ if ($is_range) {
+ // what range do we operate on?
+ $range_match = array();
+ $match = preg_match(
+ '/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $test_range, $range_match
+ );
+ if ($match) {
+ $range_start = $range_match[1];
+ $range_end = $range_match[2];
+
+ // get the first and last allowed IPs
+ $first_ip = str_replace($range_match[0], $range_start, $test_range);
+ $first_hex = bin2hex(inet_pton($first_ip));
+ $last_ip = str_replace($range_match[0], $range_end, $test_range);
+ $last_hex = bin2hex(inet_pton($last_ip));
+
+ // check if the IP to test is within the range
+ $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
+ }
+ return $result;
+ }
+
+ if ($is_cidr) {
+ // Split in address and prefix length
+ list($first_ip, $subnet) = explode('/', $test_range);
+
+ // Parse the address into a binary string
+ $first_bin = inet_pton($first_ip);
+ $first_hex = bin2hex($first_bin);
+
+ $flexbits = 128 - $subnet;
+
+ // Build the hexadecimal string of the last address
+ $last_hex = $first_hex;
+
+ $pos = 31;
+ while ($flexbits > 0) {
+ // Get the character at this position
+ $orig = mb_substr($last_hex, $pos, 1);
+
+ // Convert it to an integer
+ $origval = hexdec($orig);
+
+ // OR it with (2^flexbits)-1, with flexbits limited to 4 at a time
+ $newval = $origval | (pow(2, min(4, $flexbits)) - 1);
+
+ // Convert it back to a hexadecimal character
+ $new = dechex($newval);
+
+ // And put that character back in the string
+ $last_hex = substr_replace($last_hex, $new, $pos, 1);
+
+ // We processed one nibble, move to previous position
+ $flexbits -= 4;
+ --$pos;
+ }
+
+ // check if the IP to test is within the range
+ $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
+ }
+
+ return $result;
+ } // end of the "self::ipv6MaskTest()" function
+
+ /**
+ * Runs through IP Allow/Deny rules the use of it below for more information
+ *
+ * @param string $type 'allow' | 'deny' type of rule to match
+ *
+ * @return bool Whether rule has matched
+ *
+ * @access public
+ *
+ * @see Core::getIp()
+ */
+ public static function allowDeny($type)
+ {
+ global $cfg;
+
+ // Grabs true IP of the user and returns if it can't be found
+ $remote_ip = Core::getIp();
+ if (empty($remote_ip)) {
+ return false;
+ }
+
+ // copy username
+ $username = $cfg['Server']['user'];
+
+ // copy rule database
+ if (isset($cfg['Server']['AllowDeny']['rules'])) {
+ $rules = $cfg['Server']['AllowDeny']['rules'];
+ if (! is_array($rules)) {
+ $rules = array();
+ }
+ } else {
+ $rules = array();
+ }
+
+ // lookup table for some name shortcuts
+ $shortcuts = array(
+ 'all' => '0.0.0.0/0',
+ 'localhost' => '127.0.0.1/8'
+ );
+
+ // Provide some useful shortcuts if server gives us address:
+ if (Core::getenv('SERVER_ADDR')) {
+ $shortcuts['localnetA'] = Core::getenv('SERVER_ADDR') . '/8';
+ $shortcuts['localnetB'] = Core::getenv('SERVER_ADDR') . '/16';
+ $shortcuts['localnetC'] = Core::getenv('SERVER_ADDR') . '/24';
+ }
+
+ foreach ($rules as $rule) {
+ // extract rule data
+ $rule_data = explode(' ', $rule);
+
+ // check for rule type
+ if ($rule_data[0] != $type) {
+ continue;
+ }
+
+ // check for username
+ if (($rule_data[1] != '%') //wildcarded first
+ && (! hash_equals($rule_data[1], $username))
+ ) {
+ continue;
+ }
+
+ // check if the config file has the full string with an extra
+ // 'from' in it and if it does, just discard it
+ if ($rule_data[2] == 'from') {
+ $rule_data[2] = $rule_data[3];
+ }
+
+ // Handle shortcuts with above array
+ if (isset($shortcuts[$rule_data[2]])) {
+ $rule_data[2] = $shortcuts[$rule_data[2]];
+ }
+
+ // Add code for host lookups here
+ // Excluded for the moment
+
+ // Do the actual matching now
+ if (self::ipMaskTest($rule_data[2], $remote_ip)) {
+ return true;
+ }
+ } // end while
+
+ return false;
+ } // end of the "self::allowDeny()" function
+}
diff --git a/libraries/common.inc.php b/libraries/common.inc.php
index 750151df74..cc22b1e8ac 100644
--- a/libraries/common.inc.php
+++ b/libraries/common.inc.php
@@ -36,6 +36,7 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\DbList;
use PhpMyAdmin\ErrorHandler;
+use PhpMyAdmin\IpAllowDeny;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Logging;
use PhpMyAdmin\Message;
@@ -635,30 +636,24 @@ if (! defined('PMA_MINIMUM_COMMON')) {
if (isset($cfg['Server']['AllowDeny'])
&& isset($cfg['Server']['AllowDeny']['order'])
) {
-
- /**
- * ip based access library
- */
- include_once './libraries/ip_allow_deny.lib.php';
-
$allowDeny_forbidden = false; // default
if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
$allowDeny_forbidden = true;
- if (PMA_allowDeny('allow')) {
+ if (IpAllowDeny::allowDeny('allow')) {
$allowDeny_forbidden = false;
}
- if (PMA_allowDeny('deny')) {
+ if (IpAllowDeny::allowDeny('deny')) {
$allowDeny_forbidden = true;
}
} elseif ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
- if (PMA_allowDeny('deny')) {
+ if (IpAllowDeny::allowDeny('deny')) {
$allowDeny_forbidden = true;
}
- if (PMA_allowDeny('allow')) {
+ if (IpAllowDeny::allowDeny('allow')) {
$allowDeny_forbidden = false;
}
} elseif ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
- if (PMA_allowDeny('allow') && ! PMA_allowDeny('deny')) {
+ if (IpAllowDeny::allowDeny('allow') && ! IpAllowDeny::allowDeny('deny')) {
$allowDeny_forbidden = false;
} else {
$allowDeny_forbidden = true;
diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php
deleted file mode 100644
index 87ea8125b1..0000000000
--- a/libraries/ip_allow_deny.lib.php
+++ /dev/null
@@ -1,303 +0,0 @@
- -1
- || mb_strpos($ipToTest, ':') > -1
- ) {
- // assume IPv6
- $result = PMA_ipv6MaskTest($testRange, $ipToTest);
- } else {
- $result = PMA_ipv4MaskTest($testRange, $ipToTest);
- }
-
- return $result;
-} // end of the "PMA_ipMaskTest()" function
-
-
-/**
- * Based on IP Pattern Matcher
- * Originally by J.Adams
- * Found on
- * Modified for phpMyAdmin
- *
- * Matches:
- * xxx.xxx.xxx.xxx (exact)
- * xxx.xxx.xxx.[yyy-zzz] (range)
- * xxx.xxx.xxx.xxx/nn (CIDR)
- *
- * Does not match:
- * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported)
- *
- * @param string $testRange string of IP range to match
- * @param string $ipToTest string of IP to test against range
- *
- * @return boolean whether the IP mask matches
- *
- * @access public
- */
-function PMA_ipv4MaskTest($testRange, $ipToTest)
-{
- $result = true;
- $match = preg_match(
- '|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)|',
- $testRange,
- $regs
- );
- if ($match) {
- // performs a mask match
- $ipl = ip2long($ipToTest);
- $rangel = ip2long(
- $regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]
- );
-
- $maskl = 0;
-
- for ($i = 0; $i < 31; $i++) {
- if ($i < $regs[5] - 1) {
- $maskl = $maskl + pow(2, (30 - $i));
- } // end if
- } // end for
-
- if (($maskl & $rangel) == ($maskl & $ipl)) {
- return true;
- }
-
- return false;
- }
-
- // range based
- $maskocts = explode('.', $testRange);
- $ipocts = explode('.', $ipToTest);
-
- // perform a range match
- for ($i = 0; $i < 4; $i++) {
- if (preg_match('|\[([0-9]+)\-([0-9]+)\]|', $maskocts[$i], $regs)) {
- if (($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) {
- $result = false;
- } // end if
- } else {
- if ($maskocts[$i] <> $ipocts[$i]) {
- $result = false;
- } // end if
- } // end if/else
- } //end for
-
- return $result;
-} // end of the "PMA_ipv4MaskTest()" function
-
-
-/**
- * IPv6 matcher
- * CIDR section taken from https://stackoverflow.com/a/10086404
- * Modified for phpMyAdmin
- *
- * Matches:
- * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
- * (exact)
- * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:[yyyy-zzzz]
- * (range, only at end of IP - no subnets)
- * xxxx:xxxx:xxxx:xxxx/nn
- * (CIDR)
- *
- * Does not match:
- * xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xx[yyy-zzz]
- * (range, partial octets not supported)
- *
- * @param string $test_range string of IP range to match
- * @param string $ip_to_test string of IP to test against range
- *
- * @return boolean whether the IP mask matches
- *
- * @access public
- */
-function PMA_ipv6MaskTest($test_range, $ip_to_test)
-{
- $result = true;
-
- // convert to lowercase for easier comparison
- $test_range = mb_strtolower($test_range);
- $ip_to_test = mb_strtolower($ip_to_test);
-
- $is_cidr = mb_strpos($test_range, '/') > -1;
- $is_range = mb_strpos($test_range, '[') > -1;
- $is_single = ! $is_cidr && ! $is_range;
-
- $ip_hex = bin2hex(inet_pton($ip_to_test));
-
- if ($is_single) {
- $range_hex = bin2hex(inet_pton($test_range));
- $result = hash_equals($ip_hex, $range_hex);
- return $result;
- }
-
- if ($is_range) {
- // what range do we operate on?
- $range_match = array();
- $match = preg_match(
- '/\[([0-9a-f]+)\-([0-9a-f]+)\]/', $test_range, $range_match
- );
- if ($match) {
- $range_start = $range_match[1];
- $range_end = $range_match[2];
-
- // get the first and last allowed IPs
- $first_ip = str_replace($range_match[0], $range_start, $test_range);
- $first_hex = bin2hex(inet_pton($first_ip));
- $last_ip = str_replace($range_match[0], $range_end, $test_range);
- $last_hex = bin2hex(inet_pton($last_ip));
-
- // check if the IP to test is within the range
- $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
- }
- return $result;
- }
-
- if ($is_cidr) {
- // Split in address and prefix length
- list($first_ip, $subnet) = explode('/', $test_range);
-
- // Parse the address into a binary string
- $first_bin = inet_pton($first_ip);
- $first_hex = bin2hex($first_bin);
-
- $flexbits = 128 - $subnet;
-
- // Build the hexadecimal string of the last address
- $last_hex = $first_hex;
-
- $pos = 31;
- while ($flexbits > 0) {
- // Get the character at this position
- $orig = mb_substr($last_hex, $pos, 1);
-
- // Convert it to an integer
- $origval = hexdec($orig);
-
- // OR it with (2^flexbits)-1, with flexbits limited to 4 at a time
- $newval = $origval | (pow(2, min(4, $flexbits)) - 1);
-
- // Convert it back to a hexadecimal character
- $new = dechex($newval);
-
- // And put that character back in the string
- $last_hex = substr_replace($last_hex, $new, $pos, 1);
-
- // We processed one nibble, move to previous position
- $flexbits -= 4;
- --$pos;
- }
-
- // check if the IP to test is within the range
- $result = ($ip_hex >= $first_hex && $ip_hex <= $last_hex);
- }
-
- return $result;
-} // end of the "PMA_ipv6MaskTest()" function
-
-
-/**
- * Runs through IP Allow/Deny rules the use of it below for more information
- *
- * @param string $type 'allow' | 'deny' type of rule to match
- *
- * @return bool Whether rule has matched
- *
- * @access public
- *
- * @see Core::getIp()
- */
-function PMA_allowDeny($type)
-{
- global $cfg;
-
- // Grabs true IP of the user and returns if it can't be found
- $remote_ip = Core::getIp();
- if (empty($remote_ip)) {
- return false;
- }
-
- // copy username
- $username = $cfg['Server']['user'];
-
- // copy rule database
- if (isset($cfg['Server']['AllowDeny']['rules'])) {
- $rules = $cfg['Server']['AllowDeny']['rules'];
- if (! is_array($rules)) {
- $rules = array();
- }
- } else {
- $rules = array();
- }
-
- // lookup table for some name shortcuts
- $shortcuts = array(
- 'all' => '0.0.0.0/0',
- 'localhost' => '127.0.0.1/8'
- );
-
- // Provide some useful shortcuts if server gives us address:
- if (Core::getenv('SERVER_ADDR')) {
- $shortcuts['localnetA'] = Core::getenv('SERVER_ADDR') . '/8';
- $shortcuts['localnetB'] = Core::getenv('SERVER_ADDR') . '/16';
- $shortcuts['localnetC'] = Core::getenv('SERVER_ADDR') . '/24';
- }
-
- foreach ($rules as $rule) {
- // extract rule data
- $rule_data = explode(' ', $rule);
-
- // check for rule type
- if ($rule_data[0] != $type) {
- continue;
- }
-
- // check for username
- if (($rule_data[1] != '%') //wildcarded first
- && (! hash_equals($rule_data[1], $username))
- ) {
- continue;
- }
-
- // check if the config file has the full string with an extra
- // 'from' in it and if it does, just discard it
- if ($rule_data[2] == 'from') {
- $rule_data[2] = $rule_data[3];
- }
-
- // Handle shortcuts with above array
- if (isset($shortcuts[$rule_data[2]])) {
- $rule_data[2] = $shortcuts[$rule_data[2]];
- }
-
- // Add code for host lookups here
- // Excluded for the moment
-
- // Do the actual matching now
- if (PMA_ipMaskTest($rule_data[2], $remote_ip)) {
- return true;
- }
- } // end while
-
- return false;
-} // end of the "PMA_AllowDeny()" function
diff --git a/test/libraries/PMA_ip_allow_deny_test.php b/test/classes/IpAllowDenyTest.php
similarity index 81%
rename from test/libraries/PMA_ip_allow_deny_test.php
rename to test/classes/IpAllowDenyTest.php
index 51dcdc498f..a54661e509 100644
--- a/test/libraries/PMA_ip_allow_deny_test.php
+++ b/test/classes/IpAllowDenyTest.php
@@ -1,23 +1,23 @@
assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$testRange = "255.255.0.0/4";
$ipToTest = "255.3.0.0";
$this->assertEquals(
true,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$testRange = "255.255.0.[0-10]";
$ipToTest = "255.3.0.3";
$this->assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$ipToTest = "255.3.0.12";
$this->assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
//IPV6 testing
@@ -140,13 +140,13 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase
$testRange = "2001:4998:c:a0d:0000:0000:4998:1020";
$this->assertEquals(
true,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$ipToTest = "2001:4998:c:a0d:0000:0000:4998:1020";
$testRange = "2001:4998:c:a0d:0000:0000:4998:2020";
$this->assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
//range
@@ -154,13 +154,13 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase
$testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]";
$this->assertEquals(
true,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$ipToTest = "2001:4998:c:a0d:0000:0000:4998:3020";
$testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]";
$this->assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
//CDIR
@@ -168,18 +168,18 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase
$testRange = "2001:4998:c:a0d:0000:0000:4998:[1001-2010]";
$this->assertEquals(
true,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
$ipToTest = "2001:4998:c:a0d:0000:0000:4998:1000";
$testRange = "2001:4998:c:a0d:0000:0000:4998:3020/24";
$this->assertEquals(
false,
- PMA_ipMaskTest($testRange, $ipToTest)
+ IpAllowDeny::ipMaskTest($testRange, $ipToTest)
);
}
/**
- * Test for PMA_allowDeny
+ * Test for IpAllowDeny::allowDeny
*
* @return void
*/
@@ -188,51 +188,51 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase
$_SERVER['REMOTE_ADDR'] = "";
$this->assertEquals(
false,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
$_SERVER['REMOTE_ADDR'] = "255.0.1.0";
$this->assertEquals(
true,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
$_SERVER['REMOTE_ADDR'] = "10.0.0.0";
$this->assertEquals(
false,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
$_SERVER['REMOTE_ADDR'] = "255.255.0.1";
$this->assertEquals(
true,
- PMA_allowDeny("deny")
+ IpAllowDeny::allowDeny("deny")
);
$_SERVER['REMOTE_ADDR'] = "255.124.0.5";
$this->assertEquals(
true,
- PMA_allowDeny("deny")
+ IpAllowDeny::allowDeny("deny")
);
$_SERVER['REMOTE_ADDR'] = "122.124.0.5";
$this->assertEquals(
false,
- PMA_allowDeny("deny")
+ IpAllowDeny::allowDeny("deny")
);
//IPV6
$_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1020";
$this->assertEquals(
true,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
$_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1000";
$this->assertEquals(
false,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
$_SERVER['REMOTE_ADDR'] = "2001:4998:c:a0d:0000:0000:4998:1020";
$this->assertEquals(
true,
- PMA_allowDeny("allow")
+ IpAllowDeny::allowDeny("allow")
);
}
}
From e143d36344f281af380672fbd421b2343af26a48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 12:22:45 -0300
Subject: [PATCH 03/11] Refactor mime.lib.php function to a static method
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
libraries/classes/Mime.php | 39 +++++++++++++++++++
libraries/mime.lib.php | 30 --------------
tbl_get_field.php | 4 +-
.../MimeTest.php} | 25 ++++++------
4 files changed, 52 insertions(+), 46 deletions(-)
create mode 100644 libraries/classes/Mime.php
delete mode 100644 libraries/mime.lib.php
rename test/{libraries/PMA_mime_test.php => classes/MimeTest.php} (64%)
diff --git a/libraries/classes/Mime.php b/libraries/classes/Mime.php
new file mode 100644
index 0000000000..c42293e397
--- /dev/null
+++ b/libraries/classes/Mime.php
@@ -0,0 +1,39 @@
+= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) {
+ return 'image/jpeg';
+ }
+ if ($len >= 3 && substr($test, 0, 3) == 'GIF') {
+ return 'image/gif';
+ }
+ if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") {
+ return 'image/png';
+ }
+ return 'application/octet-stream';
+ }
+}
diff --git a/libraries/mime.lib.php b/libraries/mime.lib.php
deleted file mode 100644
index f1a7757ac0..0000000000
--- a/libraries/mime.lib.php
+++ /dev/null
@@ -1,30 +0,0 @@
-= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) {
- return 'image/jpeg';
- }
- if ($len >= 3 && substr($test, 0, 3) == 'GIF') {
- return 'image/gif';
- }
- if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") {
- return 'image/png';
- }
- return 'application/octet-stream';
-}
diff --git a/tbl_get_field.php b/tbl_get_field.php
index 366dd683e5..526410eea9 100644
--- a/tbl_get_field.php
+++ b/tbl_get_field.php
@@ -7,6 +7,7 @@
*/
use PhpMyAdmin\Core;
+use PhpMyAdmin\Mime;
/**
* Common functions.
@@ -15,7 +16,6 @@ use PhpMyAdmin\Core;
// data
define('PMA_BYPASS_GET_INSTANCE', 1);
require_once 'libraries/common.inc.php';
-require_once 'libraries/mime.lib.php';
/* Check parameters */
PhpMyAdmin\Util::checkParameters(
@@ -53,7 +53,7 @@ if ($result === false) {
Core::downloadHeader(
$table . '-' . $_GET['transform_key'] . '.bin',
- PMA_detectMIME($result),
+ Mime::detect($result),
strlen($result)
);
echo $result;
diff --git a/test/libraries/PMA_mime_test.php b/test/classes/MimeTest.php
similarity index 64%
rename from test/libraries/PMA_mime_test.php
rename to test/classes/MimeTest.php
index b49bac52be..5d0a09bd8d 100644
--- a/test/libraries/PMA_mime_test.php
+++ b/test/classes/MimeTest.php
@@ -1,48 +1,45 @@
assertEquals(
- PMA_detectMIME($test),
+ Mime::detect($test),
$output
);
}
/**
- * Provider for testPMA_detectMIME
+ * Provider for testDetect
*
- * @return array data for testPMA_detectMIME
+ * @return array data for testDetect
*/
- public function providerForTestDetectMIME()
+ public function providerForTestDetect()
{
return array(
array(
From 42023486e820d335fd42c21c3dd46433cb9d8c14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 12:48:17 -0300
Subject: [PATCH 04/11] Refactor mult_submits functions to static methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
libraries/classes/MultSubmits.php | 586 ++++++++++++++++++
libraries/mult_submits.inc.php | 21 +-
libraries/mult_submits.lib.php | 577 -----------------
.../MultSubmitsTest.php} | 42 +-
4 files changed, 616 insertions(+), 610 deletions(-)
create mode 100644 libraries/classes/MultSubmits.php
delete mode 100644 libraries/mult_submits.lib.php
rename test/{libraries/PMA_mult_submits_test.php => classes/MultSubmitsTest.php} (88%)
diff --git a/libraries/classes/MultSubmits.php b/libraries/classes/MultSubmits.php
new file mode 100644
index 0000000000..95a646de7a
--- /dev/null
+++ b/libraries/classes/MultSubmits.php
@@ -0,0 +1,586 @@
+ $what,
+ 'reload' => (! empty($reload) ? 1 : 0),
+ );
+ if (mb_strpos(' ' . $action, 'db_') == 1) {
+ $_url_params['db']= $db;
+ } elseif (mb_strpos(' ' . $action, 'tbl_') == 1
+ || $what == 'row_delete'
+ ) {
+ $_url_params['db']= $db;
+ $_url_params['table']= $table;
+ }
+ foreach ($selected as $sval) {
+ if ($what == 'row_delete') {
+ $_url_params['selected'][] = 'DELETE FROM '
+ . Util::backquote($table)
+ . ' WHERE ' . $sval . ' LIMIT 1;';
+ } else {
+ $_url_params['selected'][] = $sval;
+ }
+ }
+ if ($what == 'drop_tbl' && !empty($views)) {
+ foreach ($views as $current) {
+ $_url_params['views'][] = $current;
+ }
+ }
+ if ($what == 'row_delete') {
+ $_url_params['original_sql_query'] = $original_sql_query;
+ if (! empty($original_url_query)) {
+ $_url_params['original_url_query'] = $original_url_query;
+ }
+ }
+
+ return $_url_params;
+ }
+
+ /**
+ * Builds or execute queries for multiple elements, depending on $query_type
+ *
+ * @param string $query_type query type
+ * @param array $selected selected tables
+ * @param string $db db name
+ * @param string $table table name
+ * @param array $views table views
+ * @param string $primary table primary
+ * @param string $from_prefix from prefix original
+ * @param string $to_prefix to prefix original
+ *
+ * @return array
+ */
+ public static function buildOrExecuteQueryForMulti(
+ $query_type, $selected, $db, $table, $views, $primary,
+ $from_prefix, $to_prefix
+ ) {
+ $rebuild_database_list = false;
+ $reload = null;
+ $a_query = null;
+ $sql_query = '';
+ $sql_query_views = null;
+ // whether to run query after each pass
+ $run_parts = false;
+ // whether to execute the query at the end (to display results)
+ $execute_query_later = false;
+ $result = null;
+
+ if ($query_type == 'drop_tbl') {
+ $sql_query_views = '';
+ }
+
+ $selected_cnt = count($selected);
+ $deletes = false;
+ $copy_tbl =false;
+
+ for ($i = 0; $i < $selected_cnt; $i++) {
+ switch ($query_type) {
+ case 'row_delete':
+ $deletes = true;
+ $a_query = $selected[$i];
+ $run_parts = true;
+ break;
+
+ case 'drop_db':
+ PMA_relationsCleanupDatabase($selected[$i]);
+ $a_query = 'DROP DATABASE '
+ . Util::backquote($selected[$i]);
+ $reload = 1;
+ $run_parts = true;
+ $rebuild_database_list = true;
+ break;
+
+ case 'drop_tbl':
+ PMA_relationsCleanupTable($db, $selected[$i]);
+ $current = $selected[$i];
+ if (!empty($views) && in_array($current, $views)) {
+ $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ')
+ . Util::backquote($current);
+ } else {
+ $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
+ . Util::backquote($current);
+ }
+ $reload = 1;
+ break;
+
+ case 'check_tbl':
+ $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
+ . Util::backquote($selected[$i]);
+ $execute_query_later = true;
+ break;
+
+ case 'optimize_tbl':
+ $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
+ . Util::backquote($selected[$i]);
+ $execute_query_later = true;
+ break;
+
+ case 'analyze_tbl':
+ $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
+ . Util::backquote($selected[$i]);
+ $execute_query_later = true;
+ break;
+
+ case 'checksum_tbl':
+ $sql_query .= (empty($sql_query) ? 'CHECKSUM TABLE ' : ', ')
+ . Util::backquote($selected[$i]);
+ $execute_query_later = true;
+ break;
+
+ case 'repair_tbl':
+ $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
+ . Util::backquote($selected[$i]);
+ $execute_query_later = true;
+ break;
+
+ case 'empty_tbl':
+ $deletes = true;
+ $a_query = 'TRUNCATE ';
+ $a_query .= Util::backquote($selected[$i]);
+ $run_parts = true;
+ break;
+
+ case 'drop_fld':
+ PMA_relationsCleanupColumn($db, $table, $selected[$i]);
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ : ',')
+ . ' DROP ' . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ';' : '');
+ break;
+
+ case 'primary_fld':
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ . (empty($primary)
+ ? ''
+ : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( '
+ : ', ')
+ . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ');' : '');
+ break;
+
+ case 'index_fld':
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ . ' ADD INDEX( '
+ : ', ')
+ . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ');' : '');
+ break;
+
+ case 'unique_fld':
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ . ' ADD UNIQUE( '
+ : ', ')
+ . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ');' : '');
+ break;
+
+ case 'spatial_fld':
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ . ' ADD SPATIAL( '
+ : ', ')
+ . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ');' : '');
+ break;
+
+ case 'fulltext_fld':
+ $sql_query .= (empty($sql_query)
+ ? 'ALTER TABLE ' . Util::backquote($table)
+ . ' ADD FULLTEXT( '
+ : ', ')
+ . Util::backquote($selected[$i])
+ . (($i == $selected_cnt-1) ? ');' : '');
+ break;
+
+ case 'add_prefix_tbl':
+ $newtablename = $_POST['add_prefix'] . $selected[$i];
+ // ADD PREFIX TO TABLE NAME
+ $a_query = 'ALTER TABLE '
+ . Util::backquote($selected[$i])
+ . ' RENAME '
+ . Util::backquote($newtablename);
+ $run_parts = true;
+ break;
+
+ case 'replace_prefix_tbl':
+ $current = $selected[$i];
+ $subFromPrefix = mb_substr(
+ $current,
+ 0,
+ mb_strlen($from_prefix)
+ );
+ if ($subFromPrefix == $from_prefix) {
+ $newtablename = $to_prefix
+ . mb_substr(
+ $current,
+ mb_strlen($from_prefix)
+ );
+ } else {
+ $newtablename = $current;
+ }
+ // CHANGE PREFIX PATTERN
+ $a_query = 'ALTER TABLE '
+ . Util::backquote($selected[$i])
+ . ' RENAME '
+ . Util::backquote($newtablename);
+ $run_parts = true;
+ break;
+
+ case 'copy_tbl_change_prefix':
+ $run_parts = true;
+ $copy_tbl = true;
+
+ $current = $selected[$i];
+ $newtablename = $to_prefix .
+ mb_substr($current, mb_strlen($from_prefix));
+
+ // COPY TABLE AND CHANGE PREFIX PATTERN
+ Table::moveCopy(
+ $db, $current, $db, $newtablename,
+ 'data', false, 'one_table'
+ );
+ break;
+
+ case 'copy_tbl':
+ $run_parts = true;
+ $copy_tbl = true;
+ Table::moveCopy($db, $selected[$i], $_POST['target_db'], $selected[$i], $_POST['what'], false, 'one_table');
+ if (isset($_POST['adjust_privileges']) && !empty($_POST['adjust_privileges'])) {
+ Operations::adjustPrivilegesCopyTable($db, $selected[$i], $_POST['target_db'], $selected[$i]);
+ }
+ break;
+ } // end switch
+
+ // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
+ // statements will be run at once below
+ if ($run_parts && !$copy_tbl) {
+ $sql_query .= $a_query . ';' . "\n";
+ if ($query_type != 'drop_db') {
+ $GLOBALS['dbi']->selectDb($db);
+ }
+ $result = $GLOBALS['dbi']->query($a_query);
+
+ if ($query_type == 'drop_db') {
+ Transformations::clear($selected[$i]);
+ } elseif ($query_type == 'drop_tbl') {
+ Transformations::clear($db, $selected[$i]);
+ } else if ($query_type == 'drop_fld') {
+ Transformations::clear($db, $table, $selected[$i]);
+ }
+ } // end if
+ } // end for
+
+ if ($deletes && ! empty($_REQUEST['pos'])) {
+ $_REQUEST['pos'] = Sql::calculatePosForLastPage(
+ $db, $table, isset($_REQUEST['pos']) ? $_REQUEST['pos'] : null
+ );
+ }
+
+ return array(
+ $result, $rebuild_database_list, $reload,
+ $run_parts, $execute_query_later, $sql_query, $sql_query_views
+ );
+ }
+
+ /**
+ * Gets HTML for copy tables form
+ *
+ * @param string $action action type
+ * @param array $_url_params URL params
+ *
+ * @return string
+ */
+ public static function getHtmlForCopyMultipleTables($action, $_url_params)
+ {
+ $html = '';
+ return $html;
+ }
+
+ /**
+ * Gets HTML for replace_prefix_tbl or copy_tbl_change_prefix
+ *
+ * @param string $action action type
+ * @param array $_url_params URL params
+ *
+ * @return string
+ */
+ public static function getHtmlForReplacePrefixTable($action, $_url_params)
+ {
+ $html = '';
+
+ return $html;
+ }
+
+ /**
+ * Gets HTML for add_prefix_tbl
+ *
+ * @param string $action action type
+ * @param array $_url_params URL params
+ *
+ * @return string
+ */
+ public static function getHtmlForAddPrefixTable($action, $_url_params)
+ {
+ $html = '';
+
+ return $html;
+ }
+
+ /**
+ * Gets HTML for other mult_submits actions
+ *
+ * @param string $what mult_submit type
+ * @param string $action action type
+ * @param array $_url_params URL params
+ * @param string $full_query full sql query string
+ *
+ * @return string
+ */
+ public static function getHtmlForOtherActions($what, $action, $_url_params, $full_query)
+ {
+ $html = '';
+
+ return $html;
+ }
+
+ /**
+ * Get query string from Selected
+ *
+ * @param string $what mult_submit type
+ * @param string $table table name
+ * @param array $selected the selected columns
+ * @param array $views table views
+ *
+ * @return array
+ */
+ public static function getQueryFromSelected($what, $table, $selected, $views)
+ {
+ $reload = false;
+ $full_query_views = null;
+ $full_query = '';
+
+ if ($what == 'drop_tbl') {
+ $full_query_views = '';
+ }
+
+ $selected_cnt = count($selected);
+ $i = 0;
+ foreach ($selected as $sval) {
+ switch ($what) {
+ case 'row_delete':
+ $full_query .= 'DELETE FROM '
+ . Util::backquote(htmlspecialchars($table))
+ // Do not append a "LIMIT 1" clause here
+ // (it's not binlog friendly).
+ // We don't need the clause because the calling panel permits
+ // this feature only when there is a unique index.
+ . ' WHERE ' . htmlspecialchars($sval)
+ . '; ';
+ break;
+ case 'drop_db':
+ $full_query .= 'DROP DATABASE '
+ . Util::backquote(htmlspecialchars($sval))
+ . '; ';
+ $reload = true;
+ break;
+
+ case 'drop_tbl':
+ $current = $sval;
+ if (!empty($views) && in_array($current, $views)) {
+ $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ')
+ . Util::backquote(htmlspecialchars($current));
+ } else {
+ $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ')
+ . Util::backquote(htmlspecialchars($current));
+ }
+ break;
+
+ case 'empty_tbl':
+ $full_query .= 'TRUNCATE ';
+ $full_query .= Util::backquote(htmlspecialchars($sval))
+ . '; ';
+ break;
+
+ case 'primary_fld':
+ if ($full_query == '') {
+ $full_query .= 'ALTER TABLE '
+ . Util::backquote(htmlspecialchars($table))
+ . ' DROP PRIMARY KEY,'
+ . ' ADD PRIMARY KEY('
+ . ' '
+ . Util::backquote(htmlspecialchars($sval))
+ . ',';
+ } else {
+ $full_query .= ' '
+ . Util::backquote(htmlspecialchars($sval))
+ . ',';
+ }
+ if ($i == $selected_cnt-1) {
+ $full_query = preg_replace('@,$@', '); ', $full_query);
+ }
+ break;
+
+ case 'drop_fld':
+ if ($full_query == '') {
+ $full_query .= 'ALTER TABLE '
+ . Util::backquote(htmlspecialchars($table));
+ }
+ $full_query .= ' DROP '
+ . Util::backquote(htmlspecialchars($sval))
+ . ',';
+ if ($i == $selected_cnt - 1) {
+ $full_query = preg_replace('@,$@', '; ', $full_query);
+ }
+ break;
+ } // end switch
+ $i++;
+ }
+
+ if ($what == 'drop_tbl') {
+ if (!empty($full_query)) {
+ $full_query .= '; ' . "\n";
+ }
+ if (!empty($full_query_views)) {
+ $full_query .= $full_query_views . '; ' . "\n";
+ }
+ unset($full_query_views);
+ }
+
+ $full_query_views = isset($full_query_views)? $full_query_views : null;
+
+ return array($full_query, $reload, $full_query_views);
+ }
+}
diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php
index 946bfcc7f0..5f2d086afc 100644
--- a/libraries/mult_submits.inc.php
+++ b/libraries/mult_submits.inc.php
@@ -8,6 +8,7 @@
use PhpMyAdmin\CentralColumns;
use PhpMyAdmin\Message;
+use PhpMyAdmin\MultSubmits;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
@@ -15,8 +16,6 @@ if (! defined('PHPMYADMIN')) {
exit;
}
-require_once 'libraries/mult_submits.lib.php';
-
$request_params = array(
'clause_is_unique',
'from_prefix',
@@ -92,17 +91,17 @@ if (! empty($submit_mult)
case 'copy_tbl':
$views = $GLOBALS['dbi']->getVirtualTables($db);
list($full_query, $reload, $full_query_views)
- = PMA_getQueryFromSelected(
+ = MultSubmits::getQueryFromSelected(
$submit_mult, $table, $selected, $views
);
- $_url_params = PMA_getUrlParams(
+ $_url_params = MultSubmits::getUrlParams(
$submit_mult, $reload, $action, $db, $table, $selected, $views,
isset($original_sql_query)? $original_sql_query : null,
isset($original_url_query)? $original_url_query : null
);
$response->disable();
$response->addHTML(
- PMA_getHtmlForCopyMultipleTables($action, $_url_params)
+ MultSubmits::getHtmlForCopyMultipleTables($action, $_url_params)
);
exit;
case 'show_create':
@@ -180,12 +179,12 @@ if (!empty($submit_mult) && !empty($what)) {
// Builds the query
list($full_query, $reload, $full_query_views)
- = PMA_getQueryFromSelected(
+ = MultSubmits::getQueryFromSelected(
$what, $table, $selected, $views
);
// Displays the confirmation form
- $_url_params = PMA_getUrlParams(
+ $_url_params = MultSubmits::getUrlParams(
$what, $reload, $action, $db, $table, $selected, $views,
isset($original_sql_query)? $original_sql_query : null,
isset($original_url_query)? $original_url_query : null
@@ -195,14 +194,14 @@ if (!empty($submit_mult) && !empty($what)) {
if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') {
$response->disable();
$response->addHTML(
- PMA_getHtmlForReplacePrefixTable($action, $_url_params)
+ MultSubmits::getHtmlForReplacePrefixTable($action, $_url_params)
);
} elseif ($what == 'add_prefix_tbl') {
$response->disable();
- $response->addHTML(PMA_getHtmlForAddPrefixTable($action, $_url_params));
+ $response->addHTML(MultSubmits::getHtmlForAddPrefixTable($action, $_url_params));
} else {
$response->addHTML(
- PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
+ MultSubmits::getHtmlForOtherActions($what, $action, $_url_params, $full_query)
);
}
exit;
@@ -244,7 +243,7 @@ if (!empty($submit_mult) && !empty($what)) {
list(
$result, $rebuild_database_list, $reload_ret,
$run_parts, $execute_query_later, $sql_query, $sql_query_views
- ) = PMA_buildOrExecuteQueryForMulti(
+ ) = MultSubmits::buildOrExecuteQueryForMulti(
$query_type, $selected, $db, $table, $views,
isset($primary) ? $primary : null,
isset($from_prefix) ? $from_prefix : null,
diff --git a/libraries/mult_submits.lib.php b/libraries/mult_submits.lib.php
deleted file mode 100644
index aee828eb70..0000000000
--- a/libraries/mult_submits.lib.php
+++ /dev/null
@@ -1,577 +0,0 @@
- $what,
- 'reload' => (! empty($reload) ? 1 : 0),
- );
- if (mb_strpos(' ' . $action, 'db_') == 1) {
- $_url_params['db']= $db;
- } elseif (mb_strpos(' ' . $action, 'tbl_') == 1
- || $what == 'row_delete'
- ) {
- $_url_params['db']= $db;
- $_url_params['table']= $table;
- }
- foreach ($selected as $sval) {
- if ($what == 'row_delete') {
- $_url_params['selected'][] = 'DELETE FROM '
- . Util::backquote($table)
- . ' WHERE ' . $sval . ' LIMIT 1;';
- } else {
- $_url_params['selected'][] = $sval;
- }
- }
- if ($what == 'drop_tbl' && !empty($views)) {
- foreach ($views as $current) {
- $_url_params['views'][] = $current;
- }
- }
- if ($what == 'row_delete') {
- $_url_params['original_sql_query'] = $original_sql_query;
- if (! empty($original_url_query)) {
- $_url_params['original_url_query'] = $original_url_query;
- }
- }
-
- return $_url_params;
-}
-
-/**
- * Builds or execute queries for multiple elements, depending on $query_type
- *
- * @param string $query_type query type
- * @param array $selected selected tables
- * @param string $db db name
- * @param string $table table name
- * @param array $views table views
- * @param string $primary table primary
- * @param string $from_prefix from prefix original
- * @param string $to_prefix to prefix original
- *
- * @return array
- */
-function PMA_buildOrExecuteQueryForMulti(
- $query_type, $selected, $db, $table, $views, $primary,
- $from_prefix, $to_prefix
-) {
- $rebuild_database_list = false;
- $reload = null;
- $a_query = null;
- $sql_query = '';
- $sql_query_views = null;
- // whether to run query after each pass
- $run_parts = false;
- // whether to execute the query at the end (to display results)
- $execute_query_later = false;
- $result = null;
-
- if ($query_type == 'drop_tbl') {
- $sql_query_views = '';
- }
-
- $selected_cnt = count($selected);
- $deletes = false;
- $copy_tbl =false;
-
- for ($i = 0; $i < $selected_cnt; $i++) {
- switch ($query_type) {
- case 'row_delete':
- $deletes = true;
- $a_query = $selected[$i];
- $run_parts = true;
- break;
-
- case 'drop_db':
- PMA_relationsCleanupDatabase($selected[$i]);
- $a_query = 'DROP DATABASE '
- . Util::backquote($selected[$i]);
- $reload = 1;
- $run_parts = true;
- $rebuild_database_list = true;
- break;
-
- case 'drop_tbl':
- PMA_relationsCleanupTable($db, $selected[$i]);
- $current = $selected[$i];
- if (!empty($views) && in_array($current, $views)) {
- $sql_query_views .= (empty($sql_query_views) ? 'DROP VIEW ' : ', ')
- . Util::backquote($current);
- } else {
- $sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ')
- . Util::backquote($current);
- }
- $reload = 1;
- break;
-
- case 'check_tbl':
- $sql_query .= (empty($sql_query) ? 'CHECK TABLE ' : ', ')
- . Util::backquote($selected[$i]);
- $execute_query_later = true;
- break;
-
- case 'optimize_tbl':
- $sql_query .= (empty($sql_query) ? 'OPTIMIZE TABLE ' : ', ')
- . Util::backquote($selected[$i]);
- $execute_query_later = true;
- break;
-
- case 'analyze_tbl':
- $sql_query .= (empty($sql_query) ? 'ANALYZE TABLE ' : ', ')
- . Util::backquote($selected[$i]);
- $execute_query_later = true;
- break;
-
- case 'checksum_tbl':
- $sql_query .= (empty($sql_query) ? 'CHECKSUM TABLE ' : ', ')
- . Util::backquote($selected[$i]);
- $execute_query_later = true;
- break;
-
- case 'repair_tbl':
- $sql_query .= (empty($sql_query) ? 'REPAIR TABLE ' : ', ')
- . Util::backquote($selected[$i]);
- $execute_query_later = true;
- break;
-
- case 'empty_tbl':
- $deletes = true;
- $a_query = 'TRUNCATE ';
- $a_query .= Util::backquote($selected[$i]);
- $run_parts = true;
- break;
-
- case 'drop_fld':
- PMA_relationsCleanupColumn($db, $table, $selected[$i]);
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- : ',')
- . ' DROP ' . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ';' : '');
- break;
-
- case 'primary_fld':
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- . (empty($primary)
- ? ''
- : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( '
- : ', ')
- . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ');' : '');
- break;
-
- case 'index_fld':
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- . ' ADD INDEX( '
- : ', ')
- . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ');' : '');
- break;
-
- case 'unique_fld':
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- . ' ADD UNIQUE( '
- : ', ')
- . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ');' : '');
- break;
-
- case 'spatial_fld':
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- . ' ADD SPATIAL( '
- : ', ')
- . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ');' : '');
- break;
-
- case 'fulltext_fld':
- $sql_query .= (empty($sql_query)
- ? 'ALTER TABLE ' . Util::backquote($table)
- . ' ADD FULLTEXT( '
- : ', ')
- . Util::backquote($selected[$i])
- . (($i == $selected_cnt-1) ? ');' : '');
- break;
-
- case 'add_prefix_tbl':
- $newtablename = $_POST['add_prefix'] . $selected[$i];
- // ADD PREFIX TO TABLE NAME
- $a_query = 'ALTER TABLE '
- . Util::backquote($selected[$i])
- . ' RENAME '
- . Util::backquote($newtablename);
- $run_parts = true;
- break;
-
- case 'replace_prefix_tbl':
- $current = $selected[$i];
- $subFromPrefix = mb_substr(
- $current,
- 0,
- mb_strlen($from_prefix)
- );
- if ($subFromPrefix == $from_prefix) {
- $newtablename = $to_prefix
- . mb_substr(
- $current,
- mb_strlen($from_prefix)
- );
- } else {
- $newtablename = $current;
- }
- // CHANGE PREFIX PATTERN
- $a_query = 'ALTER TABLE '
- . Util::backquote($selected[$i])
- . ' RENAME '
- . Util::backquote($newtablename);
- $run_parts = true;
- break;
-
- case 'copy_tbl_change_prefix':
- $run_parts = true;
- $copy_tbl = true;
-
- $current = $selected[$i];
- $newtablename = $to_prefix .
- mb_substr($current, mb_strlen($from_prefix));
-
- // COPY TABLE AND CHANGE PREFIX PATTERN
- Table::moveCopy(
- $db, $current, $db, $newtablename,
- 'data', false, 'one_table'
- );
- break;
-
- case 'copy_tbl':
- $run_parts = true;
- $copy_tbl = true;
- Table::moveCopy($db, $selected[$i], $_POST['target_db'], $selected[$i], $_POST['what'], false, 'one_table');
- if (isset($_POST['adjust_privileges']) && !empty($_POST['adjust_privileges'])) {
- Operations::adjustPrivilegesCopyTable($db, $selected[$i], $_POST['target_db'], $selected[$i]);
- }
- break;
- } // end switch
-
- // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
- // statements will be run at once below
- if ($run_parts && !$copy_tbl) {
- $sql_query .= $a_query . ';' . "\n";
- if ($query_type != 'drop_db') {
- $GLOBALS['dbi']->selectDb($db);
- }
- $result = $GLOBALS['dbi']->query($a_query);
-
- if ($query_type == 'drop_db') {
- Transformations::clear($selected[$i]);
- } elseif ($query_type == 'drop_tbl') {
- Transformations::clear($db, $selected[$i]);
- } else if ($query_type == 'drop_fld') {
- Transformations::clear($db, $table, $selected[$i]);
- }
- } // end if
- } // end for
-
- if ($deletes && ! empty($_REQUEST['pos'])) {
- $_REQUEST['pos'] = Sql::calculatePosForLastPage(
- $db, $table, isset($_REQUEST['pos']) ? $_REQUEST['pos'] : null
- );
- }
-
- return array(
- $result, $rebuild_database_list, $reload,
- $run_parts, $execute_query_later, $sql_query, $sql_query_views
- );
-}
-
-/**
- * Gets HTML for copy tables form
- *
- * @param string $action action type
- * @param array $_url_params URL params
- *
- * @return string
- */
-function PMA_getHtmlForCopyMultipleTables($action, $_url_params)
-{
- $html = '';
- return $html;
-}
-
-/**
- * Gets HTML for replace_prefix_tbl or copy_tbl_change_prefix
- *
- * @param string $action action type
- * @param array $_url_params URL params
- *
- * @return string
- */
-function PMA_getHtmlForReplacePrefixTable($action, $_url_params)
-{
- $html = '';
-
- return $html;
-}
-
-/**
- * Gets HTML for add_prefix_tbl
- *
- * @param string $action action type
- * @param array $_url_params URL params
- *
- * @return string
- */
-function PMA_getHtmlForAddPrefixTable($action, $_url_params)
-{
- $html = '';
-
- return $html;
-}
-
-/**
- * Gets HTML for other mult_submits actions
- *
- * @param string $what mult_submit type
- * @param string $action action type
- * @param array $_url_params URL params
- * @param string $full_query full sql query string
- *
- * @return string
- */
-function PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
-{
- $html = '';
-
- return $html;
-}
-
-/**
- * Get query string from Selected
- *
- * @param string $what mult_submit type
- * @param string $table table name
- * @param array $selected the selected columns
- * @param array $views table views
- *
- * @return array
- */
-function PMA_getQueryFromSelected($what, $table, $selected, $views)
-{
- $reload = false;
- $full_query_views = null;
- $full_query = '';
-
- if ($what == 'drop_tbl') {
- $full_query_views = '';
- }
-
- $selected_cnt = count($selected);
- $i = 0;
- foreach ($selected as $sval) {
- switch ($what) {
- case 'row_delete':
- $full_query .= 'DELETE FROM '
- . Util::backquote(htmlspecialchars($table))
- // Do not append a "LIMIT 1" clause here
- // (it's not binlog friendly).
- // We don't need the clause because the calling panel permits
- // this feature only when there is a unique index.
- . ' WHERE ' . htmlspecialchars($sval)
- . '; ';
- break;
- case 'drop_db':
- $full_query .= 'DROP DATABASE '
- . Util::backquote(htmlspecialchars($sval))
- . '; ';
- $reload = true;
- break;
-
- case 'drop_tbl':
- $current = $sval;
- if (!empty($views) && in_array($current, $views)) {
- $full_query_views .= (empty($full_query_views) ? 'DROP VIEW ' : ', ')
- . Util::backquote(htmlspecialchars($current));
- } else {
- $full_query .= (empty($full_query) ? 'DROP TABLE ' : ', ')
- . Util::backquote(htmlspecialchars($current));
- }
- break;
-
- case 'empty_tbl':
- $full_query .= 'TRUNCATE ';
- $full_query .= Util::backquote(htmlspecialchars($sval))
- . '; ';
- break;
-
- case 'primary_fld':
- if ($full_query == '') {
- $full_query .= 'ALTER TABLE '
- . Util::backquote(htmlspecialchars($table))
- . ' DROP PRIMARY KEY,'
- . ' ADD PRIMARY KEY('
- . ' '
- . Util::backquote(htmlspecialchars($sval))
- . ',';
- } else {
- $full_query .= ' '
- . Util::backquote(htmlspecialchars($sval))
- . ',';
- }
- if ($i == $selected_cnt-1) {
- $full_query = preg_replace('@,$@', '); ', $full_query);
- }
- break;
-
- case 'drop_fld':
- if ($full_query == '') {
- $full_query .= 'ALTER TABLE '
- . Util::backquote(htmlspecialchars($table));
- }
- $full_query .= ' DROP '
- . Util::backquote(htmlspecialchars($sval))
- . ',';
- if ($i == $selected_cnt - 1) {
- $full_query = preg_replace('@,$@', '; ', $full_query);
- }
- break;
- } // end switch
- $i++;
- }
-
- if ($what == 'drop_tbl') {
- if (!empty($full_query)) {
- $full_query .= '; ' . "\n";
- }
- if (!empty($full_query_views)) {
- $full_query .= $full_query_views . '; ' . "\n";
- }
- unset($full_query_views);
- }
-
- $full_query_views = isset($full_query_views)? $full_query_views : null;
-
- return array($full_query, $reload, $full_query_views);
-}
diff --git a/test/libraries/PMA_mult_submits_test.php b/test/classes/MultSubmitsTest.php
similarity index 88%
rename from test/libraries/PMA_mult_submits_test.php
rename to test/classes/MultSubmitsTest.php
index b80b2fd243..3266ef3b39 100644
--- a/test/libraries/PMA_mult_submits_test.php
+++ b/test/classes/MultSubmitsTest.php
@@ -1,28 +1,26 @@
'PMA_original_url_query');
//Call the test function
- $html = PMA_getHtmlForReplacePrefixTable($action, $_url_params);
+ $html = MultSubmits::getHtmlForReplacePrefixTable($action, $_url_params);
//form action
$this->assertContains(
@@ -103,7 +101,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_getHtmlForAddPrefixTable
+ * Test for MultSubmits::getHtmlForAddPrefixTable
*
* @return void
*/
@@ -113,7 +111,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
$_url_params = array('url_query'=>'PMA_original_url_query');
//Call the test function
- $html = PMA_getHtmlForAddPrefixTable($action, $_url_params);
+ $html = MultSubmits::getHtmlForAddPrefixTable($action, $_url_params);
//form action
$this->assertContains(
@@ -133,7 +131,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_getHtmlForOtherActions
+ * Test for MultSubmits::getHtmlForOtherActions
*
* @return void
*/
@@ -145,7 +143,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
$full_query = 'select column from PMA_table';
//Call the test function
- $html = PMA_getHtmlForOtherActions(
+ $html = MultSubmits::getHtmlForOtherActions(
$what, $action, $_url_params, $full_query
);
@@ -181,7 +179,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_getUrlParams
+ * Test for MultSubmits::getUrlParams
*
* @return void
*/
@@ -199,7 +197,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
$original_sql_query = "original_sql_query";
$original_url_query = "original_url_query";
- $_url_params = PMA_getUrlParams(
+ $_url_params = MultSubmits::getUrlParams(
$what, $reload, $action, $db, $table, $selected, $views,
$original_sql_query, $original_url_query
);
@@ -226,7 +224,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_buildOrExecuteQueryForMulti
+ * Test for MultSubmits::buildOrExecuteQueryForMulti
*
* @return void
*/
@@ -250,7 +248,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
list(
$result, $rebuild_database_list, $reload_ret,
$run_parts, $execute_query_later,,
- ) = PMA_buildOrExecuteQueryForMulti(
+ ) = MultSubmits::buildOrExecuteQueryForMulti(
$query_type, $selected, $db, $table, $views,
$primary, $from_prefix, $to_prefix
);
@@ -282,7 +280,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
$query_type = 'analyze_tbl';
list(
,,,, $execute_query_later,,
- ) = PMA_buildOrExecuteQueryForMulti(
+ ) = MultSubmits::buildOrExecuteQueryForMulti(
$query_type, $selected, $db, $table, $views,
$primary, $from_prefix, $to_prefix
);
@@ -295,7 +293,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_getQueryFromSelected
+ * Test for MultSubmits::getQueryFromSelected
*
* @return void
*/
@@ -311,7 +309,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
);
list($full_query, $reload, $full_query_views)
- = PMA_getQueryFromSelected(
+ = MultSubmits::getQueryFromSelected(
$what, $table, $selected, $views
);
@@ -336,7 +334,7 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
$what = "drop_db";
list($full_query, $reload, $full_query_views)
- = PMA_getQueryFromSelected(
+ = MultSubmits::getQueryFromSelected(
$what, $table, $selected, $views
);
From 9ecdd9c80ae5c9865e8e79e0802052d6d391e34f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 12:53:20 -0300
Subject: [PATCH 05/11] Rename libraries/mysql_relations.lib.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Rename libraries/mysql_relations.lib.php to libraries/mysql_relations.inc.php
Signed-off-by: Maurício Meneghini Fauth
---
libraries/classes/Relation.php | 2 +-
libraries/{mysql_relations.lib.php => mysql_relations.inc.php} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename libraries/{mysql_relations.lib.php => mysql_relations.inc.php} (100%)
diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php
index d7461da935..416f089db3 100644
--- a/libraries/classes/Relation.php
+++ b/libraries/classes/Relation.php
@@ -810,7 +810,7 @@ class Relation
include_once './libraries/information_schema_relations.inc.php';
} else {
$relations_key = 'mysql_relations';
- include_once './libraries/mysql_relations.lib.php';
+ include_once './libraries/mysql_relations.inc.php';
}
if (isset($GLOBALS[$relations_key][$table])) {
foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
diff --git a/libraries/mysql_relations.lib.php b/libraries/mysql_relations.inc.php
similarity index 100%
rename from libraries/mysql_relations.lib.php
rename to libraries/mysql_relations.inc.php
From 1354b45b128051c0c54a26f4f21cb7485f958350 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 16:51:21 -0300
Subject: [PATCH 06/11] Refactor parse_analyze function to static method
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
db_multi_table_query.php | 6 +-
import.php | 8 +-
.../Table/TableStructureController.php | 4 +-
libraries/classes/ParseAnalyze.php | 78 +++++++++++++++++++
libraries/classes/Sql.php | 9 +--
libraries/parse_analyze.lib.php | 71 -----------------
sql.php | 4 +-
7 files changed, 91 insertions(+), 89 deletions(-)
create mode 100644 libraries/classes/ParseAnalyze.php
delete mode 100644 libraries/parse_analyze.lib.php
diff --git a/db_multi_table_query.php b/db_multi_table_query.php
index 0832462107..0df0ef445e 100644
--- a/db_multi_table_query.php
+++ b/db_multi_table_query.php
@@ -5,8 +5,9 @@
*
* @package PhpMyAdmin
*/
-use PhpMyAdmin\Response;
use PhpMyAdmin\DbMultiTableQuery;
+use PhpMyAdmin\ParseAnalyze;
+use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
require_once 'libraries/common.inc.php';
@@ -14,12 +15,11 @@ require_once 'libraries/common.inc.php';
if (isset($_REQUEST['sql_query'])) {
$sql_query = $_REQUEST['sql_query'];
$db = $_REQUEST['db'];
- include_once 'libraries/parse_analyze.lib.php';
list(
$analyzed_sql_results,
$db,
$table_from_sql
- ) = PMA_parseAnalyze($sql_query, $db);
+ ) = ParseAnalyze::sqlQuery($sql_query, $db);
extract($analyzed_sql_results);
$goto = 'db_multi_table_query.php';
diff --git a/import.php b/import.php
index 65780c1d34..3e462d983d 100644
--- a/import.php
+++ b/import.php
@@ -11,6 +11,7 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\File;
use PhpMyAdmin\Import;
+use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
@@ -637,13 +638,11 @@ if (isset($message)) {
// can choke on it so avoid parsing)
$sqlLength = mb_strlen($sql_query);
if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
- include_once 'libraries/parse_analyze.lib.php';
-
list(
$analyzed_sql_results,
$db,
$table_from_sql
- ) = PMA_parseAnalyze($sql_query, $db);
+ ) = ParseAnalyze::sqlQuery($sql_query, $db);
// @todo: possibly refactor
extract($analyzed_sql_results);
@@ -675,12 +674,11 @@ if ($go_sql) {
foreach ($sql_queries as $sql_query) {
// parse sql query
- include_once 'libraries/parse_analyze.lib.php';
list(
$analyzed_sql_results,
$db,
$table_from_sql
- ) = PMA_parseAnalyze($sql_query, $db);
+ ) = ParseAnalyze::sqlQuery($sql_query, $db);
// @todo: possibly refactor
extract($analyzed_sql_results);
diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php
index 3f85a95791..1a8fa69b75 100644
--- a/libraries/classes/Controllers/Table/TableStructureController.php
+++ b/libraries/classes/Controllers/Table/TableStructureController.php
@@ -14,6 +14,7 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\CreateAddField;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
+use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Sql;
use PhpMyAdmin\SqlParser\Context;
@@ -793,11 +794,10 @@ class TableStructureController extends TableController
// Parse and analyze the query
$db = &$this->db;
- include_once 'libraries/parse_analyze.lib.php';
list(
$analyzed_sql_results,
$db,
- ) = PMA_parseAnalyze($sql_query, $db);
+ ) = ParseAnalyze::sqlQuery($sql_query, $db);
// @todo: possibly refactor
extract($analyzed_sql_results);
diff --git a/libraries/classes/ParseAnalyze.php b/libraries/classes/ParseAnalyze.php
new file mode 100644
index 0000000000..c30af3e2c6
--- /dev/null
+++ b/libraries/classes/ParseAnalyze.php
@@ -0,0 +1,78 @@
+ 1) {
+
+ /**
+ * @todo if there are more than one table name in the Select:
+ * - do not extract the first table name
+ * - do not show a table name in the page header
+ * - do not display the sub-pages links)
+ */
+ $table = '';
+ } else {
+ $table = $analyzed_sql_results['select_tables'][0][0];
+ if (!empty($analyzed_sql_results['select_tables'][0][1])) {
+ $db = $analyzed_sql_results['select_tables'][0][1];
+ }
+ }
+ // There is no point checking if a reload is required if we already decided
+ // to reload. Also, no reload is required for AJAX requests.
+ $response = Response::getInstance();
+ if (empty($reload) && ! $response->isAjax()) {
+ // NOTE: Database names are case-insensitive.
+ $reload = strcasecmp($db, $prev_db) != 0;
+ }
+
+ // Updating the array.
+ $analyzed_sql_results['reload'] = $reload;
+ }
+
+ return array($analyzed_sql_results, $db, $table);
+ }
+}
diff --git a/libraries/classes/Sql.php b/libraries/classes/Sql.php
index 3d22d456d8..1272a7571d 100644
--- a/libraries/classes/Sql.php
+++ b/libraries/classes/Sql.php
@@ -14,6 +14,7 @@ use PhpMyAdmin\Display\Results as DisplayResults;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;
+use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlParser\Statements\AlterStatement;
@@ -45,10 +46,7 @@ class Sql
if (($db === null) && (!empty($GLOBALS['db']))) {
$db = $GLOBALS['db'];
}
-
- include_once 'libraries/parse_analyze.lib.php';
- list($analyzed_sql_results,,) = PMA_parseAnalyze($sql_query, $db);
-
+ list($analyzed_sql_results,,) = ParseAnalyze::sqlQuery($sql_query, $db);
return $analyzed_sql_results;
}
@@ -2064,12 +2062,11 @@ EOT;
) {
if ($analyzed_sql_results == null) {
// Parse and analyze the query
- include_once 'libraries/parse_analyze.lib.php';
list(
$analyzed_sql_results,
$db,
$table_from_sql
- ) = PMA_parseAnalyze($sql_query, $db);
+ ) = ParseAnalyze::sqlQuery($sql_query, $db);
// @todo: possibly refactor
extract($analyzed_sql_results);
diff --git a/libraries/parse_analyze.lib.php b/libraries/parse_analyze.lib.php
deleted file mode 100644
index b45f3a6334..0000000000
--- a/libraries/parse_analyze.lib.php
+++ /dev/null
@@ -1,71 +0,0 @@
- 1) {
-
- /**
- * @todo if there are more than one table name in the Select:
- * - do not extract the first table name
- * - do not show a table name in the page header
- * - do not display the sub-pages links)
- */
- $table = '';
- } else {
- $table = $analyzed_sql_results['select_tables'][0][0];
- if (!empty($analyzed_sql_results['select_tables'][0][1])) {
- $db = $analyzed_sql_results['select_tables'][0][1];
- }
- }
- // There is no point checking if a reload is required if we already decided
- // to reload. Also, no reload is required for AJAX requests.
- $response = Response::getInstance();
- if (empty($reload) && ! $response->isAjax()) {
- // NOTE: Database names are case-insensitive.
- $reload = strcasecmp($db, $prev_db) != 0;
- }
-
- // Updating the array.
- $analyzed_sql_results['reload'] = $reload;
- }
-
- return array($analyzed_sql_results, $db, $table);
-}
diff --git a/sql.php b/sql.php
index 7867577f52..c441b7d81c 100644
--- a/sql.php
+++ b/sql.php
@@ -8,6 +8,7 @@
* @package PhpMyAdmin
*/
use PhpMyAdmin\Config\PageSettings;
+use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Url;
@@ -130,12 +131,11 @@ if (empty($sql_query) && strlen($table) > 0 && strlen($db) > 0) {
/**
* Parse and analyze the query
*/
-require_once 'libraries/parse_analyze.lib.php';
list(
$analyzed_sql_results,
$db,
$table_from_sql
-) = PMA_parseAnalyze($sql_query, $db);
+) = ParseAnalyze::sqlQuery($sql_query, $db);
// @todo: possibly refactor
extract($analyzed_sql_results);
From 700e081833dd7cd1b1669412ddf1c2e135ade0a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 17:36:39 -0300
Subject: [PATCH 07/11] Refactor plugin_interface functions to static methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
db_designer.php | 1 -
db_operations.php | 4 +-
export.php | 4 +-
import.php | 5 +-
libraries/classes/Database/Designer.php | 3 +-
libraries/classes/Display/Export.php | 9 +-
libraries/classes/Display/Import.php | 14 +-
libraries/classes/File.php | 12 -
libraries/classes/Plugins.php | 584 ++++++++++++++++++
.../Plugins/Schema/Svg/SvgRelationSchema.php | 2 +-
libraries/classes/Table.php | 8 +-
libraries/classes/Tracker.php | 6 +-
libraries/plugin_interface.lib.php | 583 -----------------
schema_export.php | 4 +-
.../database/designer/schema_export.phtml | 4 +-
test/classes/Database/DesignerTest.php | 5 -
test/classes/Display/ExportTest.php | 5 +-
17 files changed, 616 insertions(+), 637 deletions(-)
create mode 100644 libraries/classes/Plugins.php
delete mode 100644 libraries/plugin_interface.lib.php
diff --git a/db_designer.php b/db_designer.php
index d199fdf1a1..ceb4f89ed6 100644
--- a/db_designer.php
+++ b/db_designer.php
@@ -22,7 +22,6 @@ if (isset($_REQUEST['dialog'])) {
} else if ($_REQUEST['dialog'] == 'save_as') {
$html = Designer::getHtmlForPageSaveAs($GLOBALS['db']);
} else if ($_REQUEST['dialog'] == 'export') {
- include_once 'libraries/plugin_interface.lib.php';
$html = Designer::getHtmlForSchemaExport(
$GLOBALS['db'], $_REQUEST['selected_page']
);
diff --git a/db_operations.php b/db_operations.php
index 63d0123bbf..c13e0d343e 100644
--- a/db_operations.php
+++ b/db_operations.php
@@ -15,6 +15,7 @@ use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Display\CreateTable;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
@@ -75,10 +76,9 @@ if (strlen($GLOBALS['db']) > 0
$tables_full = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']);
- include_once "libraries/plugin_interface.lib.php";
// remove all foreign key constraints, otherwise we can get errors
/* @var $export_sql_plugin ExportSql */
- $export_sql_plugin = PMA_getPlugin(
+ $export_sql_plugin = Plugins::getPlugin(
"export",
"sql",
'libraries/classes/Plugins/Export/',
diff --git a/export.php b/export.php
index 88b481989b..1c2fb68f84 100644
--- a/export.php
+++ b/export.php
@@ -9,6 +9,7 @@
use PhpMyAdmin\Core;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Export;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Sanitize;
@@ -26,7 +27,6 @@ if (isset($_POST['output_format']) && $_POST['output_format'] == 'sendit') {
define('PMA_BYPASS_GET_INSTANCE', 1);
}
include_once 'libraries/common.inc.php';
-include_once 'libraries/plugin_interface.lib.php';
//check if it's the GET request to check export time out
if (isset($_GET['check_time_out'])) {
@@ -181,7 +181,7 @@ $what = Core::securePath($_POST['what']);
// export class instance, not array of properties, as before
/* @var $export_plugin ExportPlugin */
-$export_plugin = PMA_getPlugin(
+$export_plugin = Plugins::getPlugin(
"export",
$what,
'libraries/classes/Plugins/Export/',
diff --git a/import.php b/import.php
index 3e462d983d..1e00db8e1b 100644
--- a/import.php
+++ b/import.php
@@ -12,6 +12,7 @@ use PhpMyAdmin\Encoding;
use PhpMyAdmin\File;
use PhpMyAdmin\Import;
use PhpMyAdmin\ParseAnalyze;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
@@ -515,10 +516,8 @@ if (! $error && isset($_POST['skip'])) {
$sql_data = array('valid_sql' => array(), 'valid_queries' => 0);
if (! $error) {
- // Check for file existence
- include_once "libraries/plugin_interface.lib.php";
/* @var $import_plugin ImportPlugin */
- $import_plugin = PMA_getPlugin(
+ $import_plugin = Plugins::getPlugin(
"import",
$format,
'libraries/classes/Plugins/Import/',
diff --git a/libraries/classes/Database/Designer.php b/libraries/classes/Database/Designer.php
index e290c95d56..763ae5ae3c 100644
--- a/libraries/classes/Database/Designer.php
+++ b/libraries/classes/Database/Designer.php
@@ -9,6 +9,7 @@ namespace PhpMyAdmin\Database;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Message;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\SchemaPlugin;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Template;
@@ -114,7 +115,7 @@ class Designer
{
/* Scan for schema plugins */
/* @var $export_list SchemaPlugin[] */
- $export_list = PMA_getPlugins(
+ $export_list = Plugins::getPlugins(
"schema",
'libraries/classes/Plugins/Schema/',
null
diff --git a/libraries/classes/Display/Export.php b/libraries/classes/Display/Export.php
index 48414bb696..6bef98947b 100644
--- a/libraries/classes/Display/Export.php
+++ b/libraries/classes/Display/Export.php
@@ -10,6 +10,7 @@ namespace PhpMyAdmin\Display;
use PhpMyAdmin\Core;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Message;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
@@ -371,7 +372,7 @@ class Export
{
$html = '';
$html .= '
' . __('Format:') . ' ';
- $html .= PMA_pluginGetChoice('Export', 'what', $export_list, 'format');
+ $html .= Plugins::getChoice('Export', 'what', $export_list, 'format');
$html .= '
';
return $html;
}
@@ -393,7 +394,7 @@ class Export
. 'and ignore the options for other formats.'
);
$html .= '';
- $html .= PMA_pluginGetOptions('Export', $export_list);
+ $html .= Plugins::getOptions('Export', $export_list);
$html .= '';
if (Encoding::canConvertKanji()) {
@@ -1002,11 +1003,9 @@ class Export
$GLOBALS['single_table'] = $_REQUEST['single_table'];
}
- include_once './libraries/plugin_interface.lib.php';
-
/* Scan for plugins */
/* @var $export_list ExportPlugin[] */
- $export_list = PMA_getPlugins(
+ $export_list = Plugins::getPlugins(
"export",
'libraries/classes/Plugins/Export/',
array(
diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php
index 17afb49e53..3fcbf21890 100644
--- a/libraries/classes/Display/Import.php
+++ b/libraries/classes/Display/Import.php
@@ -12,6 +12,7 @@ use PhpMyAdmin\Core;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Message;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Url;
@@ -308,7 +309,7 @@ class Import
$html .= ' ';
$html .= ' ';
+ . Plugins::checkboxCheck('Import', 'allow_interrupt') . '/>';
$html .= ' '
. __(
'Allow the interruption of an import in case the script detects '
@@ -325,7 +326,7 @@ class Import
)
. ' ';
$html .= ' ';
$html .= '
';
@@ -334,7 +335,7 @@ class Import
// do not show the Skip dialog to avoid the risk of someone
// entering a value here that would interfere with "skip"
$html .= ' ';
}
@@ -371,7 +372,7 @@ class Import
{
$html = ' ';
$html .= '
' . __('Format:') . ' ';
- $html .= PMA_pluginGetChoice('Import', 'format', $import_list);
+ $html .= Plugins::getChoice('Import', 'format', $import_list);
$html .= '
';
$html .= '
';
@@ -380,7 +381,7 @@ class Import
$html .= ' '
. 'Scroll down to fill in the options for the selected format '
. 'and ignore the options for other formats.
';
- $html .= PMA_pluginGetOptions('Import', $import_list);
+ $html .= Plugins::getOptions('Import', $import_list);
$html .= ' ';
$html .= '
';
@@ -650,7 +651,6 @@ class Import
public static function getImportDisplay($import_type, $db, $table, $max_upload_size)
{
global $SESSION_KEY;
- include_once './libraries/plugin_interface.lib.php';
list(
$SESSION_KEY,
@@ -659,7 +659,7 @@ class Import
/* Scan for plugins */
/* @var $import_list ImportPlugin[] */
- $import_list = PMA_getPlugins(
+ $import_list = Plugins::getPlugins(
"import",
'libraries/classes/Plugins/Import/',
$import_type
diff --git a/libraries/classes/File.php b/libraries/classes/File.php
index a7ca8a195d..9624a09317 100644
--- a/libraries/classes/File.php
+++ b/libraries/classes/File.php
@@ -547,18 +547,6 @@ class File
return false;
}
- /**
- * @todo
- * get registered plugins for file compression
-
- foreach (PMA_getPlugins($type = 'compression') as $plugin) {
- if ($plugin['classname']::canHandle($this->getName())) {
- $this->setCompressionPlugin($plugin);
- break;
- }
- }
- */
-
$this->_compression = Util::getCompressionMimeType($file);
return $this->_compression;
}
diff --git a/libraries/classes/Plugins.php b/libraries/classes/Plugins.php
new file mode 100644
index 0000000000..a9569ecd61
--- /dev/null
+++ b/libraries/classes/Plugins.php
@@ -0,0 +1,584 @@
+getProperties()) {
+ $plugin_list[] = $plugin;
+ }
+ }
+ }
+ }
+
+ usort($plugin_list, function($cmp_name_1, $cmp_name_2) {
+ return strcasecmp(
+ $cmp_name_1->getProperties()->getText(),
+ $cmp_name_2->getProperties()->getText()
+ );
+ });
+ return $plugin_list;
+ }
+
+ /**
+ * Returns locale string for $name or $name if no locale is found
+ *
+ * @param string $name for local string
+ *
+ * @return string locale string for $name
+ */
+ public static function getString($name)
+ {
+ return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
+ }
+
+ /**
+ * Returns html input tag option 'checked' if plugin $opt
+ * should be set by config or request
+ *
+ * @param string $section name of config section in
+ * $GLOBALS['cfg'][$section] for plugin
+ * @param string $opt name of option
+ *
+ * @return string html input tag option 'checked'
+ */
+ public static function checkboxCheck($section, $opt)
+ {
+ // If the form is being repopulated using $_GET data, that is priority
+ if (isset($_GET[$opt])
+ || ! isset($_GET['repopulate'])
+ && ((! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt]))
+ || ! empty($GLOBALS['cfg'][$section][$opt]))
+ ) {
+ return ' checked="checked"';
+ }
+ return '';
+ }
+
+ /**
+ * Returns default value for option $opt
+ *
+ * @param string $section name of config section in
+ * $GLOBALS['cfg'][$section] for plugin
+ * @param string $opt name of option
+ *
+ * @return string default value for option $opt
+ */
+ public static function getDefault($section, $opt)
+ {
+ if (isset($_GET[$opt])) {
+ // If the form is being repopulated using $_GET data, that is priority
+ return htmlspecialchars($_GET[$opt]);
+ }
+
+ if (isset($GLOBALS['timeout_passed'])
+ && $GLOBALS['timeout_passed']
+ && isset($_REQUEST[$opt])
+ ) {
+ return htmlspecialchars($_REQUEST[$opt]);
+ }
+
+ if (!isset($GLOBALS['cfg'][$section][$opt])) {
+ return '';
+ }
+
+ $matches = array();
+ /* Possibly replace localised texts */
+ if (!preg_match_all(
+ '/(str[A-Z][A-Za-z0-9]*)/',
+ $GLOBALS['cfg'][$section][$opt],
+ $matches
+ )) {
+ return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
+ }
+
+ $val = $GLOBALS['cfg'][$section][$opt];
+ foreach ($matches[0] as $match) {
+ if (isset($GLOBALS[$match])) {
+ $val = str_replace($match, $GLOBALS[$match], $val);
+ }
+ }
+ return htmlspecialchars($val);
+ }
+
+ /**
+ * Returns html select form element for plugin choice
+ * and hidden fields denoting whether each plugin must be exported as a file
+ *
+ * @param string $section name of config section in
+ * $GLOBALS['cfg'][$section] for plugin
+ * @param string $name name of select element
+ * @param array &$list array with plugin instances
+ * @param string $cfgname name of config value, if none same as $name
+ *
+ * @return string html select tag
+ */
+ public static function getChoice($section, $name, &$list, $cfgname = null)
+ {
+ if (! isset($cfgname)) {
+ $cfgname = $name;
+ }
+ $ret = '';
+ $default = self::getDefault($section, $cfgname);
+ $hidden = null;
+ foreach ($list as $plugin) {
+ $elem = explode('\\', get_class($plugin));
+ $plugin_name = array_pop($elem);
+ unset($elem);
+ $plugin_name = mb_strtolower(
+ mb_substr(
+ $plugin_name,
+ mb_strlen($section)
+ )
+ );
+ $ret .= 'getProperties();
+ $text = null;
+ if ($properties != null) {
+ $text = $properties->getText();
+ }
+ $ret .= ' value="' . $plugin_name . '">'
+ . self::getString($text)
+ . ' ' . "\n";
+
+ // Whether each plugin has to be saved as a file
+ $hidden .= ' ' . "\n";
+ }
+ $ret .= ' ' . "\n" . $hidden;
+
+ return $ret;
+ }
+
+ /**
+ * Returns single option in a list element
+ *
+ * @param string $section name of config section in $GLOBALS['cfg'][$section] for plugin
+ * @param string $plugin_name unique plugin name
+ * @param array|\PhpMyAdmin\Properties\PropertyItem &$propertyGroup options property main group instance
+ * @param boolean $is_subgroup if this group is a subgroup
+ *
+ * @return string table row with option
+ */
+ public static function getOneOption(
+ $section,
+ $plugin_name,
+ &$propertyGroup,
+ $is_subgroup = false
+ ) {
+ $ret = "\n";
+
+ if (! $is_subgroup) {
+ // for subgroup headers
+ if (mb_strpos(get_class($propertyGroup), "PropertyItem")) {
+ $properties = array($propertyGroup);
+ } else {
+ // for main groups
+ $ret .= '';
+
+ if (method_exists($propertyGroup, 'getText')) {
+ $text = $propertyGroup->getText();
+ }
+
+ if ($text != null) {
+ $ret .= '
' . self::getString($text) . ' ';
+ }
+ $ret .= '
';
+ }
+ }
+
+ if (! isset($properties)) {
+ $not_subgroup_header = true;
+ if (method_exists($propertyGroup, 'getProperties')) {
+ $properties = $propertyGroup->getProperties();
+ }
+ }
+
+ if (isset($properties)) {
+ /** @var OptionsPropertySubgroup $propertyItem */
+ foreach ($properties as $propertyItem) {
+ $property_class = get_class($propertyItem);
+ // if the property is a subgroup, we deal with it recursively
+ if (mb_strpos($property_class, "Subgroup")) {
+ // for subgroups
+ // each subgroup can have a header, which may also be a form element
+ /** @var OptionsPropertyItem $subgroup_header */
+ $subgroup_header = $propertyItem->getSubgroupHeader();
+ if (isset($subgroup_header)) {
+ $ret .= self::getOneOption(
+ $section,
+ $plugin_name,
+ $subgroup_header
+ );
+ }
+
+ $ret .= 'getName() . '">';
+ } else {
+ $ret .= '>';
+ }
+
+ $ret .= self::getOneOption(
+ $section,
+ $plugin_name,
+ $propertyItem,
+ true
+ );
+ continue;
+ }
+
+ // single property item
+ $ret .= self::getHtmlForProperty(
+ $section, $plugin_name, $propertyItem
+ );
+ }
+ }
+
+ if ($is_subgroup) {
+ // end subgroup
+ $ret .= ' ';
+ } else {
+ // end main group
+ if (! empty($not_subgroup_header)) {
+ $ret .= ' ';
+ }
+ }
+
+ if (method_exists($propertyGroup, "getDoc")) {
+ $doc = $propertyGroup->getDoc();
+ if ($doc != null) {
+ if (count($doc) == 3) {
+ $ret .= PhpMyAdmin\Util::showMySQLDocu(
+ $doc[1],
+ false,
+ $doc[2]
+ );
+ } elseif (count($doc) == 1) {
+ $ret .= PhpMyAdmin\Util::showDocu('faq', $doc[0]);
+ } else {
+ $ret .= PhpMyAdmin\Util::showMySQLDocu(
+ $doc[1]
+ );
+ }
+ }
+ }
+
+ // Close the list element after $doc link is displayed
+ if (isset($property_class)) {
+ if ($property_class == 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem'
+ || $property_class == 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem'
+ || $property_class == 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem'
+ || $property_class == 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem'
+ ) {
+ $ret .= '';
+ }
+ }
+ $ret .= "\n";
+ return $ret;
+ }
+
+ /**
+ * Get HTML for properties items
+ *
+ * @param string $section name of config section in
+ * $GLOBALS['cfg'][$section] for plugin
+ * @param string $plugin_name unique plugin name
+ * @param OptionsPropertyItem $propertyItem Property item
+ *
+ * @return string
+ */
+ public static function getHtmlForProperty(
+ $section, $plugin_name, $propertyItem
+ ) {
+ $ret = null;
+ $property_class = get_class($propertyItem);
+ switch ($property_class) {
+ case 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem':
+ $ret .= '' . "\n";
+ $ret .= ' getName()
+ );
+
+ if ($propertyItem->getForce() != null) {
+ // Same code is also few lines lower, update both if needed
+ $ret .= ' onclick="if (!this.checked && '
+ . '(!document.getElementById(\'checkbox_' . $plugin_name
+ . '_' . $propertyItem->getForce() . '\') '
+ . '|| !document.getElementById(\'checkbox_'
+ . $plugin_name . '_' . $propertyItem->getForce()
+ . '\').checked)) '
+ . 'return false; else return true;"';
+ }
+ $ret .= ' />';
+ $ret .= ''
+ . self::getString($propertyItem->getText()) . ' ';
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem':
+ echo 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem';
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem':
+ $ret .= ' ';
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem':
+ $ret .= '' . "\n";
+ $ret .= '' . self::getString($propertyItem->getText()) . '
';
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\RadioPropertyItem':
+ $default = self::getDefault(
+ $section,
+ $plugin_name . '_' . $propertyItem->getName()
+ );
+ foreach ($propertyItem->getValues() as $key => $val) {
+ $ret .= ' '
+ . self::getString($val) . ' ';
+ }
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem':
+ $ret .= '' . "\n";
+ $ret .= ''
+ . self::getString($propertyItem->getText()) . ' ';
+ $ret .= '';
+ $default = self::getDefault(
+ $section,
+ $plugin_name . '_' . $propertyItem->getName()
+ );
+ foreach ($propertyItem->getValues() as $key => $val) {
+ $ret .= '';
+ }
+ $ret .= ' ';
+ break;
+ case 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem':
+ case 'PhpMyAdmin\Properties\Options\Items\NumberPropertyItem':
+ $ret .= ' ' . "\n";
+ $ret .= ''
+ . self::getString($propertyItem->getText()) . ' ';
+ $ret .= ' getSize() != null
+ ? ' size="' . $propertyItem->getSize() . '"'
+ : '')
+ . ($propertyItem->getLen() != null
+ ? ' maxlength="' . $propertyItem->getLen() . '"'
+ : '')
+ . ' />';
+ break;
+ default:
+ break;
+ }
+ return $ret;
+ }
+
+ /**
+ * Returns html div with editable options for plugin
+ *
+ * @param string $section name of config section in $GLOBALS['cfg'][$section]
+ * @param array &$list array with plugin instances
+ *
+ * @return string html fieldset with plugin options
+ */
+ public static function getOptions($section, &$list)
+ {
+ $ret = '';
+ // Options for plugins that support them
+ foreach ($list as $plugin) {
+ $properties = $plugin->getProperties();
+ if ($properties != null) {
+ $text = $properties->getText();
+ $options = $properties->getOptions();
+ }
+
+ $elem = explode('\\', get_class($plugin));
+ $plugin_name = array_pop($elem);
+ unset($elem);
+ $plugin_name = mb_strtolower(
+ mb_substr(
+ $plugin_name,
+ mb_strlen($section)
+ )
+ );
+
+ $ret .= '';
+ }
+ return $ret;
+ }
+}
diff --git a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php
index 5d5231125b..c6918724c7 100644
--- a/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php
+++ b/libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php
@@ -34,7 +34,7 @@ use PhpMyAdmin\Relation;
class SvgRelationSchema extends ExportRelationSchema
{
/**
- * @var \PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia[]|TableStatsEps[]|TableStatsPdf[]|TableStatsSvg[]
+ * @var PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia[]|TableStatsEps[]|TableStatsPdf[]|TableStatsSvg[]
*/
private $_tables = array();
/** @var RelationStatsDia[] Relations */
diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php
index 44d442dddc..ad79f2e193 100644
--- a/libraries/classes/Table.php
+++ b/libraries/classes/Table.php
@@ -10,6 +10,7 @@ namespace PhpMyAdmin;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Relation;
use PhpMyAdmin\SqlParser\Components\Expression;
@@ -908,15 +909,12 @@ class Table
// No table is created when this is a data-only operation.
if ($what != 'dataonly') {
-
- include_once "libraries/plugin_interface.lib.php";
-
/**
* Instance used for exporting the current structure of the table.
*
- * @var \PhpMyAdmin\Plugins\Export\ExportSql
+ * @var PhpMyAdmin\Plugins\Export\ExportSql
*/
- $export_sql_plugin = PMA_getPlugin(
+ $export_sql_plugin = Plugins::getPlugin(
"export",
"sql",
'libraries/classes/Plugins/Export/',
diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php
index ac9c999f79..fa9e8cdf89 100644
--- a/libraries/classes/Tracker.php
+++ b/libraries/classes/Tracker.php
@@ -7,6 +7,7 @@
*/
namespace PhpMyAdmin;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Relation;
use PhpMyAdmin\SqlParser\Parser;
@@ -192,9 +193,8 @@ class Tracker
}
// get Export SQL instance
- include_once "libraries/plugin_interface.lib.php";
- /* @var $export_sql_plugin \PhpMyAdmin\Plugins\Export\ExportSql */
- $export_sql_plugin = PMA_getPlugin(
+ /* @var $export_sql_plugin PhpMyAdmin\Plugins\Export\ExportSql */
+ $export_sql_plugin = Plugins::getPlugin(
"export",
"sql",
'libraries/classes/Plugins/Export/',
diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php
deleted file mode 100644
index add6671665..0000000000
--- a/libraries/plugin_interface.lib.php
+++ /dev/null
@@ -1,583 +0,0 @@
-getProperties()) {
- $plugin_list[] = $plugin;
- }
- }
- }
- }
-
- usort($plugin_list, function($cmp_name_1, $cmp_name_2) {
- return strcasecmp(
- $cmp_name_1->getProperties()->getText(),
- $cmp_name_2->getProperties()->getText()
- );
- });
- return $plugin_list;
-}
-
-/**
- * Returns locale string for $name or $name if no locale is found
- *
- * @param string $name for local string
- *
- * @return string locale string for $name
- */
-function PMA_getString($name)
-{
- return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
-}
-
-/**
- * Returns html input tag option 'checked' if plugin $opt
- * should be set by config or request
- *
- * @param string $section name of config section in
- * $GLOBALS['cfg'][$section] for plugin
- * @param string $opt name of option
- *
- * @return string html input tag option 'checked'
- */
-function PMA_pluginCheckboxCheck($section, $opt)
-{
- // If the form is being repopulated using $_GET data, that is priority
- if (isset($_GET[$opt])
- || ! isset($_GET['repopulate'])
- && ((! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt]))
- || ! empty($GLOBALS['cfg'][$section][$opt]))
- ) {
- return ' checked="checked"';
- }
- return '';
-}
-
-/**
- * Returns default value for option $opt
- *
- * @param string $section name of config section in
- * $GLOBALS['cfg'][$section] for plugin
- * @param string $opt name of option
- *
- * @return string default value for option $opt
- */
-function PMA_pluginGetDefault($section, $opt)
-{
- if (isset($_GET[$opt])) {
- // If the form is being repopulated using $_GET data, that is priority
- return htmlspecialchars($_GET[$opt]);
- }
-
- if (isset($GLOBALS['timeout_passed'])
- && $GLOBALS['timeout_passed']
- && isset($_REQUEST[$opt])
- ) {
- return htmlspecialchars($_REQUEST[$opt]);
- }
-
- if (!isset($GLOBALS['cfg'][$section][$opt])) {
- return '';
- }
-
- $matches = array();
- /* Possibly replace localised texts */
- if (!preg_match_all(
- '/(str[A-Z][A-Za-z0-9]*)/',
- $GLOBALS['cfg'][$section][$opt],
- $matches
- )) {
- return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
- }
-
- $val = $GLOBALS['cfg'][$section][$opt];
- foreach ($matches[0] as $match) {
- if (isset($GLOBALS[$match])) {
- $val = str_replace($match, $GLOBALS[$match], $val);
- }
- }
- return htmlspecialchars($val);
-}
-
-/**
- * Returns html select form element for plugin choice
- * and hidden fields denoting whether each plugin must be exported as a file
- *
- * @param string $section name of config section in
- * $GLOBALS['cfg'][$section] for plugin
- * @param string $name name of select element
- * @param array &$list array with plugin instances
- * @param string $cfgname name of config value, if none same as $name
- *
- * @return string html select tag
- */
-function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null)
-{
- if (! isset($cfgname)) {
- $cfgname = $name;
- }
- $ret = '';
- $default = PMA_pluginGetDefault($section, $cfgname);
- $hidden = null;
- foreach ($list as $plugin) {
- $elem = explode('\\', get_class($plugin));
- $plugin_name = array_pop($elem);
- unset($elem);
- $plugin_name = mb_strtolower(
- mb_substr(
- $plugin_name,
- mb_strlen($section)
- )
- );
- $ret .= 'getProperties();
- $text = null;
- if ($properties != null) {
- $text = $properties->getText();
- }
- $ret .= ' value="' . $plugin_name . '">'
- . PMA_getString($text)
- . ' ' . "\n";
-
- // Whether each plugin has to be saved as a file
- $hidden .= ' ' . "\n";
- }
- $ret .= ' ' . "\n" . $hidden;
-
- return $ret;
-}
-
-/**
- * Returns single option in a list element
- *
- * @param string $section name of config section in $GLOBALS['cfg'][$section] for plugin
- * config
- * section in
- * $GLOBALS['cfg'][$section]
- * for plugin
- * @param string $plugin_name unique plugin name
- * name
- * @param array|\PhpMyAdmin\Properties\PropertyItem &$propertyGroup options
- * property main
- * group
- * instance
- * @param boolean $is_subgroup if this group is a subgroup
- * is a subgroup
- *
- * @return string table row with option
- */
-function PMA_pluginGetOneOption(
- $section,
- $plugin_name,
- &$propertyGroup,
- $is_subgroup = false
-) {
- $ret = "\n";
-
- if (! $is_subgroup) {
- // for subgroup headers
- if (mb_strpos(get_class($propertyGroup), "PropertyItem")) {
- $properties = array($propertyGroup);
- } else {
- // for main groups
- $ret .= '';
-
- if (method_exists($propertyGroup, 'getText')) {
- $text = $propertyGroup->getText();
- }
-
- if ($text != null) {
- $ret .= '
' . PMA_getString($text) . ' ';
- }
- $ret .= '
';
- }
- }
-
- if (! isset($properties)) {
- $not_subgroup_header = true;
- if (method_exists($propertyGroup, 'getProperties')) {
- $properties = $propertyGroup->getProperties();
- }
- }
-
- if (isset($properties)) {
- /** @var OptionsPropertySubgroup $propertyItem */
- foreach ($properties as $propertyItem) {
- $property_class = get_class($propertyItem);
- // if the property is a subgroup, we deal with it recursively
- if (mb_strpos($property_class, "Subgroup")) {
- // for subgroups
- // each subgroup can have a header, which may also be a form element
- /** @var OptionsPropertyItem $subgroup_header */
- $subgroup_header = $propertyItem->getSubgroupHeader();
- if (isset($subgroup_header)) {
- $ret .= PMA_pluginGetOneOption(
- $section,
- $plugin_name,
- $subgroup_header
- );
- }
-
- $ret .= 'getName() . '">';
- } else {
- $ret .= '>';
- }
-
- $ret .= PMA_pluginGetOneOption(
- $section,
- $plugin_name,
- $propertyItem,
- true
- );
- continue;
- }
-
- // single property item
- $ret .= PMA_getHtmlForProperty(
- $section, $plugin_name, $propertyItem
- );
- }
- }
-
- if ($is_subgroup) {
- // end subgroup
- $ret .= ' ';
- } else {
- // end main group
- if (! empty($not_subgroup_header)) {
- $ret .= ' ';
- }
- }
-
- if (method_exists($propertyGroup, "getDoc")) {
- $doc = $propertyGroup->getDoc();
- if ($doc != null) {
- if (count($doc) == 3) {
- $ret .= PhpMyAdmin\Util::showMySQLDocu(
- $doc[1],
- false,
- $doc[2]
- );
- } elseif (count($doc) == 1) {
- $ret .= PhpMyAdmin\Util::showDocu('faq', $doc[0]);
- } else {
- $ret .= PhpMyAdmin\Util::showMySQLDocu(
- $doc[1]
- );
- }
- }
- }
-
- // Close the list element after $doc link is displayed
- if (isset($property_class)) {
- if ($property_class == 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem'
- || $property_class == 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem'
- || $property_class == 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem'
- || $property_class == 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem'
- ) {
- $ret .= ' ';
- }
- }
- $ret .= "\n";
- return $ret;
-}
-
-/**
- * Get HTML for properties items
- *
- * @param string $section name of config section in
- * $GLOBALS['cfg'][$section] for plugin
- * @param string $plugin_name unique plugin name
- * @param OptionsPropertyItem $propertyItem Property item
- *
- * @return string
- */
-function PMA_getHtmlForProperty(
- $section, $plugin_name, $propertyItem
-) {
- $ret = null;
- $property_class = get_class($propertyItem);
- switch ($property_class) {
- case 'PhpMyAdmin\Properties\Options\Items\BoolPropertyItem':
- $ret .= '' . "\n";
- $ret .= ' getName()
- );
-
- if ($propertyItem->getForce() != null) {
- // Same code is also few lines lower, update both if needed
- $ret .= ' onclick="if (!this.checked && '
- . '(!document.getElementById(\'checkbox_' . $plugin_name
- . '_' . $propertyItem->getForce() . '\') '
- . '|| !document.getElementById(\'checkbox_'
- . $plugin_name . '_' . $propertyItem->getForce()
- . '\').checked)) '
- . 'return false; else return true;"';
- }
- $ret .= ' />';
- $ret .= ''
- . PMA_getString($propertyItem->getText()) . ' ';
- break;
- case 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem':
- echo 'PhpMyAdmin\Properties\Options\Items\DocPropertyItem';
- break;
- case 'PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem':
- $ret .= ' ';
- break;
- case 'PhpMyAdmin\Properties\Options\Items\MessageOnlyPropertyItem':
- $ret .= '' . "\n";
- $ret .= '' . PMA_getString($propertyItem->getText()) . '
';
- break;
- case 'PhpMyAdmin\Properties\Options\Items\RadioPropertyItem':
- $default = PMA_pluginGetDefault(
- $section,
- $plugin_name . '_' . $propertyItem->getName()
- );
- foreach ($propertyItem->getValues() as $key => $val) {
- $ret .= ' '
- . PMA_getString($val) . ' ';
- }
- break;
- case 'PhpMyAdmin\Properties\Options\Items\SelectPropertyItem':
- $ret .= '' . "\n";
- $ret .= ''
- . PMA_getString($propertyItem->getText()) . ' ';
- $ret .= '';
- $default = PMA_pluginGetDefault(
- $section,
- $plugin_name . '_' . $propertyItem->getName()
- );
- foreach ($propertyItem->getValues() as $key => $val) {
- $ret .= '';
- }
- $ret .= ' ';
- break;
- case 'PhpMyAdmin\Properties\Options\Items\TextPropertyItem':
- case 'PhpMyAdmin\Properties\Options\Items\NumberPropertyItem':
- $ret .= ' ' . "\n";
- $ret .= ''
- . PMA_getString($propertyItem->getText()) . ' ';
- $ret .= ' getSize() != null
- ? ' size="' . $propertyItem->getSize() . '"'
- : '')
- . ($propertyItem->getLen() != null
- ? ' maxlength="' . $propertyItem->getLen() . '"'
- : '')
- . ' />';
- break;
- default:
- break;
- }
- return $ret;
-}
-
-/**
- * Returns html div with editable options for plugin
- *
- * @param string $section name of config section in $GLOBALS['cfg'][$section]
- * @param array &$list array with plugin instances
- *
- * @return string html fieldset with plugin options
- */
-function PMA_pluginGetOptions($section, &$list)
-{
- $ret = '';
- // Options for plugins that support them
- foreach ($list as $plugin) {
- $properties = $plugin->getProperties();
- if ($properties != null) {
- $text = $properties->getText();
- $options = $properties->getOptions();
- }
-
- $elem = explode('\\', get_class($plugin));
- $plugin_name = array_pop($elem);
- unset($elem);
- $plugin_name = mb_strtolower(
- mb_substr(
- $plugin_name,
- mb_strlen($section)
- )
- );
-
- $ret .= '';
- }
- return $ret;
-}
diff --git a/schema_export.php b/schema_export.php
index 040768dd2b..936cc0c263 100644
--- a/schema_export.php
+++ b/schema_export.php
@@ -7,6 +7,7 @@
*/
use PhpMyAdmin\Core;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\SchemaPlugin;
use PhpMyAdmin\Relation;
@@ -22,7 +23,6 @@ require_once 'libraries/common.inc.php';
$cfgRelation = Relation::getRelationsParam();
require_once 'libraries/pmd_common.php';
-require_once 'libraries/plugin_interface.lib.php';
if (! isset($_REQUEST['export_type'])) {
PhpMyAdmin\Util::checkParameters(array('export_type'));
@@ -56,7 +56,7 @@ function PMA_processExportSchema($export_type)
// get the specific plugin
/* @var $export_plugin SchemaPlugin */
- $export_plugin = PMA_getPlugin(
+ $export_plugin = Plugins::getPlugin(
"schema",
$export_type,
'libraries/classes/Plugins/Schema/'
diff --git a/templates/database/designer/schema_export.phtml b/templates/database/designer/schema_export.phtml
index 6364edc452..ec0dcf66ee 100644
--- a/templates/database/designer/schema_export.phtml
+++ b/templates/database/designer/schema_export.phtml
@@ -2,10 +2,10 @@
= PhpMyAdmin\Url::getHiddenInputs($db); ?>
= __('Select Export Relational Type'); ?>
- = PMA_pluginGetChoice(
+ = PhpMyAdmin\Plugins::getChoice(
'Schema', 'export_type', $export_list, 'format'
); ?>
- = PMA_pluginGetOptions('Schema', $export_list); ?>
+ = PhpMyAdmin\Plugins::getOptions('Schema', $export_list); ?>
diff --git a/test/classes/Database/DesignerTest.php b/test/classes/Database/DesignerTest.php
index eab496922b..c3039e69c7 100644
--- a/test/classes/Database/DesignerTest.php
+++ b/test/classes/Database/DesignerTest.php
@@ -9,11 +9,6 @@ namespace PhpMyAdmin\Tests\Database;
use PhpMyAdmin\Database\Designer;
use PhpMyAdmin\DatabaseInterface;
-/*
- * Include to test.
- */
-require_once 'libraries/plugin_interface.lib.php';
-
/**
* Tests for PhpMyAdmin\Database\Designer
*
diff --git a/test/classes/Display/ExportTest.php b/test/classes/Display/ExportTest.php
index b737e4e5e9..5ca4ae8b41 100644
--- a/test/classes/Display/ExportTest.php
+++ b/test/classes/Display/ExportTest.php
@@ -9,12 +9,11 @@ namespace PhpMyAdmin\Tests\Display;
use PhpMyAdmin\Core;
use PhpMyAdmin\Display\Export;
+use PhpMyAdmin\Plugins;
use PhpMyAdmin\Theme;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
-require_once 'libraries/plugin_interface.lib.php';
-
/**
* class PhpMyAdmin\Tests\Display\ExportTest
*
@@ -148,7 +147,7 @@ class ExportTest extends \PHPUnit_Framework_TestCase
$GLOBALS['dbi'] = $dbi;
/* Scan for plugins */
- $export_list = PMA_getPlugins(
+ $export_list = Plugins::getPlugins(
"export",
'libraries/classes/Plugins/Export/',
array(
From df6ef79e930a1e43ca0d5554e24d0867c0559b05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?=
Date: Tue, 12 Sep 2017 17:51:58 -0300
Subject: [PATCH 08/11] Move PMA_printListItem to PhpMyAdmin\Core class
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Maurício Meneghini Fauth
---
index.php | 113 ++++++++--------------
libraries/classes/Core.php | 36 +++++++
libraries/classes/Display/GitRevision.php | 2 +-
3 files changed, 76 insertions(+), 75 deletions(-)
diff --git a/index.php b/index.php
index bb14dce20f..87eac0acd8 100644
--- a/index.php
+++ b/index.php
@@ -5,8 +5,8 @@
*
* @package PhpMyAdmin
*/
-
use PhpMyAdmin\Charsets;
+use PhpMyAdmin\Config;
use PhpMyAdmin\Core;
use PhpMyAdmin\Display\GitRevision;
use PhpMyAdmin\LanguageManager;
@@ -17,6 +17,7 @@ use PhpMyAdmin\Response;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Url;
+use PhpMyAdmin\Util;
/**
* Gets some core libraries and displays a top message if required
@@ -68,11 +69,11 @@ if (isset($_REQUEST['ajax_request']) && ! empty($_REQUEST['access_time'])) {
if (! empty($_REQUEST['db'])) {
$page = null;
if (! empty($_REQUEST['table'])) {
- $page = PhpMyAdmin\Util::getScriptNameForOption(
+ $page = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabTable'], 'table'
);
} else {
- $page = PhpMyAdmin\Util::getScriptNameForOption(
+ $page = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
);
}
@@ -107,7 +108,7 @@ $show_query = '1';
// Any message to display?
if (! empty($message)) {
- echo PhpMyAdmin\Util::getMessage($message);
+ echo Util::getMessage($message);
unset($message);
}
if (isset($_SESSION['partial_logout'])) {
@@ -183,7 +184,7 @@ if ($server > 0 || count($cfg['Servers']) > 1
) {
echo '';
include_once 'libraries/select_server.lib.php';
- echo PhpMyAdmin\Util::getImage('s_host.png') , " "
+ echo Util::getImage('s_host.png') , " "
, PMA_selectServer(true, true);
echo ' ';
}
@@ -198,8 +199,8 @@ if ($server > 0 || count($cfg['Servers']) > 1
if ($cfg['Server']['auth_type'] != 'config') {
if ($cfg['ShowChgPassword']) {
$conditional_class = 'ajax';
- PMA_printListItem(
- PhpMyAdmin\Util::getImage('s_passwd.png') . " " . __(
+ Core::printListItem(
+ Util::getImage('s_passwd.png') . " " . __(
'Change password'
),
'li_change_password',
@@ -216,10 +217,10 @@ if ($server > 0 || count($cfg['Servers']) > 1
echo ' ';
+ } elseif ($list) {
+ $retval .= '';
+ }
+
+ return $retval;
+ }
+}
diff --git a/libraries/select_server.lib.php b/libraries/select_server.lib.php
deleted file mode 100644
index 49bac63dd2..0000000000
--- a/libraries/select_server.lib.php
+++ /dev/null
@@ -1,115 +0,0 @@
-';
-
- if (! $omit_fieldset) {
- $retval .= '';
- }
-
- $retval .= Url::getHiddenFields(array());
- $retval .= ''
- . __('Current server:') . ' ';
-
- $retval .= '';
- $retval .= '(' . __('Servers') . ') ... ' . "\n";
- } elseif ($list) {
- $retval .= __('Current server:') . ' ';
- $retval .= '';
- }
-
- foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
- if (empty($server['host'])) {
- continue;
- }
-
- if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
- $selected = 1;
- } else {
- $selected = 0;
- }
- if (!empty($server['verbose'])) {
- $label = $server['verbose'];
- } else {
- $label = $server['host'];
- if (!empty($server['port'])) {
- $label .= ':' . $server['port'];
- }
- }
- if (! empty($server['only_db'])) {
- if (! is_array($server['only_db'])) {
- $label .= ' - ' . $server['only_db'];
- // try to avoid displaying a too wide selector
- } elseif (count($server['only_db']) < 4) {
- $label .= ' - ' . implode(', ', $server['only_db']);
- }
- }
- if (!empty($server['user']) && $server['auth_type'] == 'config') {
- $label .= ' (' . $server['user'] . ')';
- }
-
- if ($list) {
- $retval .= '';
- if ($selected) {
- $retval .= '' . htmlspecialchars($label) . ' ';
- } else {
-
- $retval .= '' . htmlspecialchars($label) . ' ';
- }
- $retval .= ' ';
- } else {
- $retval .= ''
- . htmlspecialchars($label) . ' ' . "\n";
- }
- } // end while
-
- if ($not_only_options) {
- $retval .= ' ';
- if (! $omit_fieldset) {
- $retval .= ' ';
- }
- $retval .= '';
- } elseif ($list) {
- $retval .= '';
- }
-
- return $retval;
-}
diff --git a/test/libraries/PMA_select_server_test.php b/test/classes/Server/SelectTest.php
similarity index 84%
rename from test/libraries/PMA_select_server_test.php
rename to test/classes/Server/SelectTest.php
index 733b336a70..71bc09a248 100644
--- a/test/libraries/PMA_select_server_test.php
+++ b/test/classes/Server/SelectTest.php
@@ -1,28 +1,25 @@
assertContains(
- PhpMyAdmin\Util::getScriptNameForOption(
+ Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabServer'], 'server'
),
$html