From 82dc32305bd250dc191c671cb238d92ac50c72ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 6 Sep 2017 21:13:54 -0300 Subject: [PATCH 1/5] Rename DisplayResults to Display/Results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move libraries/classes/DisplayResults.php to libraries/classes/Display/Results.php Signed-off-by: Maurício Meneghini Fauth --- .../Results.php} | 9 ++-- libraries/classes/Sql.php | 2 +- tbl_replace.php | 3 -- .../ResultsTest.php} | 41 +++++++++++-------- 4 files changed, 29 insertions(+), 26 deletions(-) rename libraries/classes/{DisplayResults.php => Display/Results.php} (99%) rename test/classes/{DisplayResultsTest.php => Display/ResultsTest.php} (98%) diff --git a/libraries/classes/DisplayResults.php b/libraries/classes/Display/Results.php similarity index 99% rename from libraries/classes/DisplayResults.php rename to libraries/classes/Display/Results.php index 6a7547d227..6c81e03336 100644 --- a/libraries/classes/DisplayResults.php +++ b/libraries/classes/Display/Results.php @@ -1,11 +1,11 @@ isAjax() && ! isset($_POST['ajax_page_request'])) { * If we are in grid editing, we need to process the relational and * transformed fields, if they were edited. After that, output the correct * link/transformed value and exit - * - * Logic taken from libraries/DisplayResults.php */ - if (isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') { $map = Relation::getForeigners($db, $table, '', 'both'); diff --git a/test/classes/DisplayResultsTest.php b/test/classes/Display/ResultsTest.php similarity index 98% rename from test/classes/DisplayResultsTest.php rename to test/classes/Display/ResultsTest.php index 9816b6293e..f3eb93260a 100644 --- a/test/classes/DisplayResultsTest.php +++ b/test/classes/Display/ResultsTest.php @@ -4,14 +4,21 @@ * * @package PhpMyAdmin-test */ +namespace PhpMyAdmin\Tests\Display; + +use PhpMyAdmin\Config; +use PhpMyAdmin\Core; +use PhpMyAdmin\Display\Results as DisplayResults; +use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link; +use PhpMyAdmin\SqlParser\Parser; +use PhpMyAdmin\SqlParser\Utils\Query; +use PhpMyAdmin\Transformations; +use ReflectionClass; +use stdClass; /* - * Include to test. - */ -use PhpMyAdmin\Core; -use PhpMyAdmin\DisplayResults; -use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link; - +* Include to test. +*/ require_once 'test/PMATestCase.php'; /** @@ -19,7 +26,7 @@ require_once 'test/PMATestCase.php'; * * @package PhpMyAdmin-test */ -class DisplayResultsTest extends PMATestCase +class ResultsTest extends \PMATestCase { /** * @access protected @@ -37,7 +44,7 @@ class DisplayResultsTest extends PMATestCase { $GLOBALS['server'] = 0; $this->object = new DisplayResults('as', '', '', ''); - $GLOBALS['PMA_Config'] = new PhpMyAdmin\Config(); + $GLOBALS['PMA_Config'] = new Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['text_dir'] = 'ltr'; $GLOBALS['collation_connection'] = 'utf-8'; @@ -87,7 +94,7 @@ class DisplayResultsTest extends PMATestCase */ public function testisSelect() { - $parser = new \PhpMyAdmin\SqlParser\Parser('SELECT * FROM pma'); + $parser = new Parser('SELECT * FROM pma'); $this->assertTrue( $this->_callPrivateFunction( '_isSelect', @@ -1211,7 +1218,7 @@ class DisplayResultsTest extends PMATestCase */ public function dataProviderForTestSetHighlightedColumnGlobalField() { - $parser = new PhpMyAdmin\SqlParser\Parser( + $parser = new Parser( 'SELECT * FROM db_name WHERE `db_name`.`tbl`.id > 0 AND `id` < 10' ); return array( @@ -1301,7 +1308,7 @@ class DisplayResultsTest extends PMATestCase public function dataProviderForTestHandleNonPrintableContents() { $transformation_plugin = new Text_Plain_Link(); - $meta = new StdClass(); + $meta = new stdClass(); $meta->type = 'BLOB'; $meta->orgtable = 'bar'; $url_params = array('db' => 'foo', 'table' => 'bar'); @@ -1434,7 +1441,7 @@ class DisplayResultsTest extends PMATestCase public function dataProviderForTestGetDataCellForNonNumericColumns() { $transformation_plugin = new Text_Plain_Link(); - $meta = new StdClass(); + $meta = new stdClass(); $meta->db = 'foo'; $meta->table = 'tbl'; $meta->orgtable = 'tbl'; @@ -1443,7 +1450,7 @@ class DisplayResultsTest extends PMATestCase $meta->name = 'tblob'; $meta->orgname = 'tblob'; - $meta2 = new StdClass(); + $meta2 = new stdClass(); $meta2->db = 'foo'; $meta2->table = 'tbl'; $meta2->orgtable = 'tbl'; @@ -1608,7 +1615,7 @@ class DisplayResultsTest extends PMATestCase $this->object->__set('fields_cnt', 2); // Field meta information - $meta = new StdClass(); + $meta = new stdClass(); $meta->db = 'db'; $meta->table = 'table'; $meta->orgtable = 'table'; @@ -1620,7 +1627,7 @@ class DisplayResultsTest extends PMATestCase $meta->numeric = true; $meta->primary_key = false; $meta->unique_key = false; - $meta2 = new StdClass(); + $meta2 = new stdClass(); $meta2->db = 'db'; $meta2->table = 'table'; $meta2->orgtable = 'table'; @@ -1652,7 +1659,7 @@ class DisplayResultsTest extends PMATestCase ); $this->object->__set( 'mime_map', - \PhpMyAdmin\Transformations::getMIME('db', 'table') + Transformations::getMIME('db', 'table') ); // Actually invoke tested method @@ -1661,7 +1668,7 @@ class DisplayResultsTest extends PMATestCase array( &$result, array(3600, true), 0, false, array(), '', false, $query, - PhpMyAdmin\SqlParser\Utils\Query::getAll($query) + Query::getAll($query) ) ); From 2217b4c96066024a8d0aa725b416662ff9b85902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 6 Sep 2017 21:42:18 -0300 Subject: [PATCH 2/5] Refactor change password 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 --- js/functions.js | 2 +- libraries/classes/Display/ChangePassword.php | 165 ++++++++++++++++++ libraries/classes/Server/Privileges.php | 3 +- libraries/display_change_password.lib.php | 154 ---------------- server_privileges.php | 1 - .../Display/ChangePasswordTest.php} | 26 ++- user_password.php | 7 +- 7 files changed, 182 insertions(+), 176 deletions(-) create mode 100644 libraries/classes/Display/ChangePassword.php delete mode 100644 libraries/display_change_password.lib.php rename test/{libraries/PMA_display_change_password_test.php => classes/Display/ChangePasswordTest.php} (79%) diff --git a/js/functions.js b/js/functions.js index bfffac67f0..fb0b4f0861 100644 --- a/js/functions.js +++ b/js/functions.js @@ -604,7 +604,7 @@ function PMA_display_git_revision() } /** - * for libraries/display_change_password.lib.php + * for PhpMyAdmin\Display\ChangePassword * libraries/user_password.php * */ diff --git a/libraries/classes/Display/ChangePassword.php b/libraries/classes/Display/ChangePassword.php new file mode 100644 index 0000000000..4284b80915 --- /dev/null +++ b/libraries/classes/Display/ChangePassword.php @@ -0,0 +1,165 @@ +'; + + $html .= Url::getHiddenInputs(); + + if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { + $html .= '' + . ''; + } + $html .= '
' + . '' . __('Change password') . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + $serverType = Util::getServerType(); + $serverVersion = $GLOBALS['dbi']->getVersion(); + $orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin( + 'change', + $username, + $hostname + ); + $is_superuser = $GLOBALS['dbi']->isSuperuser(); + + if (($serverType == 'MySQL' + && $serverVersion >= 50507) + || ($serverType == 'MariaDB' + && $serverVersion >= 50200) + ) { + // Provide this option only for 5.7.6+ + // OR for privileged users in 5.5.7+ + if (($serverType == 'MySQL' + && $serverVersion >= 50706) + || ($is_superuser && $mode == 'edit_other') + ) { + $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown( + $orig_auth_plugin, 'change_pw', 'new' + ); + + $html .= '' + . '' + . '' + . '
' + . '' + . '' + . '
' + . '' + . '' + . '' + . __('Enter:') . '     ' + . '' + . 'Strength: ' + . ' ' + . 'Good' + . '
' . __('Re-type:') . ' ' + . '' + . '
' . __('Password Hashing:') . ''; + $html .= $auth_plugin_dropdown; + $html .= '
'; + + $html .= '' + . Message::notice( + __( + 'This method requires using an \'SSL connection\' ' + . 'or an \'unencrypted connection that encrypts the ' + . 'password using RSA\'; while connecting to the server.' + ) + . Util::showMySQLDocu( + 'sha256-authentication-plugin' + ) + ) + ->getDisplay() + . ''; + } else { + $html .= '' + . ''; + } + } else { + $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown( + $orig_auth_plugin, 'change_pw', 'old' + ); + + $html .= '' + . '' . __('Password Hashing:') . ''; + $html .= $auth_plugin_dropdown . '' + . '' + . ''; + } + + $html .= '
' + . '' + . ''; + return $html; + } +} diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index ae1de83483..df195907c9 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Server; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Display\ChangePassword; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -4838,7 +4839,7 @@ class Privileges if (! is_array($dbname) && strlen($dbname) === 0 && ! $user_does_not_exists) { //change login information - $html_output .= PMA_getHtmlForChangePassword( + $html_output .= ChangePassword::getHtml( 'edit_other', $username, $hostname diff --git a/libraries/display_change_password.lib.php b/libraries/display_change_password.lib.php deleted file mode 100644 index a8cd84965d..0000000000 --- a/libraries/display_change_password.lib.php +++ /dev/null @@ -1,154 +0,0 @@ -'; - - $html .= Url::getHiddenInputs(); - - if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { - $html .= '' - . ''; - } - $html .= '
' - . '' . __('Change password') . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . ''; - - $serverType = PhpMyAdmin\Util::getServerType(); - $serverVersion = $GLOBALS['dbi']->getVersion(); - $orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin( - 'change', - $username, - $hostname - ); - $is_superuser = $GLOBALS['dbi']->isSuperuser(); - - if (($serverType == 'MySQL' - && $serverVersion >= 50507) - || ($serverType == 'MariaDB' - && $serverVersion >= 50200) - ) { - // Provide this option only for 5.7.6+ - // OR for privileged users in 5.5.7+ - if (($serverType == 'MySQL' - && $serverVersion >= 50706) - || ($is_superuser && $mode == 'edit_other') - ) { - $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown( - $orig_auth_plugin, 'change_pw', 'new' - ); - - $html .= '' - . '' - . '' - . '
' - . '' - . '' - . '
' - . '' - . '' - . '' - . __('Enter:') . '     ' - . '' - . 'Strength: ' - . ' ' - . 'Good' - . '
' . __('Re-type:') . ' ' - . '' - . '
' . __('Password Hashing:') . ''; - $html .= $auth_plugin_dropdown; - $html .= '
'; - - $html .= '' - . Message::notice( - __( - 'This method requires using an \'SSL connection\' ' - . 'or an \'unencrypted connection that encrypts the ' - . 'password using RSA\'; while connecting to the server.' - ) - . PhpMyAdmin\Util::showMySQLDocu( - 'sha256-authentication-plugin' - ) - ) - ->getDisplay() - . ''; - } else { - $html .= '' - . ''; - } - } else { - $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown( - $orig_auth_plugin, 'change_pw', 'old' - ); - - $html .= '' - . '' . __('Password Hashing:') . ''; - $html .= $auth_plugin_dropdown . '' - . '' - . ''; - } - - $html .= '
' - . '' - . ''; - return $html; -} diff --git a/server_privileges.php b/server_privileges.php index 6270ab0002..a3144f7ab7 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -20,7 +20,6 @@ require_once 'libraries/common.inc.php'; /** * functions implementation for this script */ -require_once 'libraries/display_change_password.lib.php'; require_once 'libraries/check_user_privileges.lib.php'; $cfgRelation = Relation::getRelationsParam(); diff --git a/test/libraries/PMA_display_change_password_test.php b/test/classes/Display/ChangePasswordTest.php similarity index 79% rename from test/libraries/PMA_display_change_password_test.php rename to test/classes/Display/ChangePasswordTest.php index 1881ed3749..1c37d3fcab 100644 --- a/test/libraries/PMA_display_change_password_test.php +++ b/test/classes/Display/ChangePasswordTest.php @@ -1,31 +1,27 @@ enableBc(); $GLOBALS['cfg']['MaxRows'] = 10; $GLOBALS['cfg']['ServerDefault'] = "PMA_server"; @@ -55,17 +51,17 @@ class PMA_DisplayChangePassword_Test extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getHtmlForChangePassword + * Test for ChangePassword::getHtml * * @return void */ - public function testPMAGetHtmlForChangePassword() + public function testGetHtml() { $username = "pma_username"; $hostname = "pma_hostname"; //Call the test function - $html = PMA_getHtmlForChangePassword('change_pw', $username, $hostname); + $html = ChangePassword::getHtml('change_pw', $username, $hostname); //PMA_PHP_SELF $this->assertContains( diff --git a/user_password.php b/user_password.php index 1654d33c9a..7eaba6db7c 100644 --- a/user_password.php +++ b/user_password.php @@ -8,9 +8,10 @@ */ use PhpMyAdmin\Core; -use PhpMyAdmin\Url; +use PhpMyAdmin\Display\ChangePassword; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Privileges; +use PhpMyAdmin\Url; /** * Gets some core libraries @@ -67,9 +68,7 @@ if (isset($msg)) { unset($msg); } -require_once './libraries/display_change_password.lib.php'; - -echo PMA_getHtmlForChangePassword('change_pw', $username, $hostname); +echo ChangePassword::getHtml('change_pw', $username, $hostname); exit; /** From 81ed2c6c03bace0966618ea8cec78ed2336e7920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 6 Sep 2017 22:01:20 -0300 Subject: [PATCH 3/5] Refactor git revision function to static function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- index.php | 8 +- libraries/classes/Display/GitRevision.php | 97 +++++++++++++++++++++++ libraries/display_git_revision.lib.php | 87 -------------------- 3 files changed, 99 insertions(+), 93 deletions(-) create mode 100644 libraries/classes/Display/GitRevision.php delete mode 100644 libraries/display_git_revision.lib.php diff --git a/index.php b/index.php index 8c36ea173e..b67f5402fa 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\Core; +use PhpMyAdmin\Display\GitRevision; use PhpMyAdmin\LanguageManager; use PhpMyAdmin\Message; use PhpMyAdmin\RecentFavoriteTable; @@ -22,11 +23,6 @@ use PhpMyAdmin\Url; */ require_once 'libraries/common.inc.php'; -/** - * display Git revision if requested - */ -require_once 'libraries/display_git_revision.lib.php'; - /** * pass variables to child pages */ @@ -98,7 +94,7 @@ if ($response->isAjax() && ! empty($_REQUEST['recent_table'])) { if ($GLOBALS['PMA_Config']->isGitRevision()) { if (isset($_REQUEST['git_revision']) && $response->isAjax()) { - PMA_printGitRevision(); + GitRevision::print(); exit; } echo '
'; diff --git a/libraries/classes/Display/GitRevision.php b/libraries/classes/Display/GitRevision.php new file mode 100644 index 0000000000..f20939e6e2 --- /dev/null +++ b/libraries/classes/Display/GitRevision.php @@ -0,0 +1,97 @@ +get('PMA_VERSION_GIT')) { + $response = Response::getInstance(); + $response->setRequestStatus(false); + return; + } + + // load revision data from repo + $GLOBALS['PMA_Config']->checkGitRevision(); + + // if using a remote commit fast-forwarded, link to GitHub + $commit_hash = substr( + $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), + 0, + 7 + ); + $commit_hash = '' . $commit_hash . ''; + if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) { + $commit_hash = '' . $commit_hash . ''; + } + + $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH'); + if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) { + $branch = '' . $branch . ''; + } + if ($branch !== false) { + $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch); + } else { + $branch = $commit_hash . ' (' . __('no branch') . ')'; + } + + $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); + $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); + PMA_printListItem( + __('Git revision:') . ' ' + . $branch . ',
' + . sprintf( + __('committed on %1$s by %2$s'), + Util::localisedDate(strtotime($committer['date'])), + '' + . htmlspecialchars($committer['name']) . '' + ) + . ($author != $committer + ? ',
' + . sprintf( + __('authored on %1$s by %2$s'), + Util::localisedDate(strtotime($author['date'])), + '' + . htmlspecialchars($author['name']) . '' + ) + : ''), + 'li_pma_version_git', null, null, null + ); + } +} diff --git a/libraries/display_git_revision.lib.php b/libraries/display_git_revision.lib.php deleted file mode 100644 index c2f3521e5f..0000000000 --- a/libraries/display_git_revision.lib.php +++ /dev/null @@ -1,87 +0,0 @@ -get('PMA_VERSION_GIT')) { - $response = Response::getInstance(); - $response->setRequestStatus(false); - return; - } - - // load revision data from repo - $GLOBALS['PMA_Config']->checkGitRevision(); - - // if using a remote commit fast-forwarded, link to GitHub - $commit_hash = substr( - $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), - 0, - 7 - ); - $commit_hash = '' . $commit_hash . ''; - if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) { - $commit_hash = '' . $commit_hash . ''; - } - - $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH'); - if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) { - $branch = '' . $branch . ''; - } - if ($branch !== false) { - $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch); - } else { - $branch = $commit_hash . ' (' . __('no branch') . ')'; - } - - $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); - $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); - PMA_printListItem( - __('Git revision:') . ' ' - . $branch . ',
' - . sprintf( - __('committed on %1$s by %2$s'), - PhpMyAdmin\Util::localisedDate(strtotime($committer['date'])), - '' - . htmlspecialchars($committer['name']) . '' - ) - . ($author != $committer - ? ',
' - . sprintf( - __('authored on %1$s by %2$s'), - PhpMyAdmin\Util::localisedDate(strtotime($author['date'])), - '' - . htmlspecialchars($author['name']) . '' - ) - : ''), - 'li_pma_version_git', null, null, null - ); -} From 57f400642337eb96d0ee7d83f8866a4e5b803162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 6 Sep 2017 22:26:37 -0300 Subject: [PATCH 4/5] Refactor display_import_ajax 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 --- import_status.php | 6 +- libraries/classes/Display/Import.php | 4 +- libraries/classes/Display/ImportAjax.php | 141 ++++++++++++++++++ .../Plugins/Import/Upload/UploadApc.php | 3 +- .../Plugins/Import/Upload/UploadProgress.php | 3 +- .../Plugins/Import/Upload/UploadSession.php | 3 +- libraries/display_import_ajax.lib.php | 137 ----------------- 7 files changed, 152 insertions(+), 145 deletions(-) create mode 100644 libraries/classes/Display/ImportAjax.php delete mode 100644 libraries/display_import_ajax.lib.php diff --git a/import_status.php b/import_status.php index 415052c83b..02e39d45ca 100644 --- a/import_status.php +++ b/import_status.php @@ -7,6 +7,7 @@ */ use PhpMyAdmin\Core; +use PhpMyAdmin\Display\ImportAjax; /* PHP 5.4 stores upload progress data only in the default session. * After calling session_name(), we won't find the progress data anymore. @@ -51,12 +52,11 @@ if (ini_get('session.upload_progress.enabled')) { define('PMA_MINIMUM_COMMON', 1); require_once 'libraries/common.inc.php'; -require_once 'libraries/display_import_ajax.lib.php'; list( $SESSION_KEY, $upload_id, $plugins -) = PMA_uploadProgressSetup(); +) = ImportAjax::uploadProgressSetup(); /* if (defined('SESSIONUPLOAD')) { @@ -117,5 +117,5 @@ if (isset($_GET["message"]) && $_GET["message"]) { echo '' , "\n"; } else { - PMA_importAjaxStatus($_GET["id"]); + ImportAjax::status($_GET["id"]); } diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index bd9775fef9..65a4c8a97a 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Display; use PhpMyAdmin\Charsets; use PhpMyAdmin\Core; +use PhpMyAdmin\Display\ImportAjax; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\ImportPlugin; @@ -652,11 +653,10 @@ class Import include_once './libraries/file_listing.lib.php'; include_once './libraries/plugin_interface.lib.php'; - include_once './libraries/display_import_ajax.lib.php'; list( $SESSION_KEY, $upload_id, - ) = PMA_uploadProgressSetup(); + ) = ImportAjax::uploadProgressSetup(); /* Scan for plugins */ /* @var $import_list ImportPlugin[] */ diff --git a/libraries/classes/Display/ImportAjax.php b/libraries/classes/Display/ImportAjax.php new file mode 100644 index 0000000000..acebebad3d --- /dev/null +++ b/libraries/classes/Display/ImportAjax.php @@ -0,0 +1,141 @@ + Date: Wed, 6 Sep 2017 22:49:52 -0300 Subject: [PATCH 5/5] Refactor display_create_table 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_operations.php | 4 +-- db_tracking.php | 4 +-- js/functions.js | 2 +- .../Database/DatabaseStructureController.php | 7 ++-- .../Display/CreateTable.php} | 33 +++++++++++-------- libraries/classes/Display/Results.php | 2 +- .../Display/CreateTableTest.php} | 28 +++++++--------- 7 files changed, 40 insertions(+), 40 deletions(-) rename libraries/{display_create_table.lib.php => classes/Display/CreateTable.php} (74%) rename test/{libraries/PMA_display_create_table_test.php => classes/Display/CreateTableTest.php} (75%) diff --git a/db_operations.php b/db_operations.php index 174a36f09b..19744a7075 100644 --- a/db_operations.php +++ b/db_operations.php @@ -12,6 +12,7 @@ * @package PhpMyAdmin */ use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; use PhpMyAdmin\Plugins\Export\ExportSql; @@ -23,7 +24,6 @@ use PhpMyAdmin\Util; * requirements */ require_once 'libraries/common.inc.php'; -require_once 'libraries/display_create_table.lib.php'; /** * functions implementation for this script @@ -247,7 +247,7 @@ if (!$is_information_schema) { } $response->addHTML('
'); - $response->addHTML(PMA_getHtmlForCreateTable($db)); + $response->addHTML(CreateTable::getHtml($db)); $response->addHTML('
'); /** diff --git a/db_tracking.php b/db_tracking.php index 32cbbe7ad7..2b059343c3 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -5,6 +5,7 @@ * * @package PhpMyAdmin */ +use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -16,7 +17,6 @@ use PhpMyAdmin\Util; * Run common work */ require_once 'libraries/common.inc.php'; -require_once 'libraries/display_create_table.lib.php'; //Get some js files needed for Ajax requests $response = Response::getInstance(); @@ -105,7 +105,7 @@ if ($num_tables == 0 && count($data['ddlog']) == 0) { echo '

' , __('No tables found in database.') , '

' , "\n"; if (empty($db_is_system_schema)) { - echo PMA_getHtmlForCreateTable($db); + echo CreateTable::getHtml($db); } exit; } diff --git a/js/functions.js b/js/functions.js index fb0b4f0861..5dfd74ba63 100644 --- a/js/functions.js +++ b/js/functions.js @@ -2893,7 +2893,7 @@ AJAX.registerTeardown('functions.js', function () { /** * jQuery coding for 'Create Table'. Used on db_operations.php, * db_structure.php and db_tracking.php (i.e., wherever - * libraries/display_create_table.lib.php is used) + * PhpMyAdmin\Display\CreateTable is used) * * Attach Ajax Event handlers for Create Table */ diff --git a/libraries/classes/Controllers/Database/DatabaseStructureController.php b/libraries/classes/Controllers/Database/DatabaseStructureController.php index 3377473327..ea1b0904b6 100644 --- a/libraries/classes/Controllers/Database/DatabaseStructureController.php +++ b/libraries/classes/Controllers/Database/DatabaseStructureController.php @@ -13,6 +13,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\DatabaseController; use PhpMyAdmin\Core; +use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; use PhpMyAdmin\RecentFavoriteTable; use PhpMyAdmin\Relation; @@ -23,8 +24,6 @@ use PhpMyAdmin\Tracker; use PhpMyAdmin\Util; use PhpMyAdmin\Url; -require_once 'libraries/display_create_table.lib.php'; - /** * Handles database structure logic * @@ -150,7 +149,7 @@ class DatabaseStructureController extends DatabaseController Message::notice(__('No tables found in database.')) ); if (empty($this->_db_is_system_schema)) { - $this->response->addHTML(PMA_getHtmlForCreateTable($this->db)); + $this->response->addHTML(CreateTable::getHtml($this->db)); } return; } @@ -210,7 +209,7 @@ class DatabaseStructureController extends DatabaseController ); if (empty($this->_db_is_system_schema)) { - $this->response->addHTML(PMA_getHtmlForCreateTable($this->db)); + $this->response->addHTML(CreateTable::getHtml($this->db)); } } diff --git a/libraries/display_create_table.lib.php b/libraries/classes/Display/CreateTable.php similarity index 74% rename from libraries/display_create_table.lib.php rename to libraries/classes/Display/CreateTable.php index 5b68de8191..649083b44b 100644 --- a/libraries/display_create_table.lib.php +++ b/libraries/classes/Display/CreateTable.php @@ -24,25 +24,30 @@ * * @package PhpMyAdmin */ -if (! defined('PHPMYADMIN')) { - exit; -} +namespace PhpMyAdmin\Display; + +use PhpMyAdmin\Template; -/** - * - */ require_once './libraries/check_user_privileges.lib.php'; /** - * Returns the html for create table. + * PhpMyAdmin\Display\CreateTable class * - * @param string $db database name - * - * @return string + * @package PhpMyAdmin */ -function PMA_getHtmlForCreateTable($db) +class CreateTable { - return PhpMyAdmin\Template::get('database/create_table')->render( - array('db' => $db) - ); + /** + * Returns the html for create table. + * + * @param string $db database name + * + * @return string + */ + public static function getHtml($db) + { + return Template::get('database/create_table')->render( + array('db' => $db) + ); + } } diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 6c81e03336..7102046506 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -5209,7 +5209,7 @@ class Results /** * * @todo detect privileges to create a view - * (but see 2006-01-19 note in display_create_table.lib.php, + * (but see 2006-01-19 note in PhpMyAdmin\Display\CreateTable, * I think we cannot detect db-specific privileges reliably) * Note: we don't display a Create view link if we found a PROCEDURE clause */ diff --git a/test/libraries/PMA_display_create_table_test.php b/test/classes/Display/CreateTableTest.php similarity index 75% rename from test/libraries/PMA_display_create_table_test.php rename to test/classes/Display/CreateTableTest.php index 39b2b4d540..40977257b2 100644 --- a/test/libraries/PMA_display_create_table_test.php +++ b/test/classes/Display/CreateTableTest.php @@ -1,31 +1,25 @@ assertContains( - PhpMyAdmin\Util::getImage('b_table_add.png'), + Util::getImage('b_table_add.png'), $html );