Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauriciofauth@gmail.com>2017-09-13 05:12:28 +0300
committerMaurício Meneghini Fauth <mauriciofauth@gmail.com>2017-09-13 05:12:28 +0300
commit99642bf6e2c94d7f2fbe8fe3b3af933f671c9a2e (patch)
tree68000a5afcb0e357d8051520db15999ad0b4a248
parentce49e7f60f2995ca2d5c39e1407c3d701c77e967 (diff)
Refactor select_server functions to static methods
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
-rw-r--r--index.php4
-rw-r--r--libraries/classes/Navigation/NavigationHeader.php4
-rw-r--r--libraries/classes/Plugins/Auth/AuthenticationConfig.php4
-rw-r--r--libraries/classes/Plugins/Auth/AuthenticationCookie.php6
-rw-r--r--libraries/classes/Server/Select.php125
-rw-r--r--libraries/select_server.lib.php115
-rw-r--r--test/classes/Server/SelectTest.php (renamed from test/libraries/PMA_select_server_test.php)29
7 files changed, 146 insertions, 141 deletions
diff --git a/index.php b/index.php
index 87eac0acd8..ba59c03d5e 100644
--- a/index.php
+++ b/index.php
@@ -15,6 +15,7 @@ use PhpMyAdmin\RecentFavoriteTable;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sanitize;
+use PhpMyAdmin\Server\Select;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
@@ -183,9 +184,8 @@ if ($server > 0 || count($cfg['Servers']) > 1
|| ($server == 0 && count($cfg['Servers']) == 1)))
) {
echo '<li id="li_select_server" class="no_bullets" >';
- include_once 'libraries/select_server.lib.php';
echo Util::getImage('s_host.png') , " "
- , PMA_selectServer(true, true);
+ , Select::render(true, true);
echo '</li>';
}
diff --git a/libraries/classes/Navigation/NavigationHeader.php b/libraries/classes/Navigation/NavigationHeader.php
index 2a6d5d8558..4af2e2c43a 100644
--- a/libraries/classes/Navigation/NavigationHeader.php
+++ b/libraries/classes/Navigation/NavigationHeader.php
@@ -8,6 +8,7 @@
namespace PhpMyAdmin\Navigation;
use PhpMyAdmin\Sanitize;
+use PhpMyAdmin\Server\Select;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
@@ -240,10 +241,9 @@ class NavigationHeader
if ($GLOBALS['cfg']['NavigationDisplayServers']
&& count($GLOBALS['cfg']['Servers']) > 1
) {
- include_once './libraries/select_server.lib.php';
$retval .= '<!-- SERVER CHOICE START -->';
$retval .= '<div id="serverChoice">';
- $retval .= PMA_selectServer(true, true);
+ $retval .= Select::render(true, true);
$retval .= '</div>';
$retval .= '<!-- SERVER CHOICE END -->';
}
diff --git a/libraries/classes/Plugins/Auth/AuthenticationConfig.php b/libraries/classes/Plugins/Auth/AuthenticationConfig.php
index 79a2242efc..9d53919249 100644
--- a/libraries/classes/Plugins/Auth/AuthenticationConfig.php
+++ b/libraries/classes/Plugins/Auth/AuthenticationConfig.php
@@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Auth;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
use PhpMyAdmin\Response;
+use PhpMyAdmin\Server\Select;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
@@ -161,10 +162,9 @@ class AuthenticationConfig extends AuthenticationPlugin
</tr>' , "\n";
if (count($GLOBALS['cfg']['Servers']) > 1) {
// offer a chance to login to other servers if the current one failed
- include_once './libraries/select_server.lib.php';
echo '<tr>' , "\n";
echo ' <td>' , "\n";
- echo PMA_selectServer(true, true);
+ echo Select::render(true, true);
echo ' </td>' , "\n";
echo '</tr>' , "\n";
}
diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php
index 5831c9c0e4..78ef5a7ccc 100644
--- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php
+++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php
@@ -14,6 +14,7 @@ use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
use PhpMyAdmin\Response;
+use PhpMyAdmin\Server\Select;
use PhpMyAdmin\Session;
use PhpMyAdmin\Util;
use PhpMyAdmin\Url;
@@ -218,10 +219,7 @@ class AuthenticationCookie extends AuthenticationPlugin
, 'elements[\'pma_servername\'].value = \'\'" ';
}
echo '>';
-
- include_once './libraries/select_server.lib.php';
- echo PMA_selectServer(false, false);
-
+ echo Select::render(false, false);
echo '</select></div>';
} else {
echo ' <input type="hidden" name="server" value="'
diff --git a/libraries/classes/Server/Select.php b/libraries/classes/Server/Select.php
new file mode 100644
index 0000000000..b5b434de83
--- /dev/null
+++ b/libraries/classes/Server/Select.php
@@ -0,0 +1,125 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Code for displaying server selection
+ *
+ * @package PhpMyAdmin
+ */
+namespace PhpMyAdmin\Server;
+
+use PhpMyAdmin\Url;
+use PhpMyAdmin\Util;
+
+/**
+ * PhpMyAdmin\Server\Select class
+ *
+ * @package PhpMyAdmin
+ */
+class Select
+{
+ /**
+ * Renders the server selection in list or selectbox form, or option tags only
+ *
+ * @param boolean $not_only_options whether to include form tags or not
+ * @param boolean $omit_fieldset whether to omit fieldset tag or not
+ *
+ * @return string
+ */
+ public static function render($not_only_options, $omit_fieldset)
+ {
+ $retval = '';
+
+ // Show as list?
+ if ($not_only_options) {
+ $list = $GLOBALS['cfg']['DisplayServersList'];
+ $not_only_options =! $list;
+ } else {
+ $list = false;
+ }
+
+ if ($not_only_options) {
+ $retval .= '<form method="post" action="'
+ . Util::getScriptNameForOption(
+ $GLOBALS['cfg']['DefaultTabServer'], 'server'
+ )
+ . '" class="disableAjax">';
+
+ if (! $omit_fieldset) {
+ $retval .= '<fieldset>';
+ }
+
+ $retval .= Url::getHiddenFields(array());
+ $retval .= '<label for="select_server">'
+ . __('Current server:') . '</label> ';
+
+ $retval .= '<select name="server" id="select_server" class="autosubmit">';
+ $retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
+ } elseif ($list) {
+ $retval .= __('Current server:') . '<br />';
+ $retval .= '<ul id="list_server">';
+ }
+
+ 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 .= '<li>';
+ if ($selected) {
+ $retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
+ } else {
+
+ $retval .= '<a class="disableAjax item" href="'
+ . Util::getScriptNameForOption(
+ $GLOBALS['cfg']['DefaultTabServer'], 'server'
+ )
+ . Url::getCommon(array('server' => $key))
+ . '" >' . htmlspecialchars($label) . '</a>';
+ }
+ $retval .= '</li>';
+ } else {
+ $retval .= '<option value="' . $key . '" '
+ . ($selected ? ' selected="selected"' : '') . '>'
+ . htmlspecialchars($label) . '</option>' . "\n";
+ }
+ } // end while
+
+ if ($not_only_options) {
+ $retval .= '</select>';
+ if (! $omit_fieldset) {
+ $retval .= '</fieldset>';
+ }
+ $retval .= '</form>';
+ } elseif ($list) {
+ $retval .= '</ul>';
+ }
+
+ 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 @@
-<?php
-/* vim: set expandtab sw=4 ts=4 sts=4: */
-/**
- * Code for displaying server selection
- *
- * @package PhpMyAdmin
- */
-
-use PhpMyAdmin\Url;
-
-/**
- * Renders the server selection in list or selectbox form, or option tags only
- *
- * @param boolean $not_only_options whether to include form tags or not
- * @param boolean $omit_fieldset whether to omit fieldset tag or not
- *
- * @return string
- */
-function PMA_selectServer($not_only_options, $omit_fieldset)
-{
- $retval = '';
-
- // Show as list?
- if ($not_only_options) {
- $list = $GLOBALS['cfg']['DisplayServersList'];
- $not_only_options =! $list;
- } else {
- $list = false;
- }
-
- if ($not_only_options) {
- $retval .= '<form method="post" action="'
- . PhpMyAdmin\Util::getScriptNameForOption(
- $GLOBALS['cfg']['DefaultTabServer'], 'server'
- )
- . '" class="disableAjax">';
-
- if (! $omit_fieldset) {
- $retval .= '<fieldset>';
- }
-
- $retval .= Url::getHiddenFields(array());
- $retval .= '<label for="select_server">'
- . __('Current server:') . '</label> ';
-
- $retval .= '<select name="server" id="select_server" class="autosubmit">';
- $retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
- } elseif ($list) {
- $retval .= __('Current server:') . '<br />';
- $retval .= '<ul id="list_server">';
- }
-
- 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 .= '<li>';
- if ($selected) {
- $retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
- } else {
-
- $retval .= '<a class="disableAjax item" href="'
- . PhpMyAdmin\Util::getScriptNameForOption(
- $GLOBALS['cfg']['DefaultTabServer'], 'server'
- )
- . Url::getCommon(array('server' => $key))
- . '" >' . htmlspecialchars($label) . '</a>';
- }
- $retval .= '</li>';
- } else {
- $retval .= '<option value="' . $key . '" '
- . ($selected ? ' selected="selected"' : '') . '>'
- . htmlspecialchars($label) . '</option>' . "\n";
- }
- } // end while
-
- if ($not_only_options) {
- $retval .= '</select>';
- if (! $omit_fieldset) {
- $retval .= '</fieldset>';
- }
- $retval .= '</form>';
- } elseif ($list) {
- $retval .= '</ul>';
- }
-
- return $retval;
-}
diff --git a/test/libraries/PMA_select_server_test.php b/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 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
- * tests for select_server.lib.php
+ * tests for PhpMyAdmin\Server\Select
*
* @package PhpMyAdmin-test
*/
+namespace PhpMyAdmin\Tests\Server;
-/*
- * Include to test.
- */
+use PhpMyAdmin\Server\Select;
use PhpMyAdmin\Theme;
-
-
-require_once 'libraries/select_server.lib.php';
-
+use PhpMyAdmin\Util;
+use PHPUnit_Framework_TestCase as TestCase;
/**
- * PMA_SelectServer_Test class
+ * PhpMyAdmin\Tests\Server\SelectTest class
*
- * this class is for testing select_server.lib.php functions
+ * this class is for testing PhpMyAdmin\Server\Select methods
*
* @package PhpMyAdmin-test
*/
-class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
+class SelectTest extends TestCase
{
/**
* Prepares environment for the test.
@@ -52,11 +49,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
}
/**
- * Test for PMA_selectServer
+ * Test for Select::render
*
* @return void
*/
- public function testPMASelectServer()
+ public function testRender()
{
$not_only_options = false;
$omit_fieldset = false;
@@ -81,7 +78,7 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
);
//$not_only_options=false & $omit_fieldset=false
- $html = PMA_selectServer($not_only_options, $omit_fieldset);
+ $html = Select::render($not_only_options, $omit_fieldset);
$server = $GLOBALS['cfg']['Servers']['0'];
//server items
@@ -107,11 +104,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
$GLOBALS['cfg']['DisplayServersList'] = null;
//$not_only_options=true & $omit_fieldset=true
- $html = PMA_selectServer($not_only_options, $omit_fieldset);
+ $html = Select::render($not_only_options, $omit_fieldset);
//$GLOBALS['cfg']['DefaultTabServer']
$this->assertContains(
- PhpMyAdmin\Util::getScriptNameForOption(
+ Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabServer'], 'server'
),
$html