Merge pull request #13663 from mauriciofauth/display

Refactor display functions to static methods
This commit is contained in:
Maurício Meneghini Fauth 2017-09-07 10:58:27 -03:00 committed by GitHub
commit 12b7b1ac10
26 changed files with 502 additions and 480 deletions

View File

@ -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('<div>');
$response->addHTML(PMA_getHtmlForCreateTable($db));
$response->addHTML(CreateTable::getHtml($db));
$response->addHTML('</div>');
/**

View File

@ -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 '<p>' , __('No tables found in database.') , '</p>' , "\n";
if (empty($db_is_system_schema)) {
echo PMA_getHtmlForCreateTable($db);
echo CreateTable::getHtml($db);
}
exit;
}

View File

@ -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 '</fieldset>' , "\n";
} else {
PMA_importAjaxStatus($_GET["id"]);
ImportAjax::status($_GET["id"]);
}

View File

@ -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 '<div id="is_git_revision"></div>';

View File

@ -604,7 +604,7 @@ function PMA_display_git_revision()
}
/**
* for libraries/display_change_password.lib.php
* for PhpMyAdmin\Display\ChangePassword
* libraries/user_password.php
*
*/
@ -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
*/

View File

@ -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));
}
}

View File

@ -0,0 +1,165 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays form for password change
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Display;
use PhpMyAdmin\Message;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
/**
* Displays form for password change
*
* @package PhpMyAdmin
*/
class ChangePassword
{
/**
* Get HTML for the Change password dialog
*
* @param string $mode where is the function being called?
* values : 'change_pw' or 'edit_other'
* @param string $username username
* @param string $hostname hostname
*
* @return string html snippet
*/
public static function getHtml($mode, $username, $hostname)
{
/**
* autocomplete feature of IE kills the "onchange" event handler and it
* must be replaced by the "onpropertychange" one in this case
*/
$chg_evt_handler = 'onchange';
$is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
$html = '<form method="post" id="change_password_form" '
. 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" '
. 'name="chgPassword" '
. 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
$html .= Url::getHiddenInputs();
if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
$html .= '<input type="hidden" name="username" '
. 'value="' . htmlspecialchars($username) . '" />'
. '<input type="hidden" name="hostname" '
. 'value="' . htmlspecialchars($hostname) . '" />';
}
$html .= '<fieldset id="fieldset_change_password">'
. '<legend'
. ($is_privileges
? ' data-submenu-label="' . __('Change password') . '"'
: ''
)
. '>' . __('Change password') . '</legend>'
. '<table class="data noclick">'
. '<tr>'
. '<td colspan="2">'
. '<input type="radio" name="nopass" value="1" id="nopass_1" '
. 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; '
. 'this.checked = true" />'
. '<label for="nopass_1">' . __('No Password') . '</label>'
. '</td>'
. '</tr>'
. '<tr class="vmiddle">'
. '<td>'
. '<input type="radio" name="nopass" value="0" id="nopass_0" '
. 'onclick="document.getElementById(\'text_pma_change_pw\').focus();" '
. 'checked="checked" />'
. '<label for="nopass_0">' . __('Password:') . '&nbsp;</label>'
. '</td>'
. '<td>'
. __('Enter:') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp'
. '<input type="password" name="pma_pw" id="text_pma_change_pw" size="10" '
. 'class="textfield"'
. $chg_evt_handler . '="nopass[1].checked = true" />'
. '<span>Strength:</span> '
. '<meter max="4" id="change_password_strength_meter" name="pw_meter"></meter> '
. '<span id="change_password_strength" name="pw_strength">Good</span>'
. '<br>' . __('Re-type:') . '&nbsp;'
. '<input type="password" name="pma_pw2" id="text_pma_change_pw2" size="10" '
. 'class="textfield"'
. $chg_evt_handler . '="nopass[1].checked = true" />'
. '</td>'
. '</tr>';
$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 .= '<tr class="vmiddle">'
. '<td>' . __('Password Hashing:') . '</td><td>';
$html .= $auth_plugin_dropdown;
$html .= '</td></tr>'
. '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
$html .= '<div'
. ($orig_auth_plugin != 'sha256_password'
? ' class="hide"'
: '')
. ' id="ssl_reqd_warning_cp">'
. Message::notice(
__(
'This method requires using an \'<i>SSL connection</i>\' '
. 'or an \'<i>unencrypted connection that encrypts the '
. 'password using RSA</i>\'; while connecting to the server.'
)
. Util::showMySQLDocu(
'sha256-authentication-plugin'
)
)
->getDisplay()
. '</div>';
} else {
$html .= '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
}
} else {
$auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
$orig_auth_plugin, 'change_pw', 'old'
);
$html .= '<tr class="vmiddle">'
. '<td>' . __('Password Hashing:') . '</td><td>';
$html .= $auth_plugin_dropdown . '</td></tr>'
. '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
}
$html .= '</fieldset>'
. '<fieldset id="fieldset_change_password_footer" class="tblFooters">'
. '<input type="hidden" name="change_pw" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />'
. '</fieldset>'
. '</form>';
return $html;
}
}

View File

@ -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)
);
}
}

View File

@ -0,0 +1,97 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays git revision
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Display;
use PhpMyAdmin\Core;
use PhpMyAdmin\Response;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Display\GitRevision class
*
* @package PhpMyAdmin
*/
class GitRevision
{
/**
* Prints details about the current Git commit revision
*
* @return void
*/
public static function print()
{
if (! $GLOBALS['PMA_Config']->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 = '<strong title="'
. htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE'))
. '">' . $commit_hash . '</strong>';
if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) {
$commit_hash = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/commit/'
. $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')
)
. '" rel="noopener noreferrer" target="_blank">' . $commit_hash . '</a>';
}
$branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH');
if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) {
$branch = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/tree/'
. $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')
)
. '" rel="noopener noreferrer" target="_blank">' . $branch . '</a>';
}
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 . ',<br /> '
. sprintf(
__('committed on %1$s by %2$s'),
Util::localisedDate(strtotime($committer['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($committer['email'])
) . '">'
. htmlspecialchars($committer['name']) . '</a>'
)
. ($author != $committer
? ', <br />'
. sprintf(
__('authored on %1$s by %2$s'),
Util::localisedDate(strtotime($author['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($author['email'])
) . '">'
. htmlspecialchars($author['name']) . '</a>'
)
: ''),
'li_pma_version_git', null, null, null
);
}
}

View File

@ -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[] */

View File

@ -0,0 +1,141 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Handles plugins that show the upload progress
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin\Display;
use PhpMyAdmin\Core;
/**
* PhpMyAdmin\Display\ImportAjax class
*
* @package PhpMyAdmin
*/
class ImportAjax
{
/**
* Sets up some variables for upload progress
*
* @return array
*/
public static function uploadProgressSetup()
{
/**
* constant for differentiating array in $_SESSION variable
*/
$SESSION_KEY = '__upload_status';
/**
* sets default plugin for handling the import process
*/
$_SESSION[$SESSION_KEY]["handler"] = "";
/**
* unique ID for each upload
*/
$upload_id = uniqid("");
/**
* list of available plugins
*/
$plugins = array(
// PHP 5.4 session-based upload progress is problematic, see bug 3964
//"session",
"progress",
"apc",
"noplugin"
);
// select available plugin
foreach ($plugins as $plugin) {
$check = $plugin . "Check";
if (self::$check()) {
$upload_class = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords(
$plugin
);
$_SESSION[$SESSION_KEY]["handler"] = $upload_class;
break;
}
}
return array($SESSION_KEY, $upload_id, $plugins);
}
/**
* Checks if APC bar extension is available and configured correctly.
*
* @return boolean true if APC extension is available and if rfc1867 is enabled,
* false if it is not
*/
public static function apcCheck()
{
if (! extension_loaded('apc')
|| ! function_exists('apc_fetch')
|| ! function_exists('getallheaders')
) {
return false;
}
return (ini_get('apc.enabled') && ini_get('apc.rfc1867'));
}
/**
* Checks if PhpMyAdmin\Plugins\Import\Upload\UploadProgress bar extension is
* available.
*
* @return boolean true if PhpMyAdmin\Plugins\Import\Upload\UploadProgress
* extension is available, false if it is not
*/
public static function progressCheck()
{
if (! function_exists("uploadprogress_get_info")
|| ! function_exists('getallheaders')
) {
return false;
}
return true;
}
/**
* Checks if PHP 5.4 session upload-progress feature is available.
*
* @return boolean true if PHP 5.4 session upload-progress is available,
* false if it is not
*/
public static function sessionCheck()
{
if (! ini_get('session.upload_progress.enabled')) {
return false;
}
return true;
}
/**
* Default plugin for handling import.
* If no other plugin is available, noplugin is used.
*
* @return boolean true
*/
public static function nopluginCheck()
{
return true;
}
/**
* The function outputs json encoded status of uploaded.
* It uses PMA_getUploadStatus, which is defined in plugin's file.
*
* @param string $id ID of transfer, usually $upload_id
*
* @return void
*/
public static function status($id)
{
Core::headerJSON();
echo json_encode(
$_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)
);
}
}

View File

@ -1,11 +1,11 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Hold the PhpMyAdmin\DisplayResults class
* Hold the PhpMyAdmin\Display\Results class
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin;
namespace PhpMyAdmin\Display;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
@ -30,9 +30,8 @@ use PhpMyAdmin\Util;
*
* @package PhpMyAdmin
*/
class DisplayResults
class Results
{
// Define constants
const NO_EDIT_OR_DELETE = 'nn';
const UPDATE_ROW = 'ur';
@ -219,7 +218,7 @@ class DisplayResults
/**
* Constructor for DisplayResults class
* Constructor for PhpMyAdmin\Display\Results class
*
* @param string $db the database name
* @param string $table the table name
@ -5210,7 +5209,7 @@ class DisplayResults
/**
*
* @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
*/

View File

@ -7,6 +7,7 @@
*/
namespace PhpMyAdmin\Plugins\Import\Upload;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Plugins\UploadInterface;
/**
@ -54,7 +55,7 @@ class UploadApc implements UploadInterface
}
$ret = $_SESSION[$SESSION_KEY][$id];
if (!PMA_Import_apcCheck() || $ret['finished']) {
if (!ImportAjax::apcCheck() || $ret['finished']) {
return $ret;
}
$status = apc_fetch('upload_' . $id);

View File

@ -7,6 +7,7 @@
*/
namespace PhpMyAdmin\Plugins\Import\Upload;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Plugins\UploadInterface;
/**
@ -55,7 +56,7 @@ class UploadProgress implements UploadInterface
}
$ret = $_SESSION[$SESSION_KEY][$id];
if (!PMA_Import_progressCheck() || $ret['finished']) {
if (!ImportAjax::progressCheck() || $ret['finished']) {
return $ret;
}

View File

@ -7,6 +7,7 @@
*/
namespace PhpMyAdmin\Plugins\Import\Upload;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Plugins\UploadInterface;
/**
@ -55,7 +56,7 @@ class UploadSession implements UploadInterface
}
$ret = $_SESSION[$SESSION_KEY][$id];
if (!PMA_Import_sessionCheck() || $ret['finished']) {
if (!ImportAjax::sessionCheck() || $ret['finished']) {
return $ret;
}

View File

@ -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

View File

@ -10,7 +10,7 @@ namespace PhpMyAdmin;
use PhpMyAdmin\Bookmark;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\DisplayResults;
use PhpMyAdmin\Display\Results as DisplayResults;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;

View File

@ -1,154 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays form for password change
*
* @package PhpMyAdmin
*/
use PhpMyAdmin\Message;
use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Url;
/**
* Get HTML for the Change password dialog
*
* @param string $mode where is the function being called?
* values : 'change_pw' or 'edit_other'
* @param string $username username
* @param string $hostname hostname
*
* @return string html snippet
*/
function PMA_getHtmlForChangePassword($mode, $username, $hostname)
{
/**
* autocomplete feature of IE kills the "onchange" event handler and it
* must be replaced by the "onpropertychange" one in this case
*/
$chg_evt_handler = 'onchange';
$is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
$html = '<form method="post" id="change_password_form" '
. 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" '
. 'name="chgPassword" '
. 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
$html .= Url::getHiddenInputs();
if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
$html .= '<input type="hidden" name="username" '
. 'value="' . htmlspecialchars($username) . '" />'
. '<input type="hidden" name="hostname" '
. 'value="' . htmlspecialchars($hostname) . '" />';
}
$html .= '<fieldset id="fieldset_change_password">'
. '<legend'
. ($is_privileges
? ' data-submenu-label="' . __('Change password') . '"'
: ''
)
. '>' . __('Change password') . '</legend>'
. '<table class="data noclick">'
. '<tr>'
. '<td colspan="2">'
. '<input type="radio" name="nopass" value="1" id="nopass_1" '
. 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; '
. 'this.checked = true" />'
. '<label for="nopass_1">' . __('No Password') . '</label>'
. '</td>'
. '</tr>'
. '<tr class="vmiddle">'
. '<td>'
. '<input type="radio" name="nopass" value="0" id="nopass_0" '
. 'onclick="document.getElementById(\'text_pma_change_pw\').focus();" '
. 'checked="checked" />'
. '<label for="nopass_0">' . __('Password:') . '&nbsp;</label>'
. '</td>'
. '<td>'
. __('Enter:') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp'
. '<input type="password" name="pma_pw" id="text_pma_change_pw" size="10" '
. 'class="textfield"'
. $chg_evt_handler . '="nopass[1].checked = true" />'
. '<span>Strength:</span> '
. '<meter max="4" id="change_password_strength_meter" name="pw_meter"></meter> '
. '<span id="change_password_strength" name="pw_strength">Good</span>'
. '<br>' . __('Re-type:') . '&nbsp;'
. '<input type="password" name="pma_pw2" id="text_pma_change_pw2" size="10" '
. 'class="textfield"'
. $chg_evt_handler . '="nopass[1].checked = true" />'
. '</td>'
. '</tr>';
$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 .= '<tr class="vmiddle">'
. '<td>' . __('Password Hashing:') . '</td><td>';
$html .= $auth_plugin_dropdown;
$html .= '</td></tr>'
. '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
$html .= '<div'
. ($orig_auth_plugin != 'sha256_password'
? ' class="hide"'
: '')
. ' id="ssl_reqd_warning_cp">'
. Message::notice(
__(
'This method requires using an \'<i>SSL connection</i>\' '
. 'or an \'<i>unencrypted connection that encrypts the '
. 'password using RSA</i>\'; while connecting to the server.'
)
. PhpMyAdmin\Util::showMySQLDocu(
'sha256-authentication-plugin'
)
)
->getDisplay()
. '</div>';
} else {
$html .= '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
}
} else {
$auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
$orig_auth_plugin, 'change_pw', 'old'
);
$html .= '<tr class="vmiddle">'
. '<td>' . __('Password Hashing:') . '</td><td>';
$html .= $auth_plugin_dropdown . '</td></tr>'
. '<tr id="tr_element_before_generate_password"></tr>'
. '</table>';
}
$html .= '</fieldset>'
. '<fieldset id="fieldset_change_password_footer" class="tblFooters">'
. '<input type="hidden" name="change_pw" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />'
. '</fieldset>'
. '</form>';
return $html;
}

View File

@ -1,87 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays form for password change
*
* @package PhpMyAdmin
*/
use PhpMyAdmin\Core;
use PhpMyAdmin\Response;
/**
* Prints details about the current Git commit revision
*
* @return void
*/
function PMA_printGitRevision()
{
if (! $GLOBALS['PMA_Config']->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 = '<strong title="'
. htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE'))
. '">' . $commit_hash . '</strong>';
if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) {
$commit_hash = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/commit/'
. $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')
)
. '" rel="noopener noreferrer" target="_blank">' . $commit_hash . '</a>';
}
$branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH');
if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) {
$branch = '<a href="'
. Core::linkURL(
'https://github.com/phpmyadmin/phpmyadmin/tree/'
. $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')
)
. '" rel="noopener noreferrer" target="_blank">' . $branch . '</a>';
}
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 . ',<br /> '
. sprintf(
__('committed on %1$s by %2$s'),
PhpMyAdmin\Util::localisedDate(strtotime($committer['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($committer['email'])
) . '">'
. htmlspecialchars($committer['name']) . '</a>'
)
. ($author != $committer
? ', <br />'
. sprintf(
__('authored on %1$s by %2$s'),
PhpMyAdmin\Util::localisedDate(strtotime($author['date'])),
'<a href="' . Core::linkURL(
'mailto:' . htmlspecialchars($author['email'])
) . '">'
. htmlspecialchars($author['name']) . '</a>'
)
: ''),
'li_pma_version_git', null, null, null
);
}

View File

@ -1,137 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Handles plugins that show the upload progress
*
* @package PhpMyAdmin
*/
use PhpMyAdmin\Core;
/**
* Sets up some variables for upload progress
*
* @return array
*
*/
function PMA_uploadProgressSetup()
{
/**
* constant for differentiating array in $_SESSION variable
*/
$SESSION_KEY = '__upload_status';
/**
* sets default plugin for handling the import process
*/
$_SESSION[$SESSION_KEY]["handler"] = "";
/**
* unique ID for each upload
*/
$upload_id = uniqid("");
/**
* list of available plugins
*
* Each plugin has own checkfunction in display_import_ajax.lib.php
* and own file with functions in upload_#KEY#.php
*/
$plugins = array(
// PHP 5.4 session-based upload progress is problematic, see bug 3964
//"session",
"progress",
"apc",
"noplugin"
);
// select available plugin
foreach ($plugins as $plugin) {
$check = "PMA_Import_" . $plugin . "Check";
if ($check()) {
$upload_class = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords(
$plugin
);
$_SESSION[$SESSION_KEY]["handler"] = $upload_class;
break;
}
}
return array($SESSION_KEY, $upload_id, $plugins);
}
/**
* Checks if APC bar extension is available and configured correctly.
*
* @return boolean true if APC extension is available and if rfc1867 is enabled,
* false if it is not
*/
function PMA_Import_apcCheck()
{
if (! extension_loaded('apc')
|| ! function_exists('apc_fetch')
|| ! function_exists('getallheaders')
) {
return false;
}
return (ini_get('apc.enabled') && ini_get('apc.rfc1867'));
}
/**
* Checks if PhpMyAdmin\Plugins\Import\Upload\UploadProgress bar extension is
* available.
*
* @return boolean true if PhpMyAdmin\Plugins\Import\Upload\UploadProgress
* extension is available, false if it is not
*/
function PMA_Import_progressCheck()
{
if (! function_exists("uploadprogress_get_info")
|| ! function_exists('getallheaders')
) {
return false;
}
return true;
}
/**
* Checks if PHP 5.4 session upload-progress feature is available.
*
* @return boolean true if PHP 5.4 session upload-progress is available,
* false if it is not
*/
function PMA_Import_sessionCheck()
{
if (! ini_get('session.upload_progress.enabled')) {
return false;
}
return true;
}
/**
* Default plugin for handling import.
* If no other plugin is available, noplugin is used.
*
* @return boolean true
*/
function PMA_Import_nopluginCheck()
{
return true;
}
/**
* The function outputs json encoded status of uploaded.
* It uses PMA_getUploadStatus, which is defined in plugin's file.
*
* @param string $id ID of transfer, usually $upload_id
* from display_import_ajax.lib.php
*
* @return void
*/
function PMA_importAjaxStatus($id)
{
Core::headerJSON();
echo json_encode(
$_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)
);
}

View File

@ -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();

View File

@ -376,10 +376,7 @@ if ($response->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');

View File

@ -1,31 +1,27 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for display_change_password.lib.php
* tests for PhpMyAdmin\Display\ChangePassword
*
* @package PhpMyAdmin-test
*/
namespace PhpMyAdmin\Tests\Display;
/*
* Include to test.
*/
use PhpMyAdmin\Config;
use PhpMyAdmin\Display\ChangePassword;
use PhpMyAdmin\Theme;
use PhpMyAdmin\Url;
require_once 'libraries/display_change_password.lib.php';
require_once 'libraries/config.default.php';
/**
* class PMA_DisplayChangePassword_Test
* ChangePasswordTest class
*
* this class is for testing display_change_password.lib.php functions
* this class is for testing PhpMyAdmin\Display\ChangePassword functions
*
* @package PhpMyAdmin-test
*/
class PMA_DisplayChangePassword_Test extends PHPUnit_Framework_TestCase
class ChangePasswordTest extends \PHPUnit_Framework_TestCase
{
/**
* Test for setUp
@ -35,7 +31,7 @@ class PMA_DisplayChangePassword_Test extends PHPUnit_Framework_TestCase
public function setUp()
{
//$GLOBALS
$GLOBALS['PMA_Config'] = new PhpMyAdmin\Config();
$GLOBALS['PMA_Config'] = new Config();
$GLOBALS['PMA_Config']->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(

View File

@ -1,31 +1,25 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for display_create_table.lib.php
* tests for PhpMyAdmin\Display\CreateTable
*
* @package PhpMyAdmin-test
*/
namespace PhpMyAdmin\Tests\Display;
use PhpMyAdmin\Display\CreateTable;
use PhpMyAdmin\Theme;
use PhpMyAdmin\Url;
$GLOBALS['server'] = 0;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['cfg']['DBG']['sql'] = false;
/*
* Include to test.
*/
require_once 'libraries/display_create_table.lib.php';
use PhpMyAdmin\Util;
/**
* class PMA_DisplayCreateTable_Test
* PhpMyAdmin\Tests\Display\CreateTableTest class
*
* this class is for testing display_create_table.lib.php functions
* this class is for testing PhpMyAdmin\Display\CreateTable methods
*
* @package PhpMyAdmin-test
*/
class PMA_DisplayCreateTable_Test extends PHPUnit_Framework_TestCase
class CreateTableTest extends \PHPUnit_Framework_TestCase
{
/**
* Test for setUp
@ -36,6 +30,8 @@ class PMA_DisplayCreateTable_Test extends PHPUnit_Framework_TestCase
{
//$GLOBALS
$GLOBALS['server'] = 0;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['cfg']['DBG']['sql'] = false;
$GLOBALS['cfg']['MaxRows'] = 10;
$GLOBALS['cfg']['ServerDefault'] = "PMA_server";
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
@ -52,7 +48,7 @@ class PMA_DisplayCreateTable_Test extends PHPUnit_Framework_TestCase
}
/**
* Test for PMA_getHtmlForCreateTable
* Test for CreateTable::getHtml
*
* @return void
*/
@ -61,11 +57,11 @@ class PMA_DisplayCreateTable_Test extends PHPUnit_Framework_TestCase
$db = "pma_db";
//Call the test function
$html = PMA_getHtmlForCreateTable($db);
$html = CreateTable::getHtml($db);
//getImage
$this->assertContains(
PhpMyAdmin\Util::getImage('b_table_add.png'),
Util::getImage('b_table_add.png'),
$html
);

View File

@ -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)
)
);

View File

@ -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;
/**