Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-12-17 00:08:54 +01:00
commit af666fbd11
6 changed files with 201 additions and 168 deletions

View File

@ -0,0 +1,106 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PMA\libraries\controllers\server\ServerPluginsController
*
* @package PMA\libraries\controllers\server
*/
namespace PMA\libraries\controllers\server;
use PMA\libraries\controllers\Controller;
use PMA\libraries\Template;
/**
* Handles viewing server plugin details
*
* @package PMA\libraries\controllers\server
*/
class ServerPluginsController extends Controller
{
/**
* @var array plugin details
*/
protected $plugins;
/**
* Constructs ServerPluginsController
*/
public function __construct()
{
parent::__construct();
$this->_setServerPlugins();
}
/**
* Index action
*
* @return void
*/
public function indexAction()
{
include 'libraries/server_common.inc.php';
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('jquery/jquery.tablesorter.js');
$scripts->addFile('server_plugins.js');
/**
* Displays the page
*/
$this->response->addHTML(PMA_getHtmlForSubPageHeader('plugins'));
$this->response->addHTML($this->_getPluginsHtml());
}
/**
* Sets details about server plugins
*
* @return void
*/
private function _setServerPlugins()
{
$sql = "SELECT plugin_name,
plugin_type,
(plugin_status = 'ACTIVE') AS is_active,
plugin_type_version,
plugin_author,
plugin_description,
plugin_license
FROM information_schema.plugins
ORDER BY plugin_type, plugin_name";
$res = $this->dbi->query($sql);
$this->plugins = array();
while ($row = $this->dbi->fetchAssoc($res)) {
$this->plugins[$row['plugin_type']][] = $row;
}
$this->dbi->freeResult($res);
ksort($this->plugins);
}
/**
* Returns the html for plugin Tab.
*
* @return string
*/
private function _getPluginsHtml()
{
$html = '<div id="plugins_plugins">';
$html .= Template::get('server/plugins/section_links')
->render(array('plugins' => $this->plugins));
foreach ($this->plugins as $plugin_type => $plugin_list) {
$html .= Template::get('server/plugins/section')
->render(
array(
'plugin_type' => $plugin_type,
'plugin_list' => $plugin_list,
)
);
}
$html .= '</div>';
return $html;
}
}

View File

@ -1,120 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server plugins
*
* @usedby server_plugins.php
*
* @package PhpMyAdmin
*/
/**
* Returns the common SQL used to retrieve plugin data
*
* @return string SQL
*/
function PMA_getServerPluginSQL()
{
return "SELECT plugin_name, plugin_type, (plugin_status = 'ACTIVE') AS is_active,
plugin_type_version, plugin_author, plugin_description, plugin_license
FROM information_schema.plugins
ORDER BY plugin_type, plugin_name";
}
/**
* Returns details about server plugins
*
* @return array server plugins data
*/
function PMA_getServerPlugins()
{
$sql = PMA_getServerPluginSQL();
$res = $GLOBALS['dbi']->query($sql);
$plugins = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
$plugins[$row['plugin_type']][] = $row;
}
$GLOBALS['dbi']->freeResult($res);
ksort($plugins);
return $plugins;
}
/**
* Returns the html for plugin Tab.
*
* @param array $plugins list
*
* @return string
*/
function PMA_getPluginTab($plugins)
{
$html = '<div id="plugins_plugins">';
$html .= '<div id="sectionlinks">';
foreach ($plugins as $plugin_type => $plugin_list) {
$key = 'plugins-'
. preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type));
$html .= '<a href="#' . $key . '">'
. htmlspecialchars($plugin_type) . '</a>' . "\n";
}
$html .= '</div>';
$html .= '<br />';
foreach ($plugins as $plugin_type => $plugin_list) {
$key = 'plugins-'
. preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type));
sort($plugin_list);
$html .= '<table class="data_full_width" id="' . $key . '">';
$html .= '<caption class="tblHeaders">';
$html .= htmlspecialchars($plugin_type);
$html .= '</caption>';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>' . __('Plugin') . '</th>';
$html .= '<th>' . __('Description') . '</th>';
$html .= '<th>' . __('Version') . '</th>';
$html .= '<th>' . __('Author') . '</th>';
$html .= '<th>' . __('License') . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$html .= PMA_getPluginList($plugin_list);
$html .= '</tbody>';
$html .= '</table>';
}
$html .= '</div>';
return $html;
}
/**
* Returns the html for plugin List.
*
* @param array $plugin_list list
*
* @return string
*/
function PMA_getPluginList($plugin_list)
{
$html = "";
$odd_row = false;
foreach ($plugin_list as $plugin) {
$odd_row = !$odd_row;
$html .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
$html .= '<th>';
$html .= htmlspecialchars($plugin['plugin_name']);
if (! $plugin['is_active']) {
$html .= '&nbsp;<small class="attention">' . __('disabled') . '</small>';
}
$html .= '</th>';
$html .= '<td>' . htmlspecialchars($plugin['plugin_description']) . '</td>';
$html .= '<td>' . htmlspecialchars($plugin['plugin_type_version']) . '</td>';
$html .= '<td>' . htmlspecialchars($plugin['plugin_author']) . '</td>';
$html .= '<td>' . htmlspecialchars($plugin['plugin_license']) . '</td>';
$html .= '</tr>';
}
return $html;
}

View File

@ -1,38 +1,32 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* object the server plugin page
* Handles server plugins page.
*
* @package PhpMyAdmin
*/
namespace PMA;
use PMA\libraries\controllers\server\ServerPluginsController;
use PMA\libraries\Response;
/**
* requirements
*/
require_once 'libraries/common.inc.php';
/**
* JS includes
*/
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('jquery/jquery.tablesorter.js');
$scripts->addFile('server_plugins.js');
$container = \PMA\libraries\di\Container::getDefaultContainer();
$container->factory(
'PMA\libraries\controllers\server\ServerPluginsController'
);
$container->alias(
'ServerPluginsController',
'PMA\libraries\controllers\server\ServerPluginsController'
);
$container->set('PMA\libraries\Response', Response::getInstance());
$container->alias('response', 'PMA\libraries\Response');
/**
* Does the common work
*/
require 'libraries/server_common.inc.php';
require 'libraries/server_plugins.lib.php';
$plugins = PMA_getServerPlugins();
/**
* Displays the page
*/
$response->addHTML(PMA_getHtmlForSubPageHeader('plugins'));
$response->addHTML(PMA_getPluginTab($plugins));
exit;
/** @var ServerPluginsController $controller */
$controller = $container->get(
'ServerPluginsController', array()
);
$controller->indexAction();

View File

@ -0,0 +1,33 @@
<table class="data_full_width"
id="plugins-<?php echo preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); ?>">
<caption class="tblHeaders">
<?php echo htmlspecialchars($plugin_type); ?>
</caption>
<thead>
<tr>
<th><?php echo __('Plugin'); ?></th>
<th><?php echo __('Description'); ?></th>
<th><?php echo __('Version'); ?></th>
<th><?php echo __('Author'); ?></th>
<th><?php echo __('License'); ?></th>
</tr>
</thead>
<tbody>
<?php $odd_row = true; ?>
<?php foreach ($plugin_list as $plugin): ?>
<tr class="noclick <?php echo ($odd_row ? 'odd' : 'even'); ?>">
<th>
<?php echo htmlspecialchars($plugin['plugin_name']); ?>
<?php if (! $plugin['is_active']): ?>
<small class="attention"><?php echo __('disabled'); ?></small>
<?php endif; ?>
</th>
<td><?php echo htmlspecialchars($plugin['plugin_description']); ?></td>
<td><?php echo htmlspecialchars($plugin['plugin_type_version']); ?></td>
<td><?php echo htmlspecialchars($plugin['plugin_author']); ?></td>
<td><?php echo htmlspecialchars($plugin['plugin_license']); ?></td>
</tr>
<?php $odd_row = !$odd_row; ?>
<?php endforeach; ?>
</tbody>
</table>

View File

@ -0,0 +1,8 @@
<div id="sectionlinks">
<?php foreach ($plugins as $plugin_type => $plugin_list): ?>
<a href="#plugins-<?php echo preg_replace('/[^a-z]/', '', /*overload*/mb_strtolower($plugin_type)); ?>">
<?php echo htmlspecialchars($plugin_type); ?>
</a>
<?php endforeach; ?>
</div>
<br />

View File

@ -1,7 +1,7 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for server_plugins.lib.php
* Holds ServerPluginsControllerTest class
*
* @package PhpMyAdmin-test
*/
@ -10,22 +10,20 @@
* Include to test.
*/
use PMA\libraries\Theme;
use PMA\libraries\controllers\server\ServerPluginsController;
use PMA\libraries\di\Container;
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/server_plugins.lib.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/js_escape.lib.php';
/**
* PMA_ServerPlugins_Test class
*
* this class is for testing server_plugins.lib.php functions
* Tests for ServerPluginsController class
*
* @package PhpMyAdmin-test
*/
class PMA_ServerPlugins_Test extends PHPUnit_Framework_TestCase
class ServerPluginsControllerTest extends PHPUnit_Framework_TestCase
{
/**
* Prepares environment for the test.
@ -58,26 +56,15 @@ class PMA_ServerPlugins_Test extends PHPUnit_Framework_TestCase
}
/**
* Test for PMA_getPluginAndModuleInfo
* Test for _getPluginsHtml() method
*
* @return void
*/
public function testPMAGetPluginAndModuleInfo()
{
//Mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
//Call the test function
/**
* Prepare plugin list
*/
$plugins = array();
$row = array();
$row["plugin_name"] = "plugin_name1";
$row["plugin_type"] = "plugin_type1";
@ -86,9 +73,34 @@ class PMA_ServerPlugins_Test extends PHPUnit_Framework_TestCase
$row["plugin_license"] = "plugin_license1";
$row["plugin_description"] = "plugin_description1";
$row["is_active"] = true;
$plugins[$row['plugin_type']][] = $row;
$html = PMA_getPluginTab($plugins);
//Mock DBI
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->at(1))
->method('fetchAssoc')
->will($this->returnValue($row));
$dbi->expects($this->at(2))
->method('fetchAssoc')
->will($this->returnValue(false));
$dbi->expects($this->once())
->method('freeResult')
->will($this->returnValue(true));
$container = Container::getDefaultContainer();
$container->set('dbi', $dbi);
$class = new ReflectionClass('\PMA\libraries\controllers\server\ServerPluginsController');
$method = $class->getMethod('_getPluginsHtml');
$method->setAccessible(true);
$ctrl = new ServerPluginsController();
$html = $method->invoke($ctrl);
//validate 1:Items
$this->assertContains(