Permalink
Browse files

Add support for 'actionbuttons' hooks in the plugin architecture.

By Leonardo Sapiras during the GSoC 2011. Reviewed, massively patched,
fixed, integrated and commited by ioguix
  • Loading branch information...
1 parent f5892dd commit 4f77054ad815d1d28e40e38e3c5cc08761e2fbad @leonardosapiras leonardosapiras committed with ioguix Feb 23, 2012
Showing with 1,059 additions and 399 deletions.
  1. +24 −12 admin.php
  2. +23 −7 aggregates.php
  3. +39 −16 all_db.php
  4. +1 −1 casts.php
  5. +52 −32 classes/Misc.php
  6. +1 −1 classes/PluginManager.php
  7. +1 −1 colproperties.php
  8. +14 −5 constraints.php
  9. +1 −1 conversions.php
  10. +26 −10 database.php
  11. +30 −2 display.php
  12. +57 −29 domains.php
  13. +66 −22 fulltext.php
  14. +34 −10 functions.php
  15. +38 −17 groups.php
  16. +25 −9 history.php
  17. +36 −12 indexes.php
  18. +101 −68 info.php
  19. +1 −1 languages.php
  20. +1 −1 opclasses.php
  21. +18 −5 operators.php
  22. +35 −11 reports.php
  23. +21 −7 roles.php
  24. +14 −4 rules.php
  25. +32 −11 schemas.php
  26. +32 −10 sequences.php
  27. +12 −5 servers.php
  28. +93 −29 tables.php
  29. +31 −10 tablespaces.php
  30. +62 −3 tblproperties.php
  31. +49 −17 triggers.php
  32. +12 −5 types.php
  33. +21 −7 users.php
  34. +12 −4 viewproperties.php
  35. +44 −14 views.php
View
@@ -628,23 +628,35 @@ function enlight($f, $p) {
$actions = array(
'edit' => array(
- 'title' => $lang['stredit'],
- 'url' => "{$script}?action=confeditautovac&{$misc->href}&subject={$type}&",
- 'vars' => array(
- 'schema' => 'nspname',
- 'table' => 'relname'
+ 'content' => $lang['stredit'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => $script,
+ 'urlvars' => array (
+ 'subject' => $type,
+ 'action' => 'confeditautovac',
+ 'schema' => field('nspname'),
+ 'table' => field('relname')
+ )
+ )
)
),
'delete' => array(
- 'title' => $lang['strdelete'],
- 'url' => "{$script}?action=confdelautovac&{$misc->href}&subject={$type}&",
- 'vars' => array(
- 'schema' => 'nspname',
- 'table' => 'relname'
+ 'content' => $lang['strdelete'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => $script,
+ 'urlvars' => array (
+ 'subject' => $type,
+ 'action' => 'confdelautovac',
+ 'schema' => field('nspname'),
+ 'table' => field('relname')
+ )
+ )
)
)
);
-
+
if ($type == 'table') {
unset($actions['edit']['vars']['schema'],
$actions['delete']['vars']['schema'],
@@ -653,7 +665,7 @@ function enlight($f, $p) {
);
}
- $misc->printTable($autovac, $columns, $actions, $lang['strnovacuumconf']);
+ $misc->printTable($autovac, $columns, $actions, 'admin-admin', $lang['strnovacuumconf']);
if (($type == 'table') and ($autovac->recordCount() == 0)) {
echo "<br />";
View
@@ -344,19 +344,35 @@ function doDefault($msg = '') {
$actions = array(
'alter' => array(
- 'title' => $lang['stralter'],
- 'url' => "aggregates.php?action=alter&amp;{$misc->href}&amp;",
- 'vars' => array('aggrname' => 'proname', 'aggrtype' => 'proargtypes'),
+ 'content' => $lang['stralter'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'aggregates.php',
+ 'urlvars' => array (
+ 'action' => 'alter',
+ 'aggrname' => field('proname'),
+ 'aggrtype' => field('proargtypes')
+ )
+ )
+ )
),
'drop' => array(
- 'title' => $lang['strdrop'],
- 'url' => "aggregates.php?action=confirm_drop&amp;{$misc->href}&amp;",
- 'vars' => array('aggrname' => 'proname', 'aggrtype' => 'proargtypes'),
+ 'content' => $lang['strdrop'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'aggregates.php',
+ 'urlvars' => array (
+ 'action' => 'confirm_drop',
+ 'aggrname' => field('proname'),
+ 'aggrtype' => field('proargtypes')
+ )
+ )
+ )
)
);
if (!$data->hasAlterAggregate()) unset($actions['alter']);
- $misc->printTable($aggregates, $columns, $actions, $lang['strnoaggregates']);
+ $misc->printTable($aggregates, $columns, $actions, 'aggregates-aggregates', $lang['strnoaggregates']);
$navlinks = array (
array (
View
@@ -393,36 +393,59 @@ function doDefault($msg = '') {
$actions = array(
'multiactions' => array(
- 'keycols' => array('database' => 'datname'),
- 'url' => 'all_db.php',
- 'default' => null,
+ 'keycols' => array('database' => 'datname'),
+ 'url' => 'all_db.php',
+ 'default' => null,
),
'drop' => array(
- 'title' => $lang['strdrop'],
- 'url' => "all_db.php?action=confirm_drop&amp;subject=database&amp;{$misc->href}&amp;",
- 'vars' => array('dropdatabase' => 'datname'),
- 'multiaction' => 'confirm_drop',
+ 'content' => $lang['strdrop'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'all_db.php',
+ 'urlvars' => array (
+ 'subject' => 'database',
+ 'action' => 'confirm_drop',
+ 'dropdatabase' => field('datname')
+ )
+ )
+ ),
+ 'multiaction' => 'confirm_drop',
),
'privileges' => array(
- 'title' => $lang['strprivileges'],
- 'url' => "privileges.php?subject=database&amp;{$misc->href}&amp;",
- 'vars' => array('database' => 'datname'),
+ 'content' => $lang['strprivileges'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'privileges.php',
+ 'urlvars' => array (
+ 'subject' => 'database',
+ 'database' => field('datname')
+ )
+ )
+ )
)
);
if ($data->hasAlterDatabase() ) {
- $actions['alter'] = array(
- 'title' => $lang['stralter'],
- 'url' => "all_db.php?action=confirm_alter&amp;subject=database&amp;{$misc->href}&amp;",
- 'vars' => array('alterdatabase' => 'datname')
- );
+ $actions['alter'] = array(
+ 'content' => $lang['stralter'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'all_db.php',
+ 'urlvars' => array (
+ 'subject' => 'database',
+ 'action' => 'confirm_alter',
+ 'alterdatabase' => field('datname')
+ )
+ )
+ )
+ );
}
if (!$data->hasTablespaces()) unset($columns['tablespace']);
if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']);
if (!$data->hasDatabaseCollation()) unset($columns['lc_collate'], $columns['lc_ctype']);
if (!isset($data->privlist['database'])) unset($actions['privileges']);
- $misc->printTable($databases, $columns, $actions, $lang['strnodatabases']);
+ $misc->printTable($databases, $columns, $actions, 'all_db-databases', $lang['strnodatabases']);
$navlinks = array (
array (
View
@@ -62,7 +62,7 @@ function renderCastContext($val) {
$actions = array();
- $misc->printTable($casts, $columns, $actions, $lang['strnocasts']);
+ $misc->printTable($casts, $columns, $actions, 'casts-casts', $lang['strnocasts']);
}
/**
View
@@ -594,35 +594,46 @@ function printReload($database) {
}
/**
- * Display a list of links
- * @param $links An associative array of links to print
- * links = array(
+ * Display a link
+ * @param $link An associative array of link parameters to print
+ * link = array(
* 'attr' => array( // list of A tag attribute
* 'attrname' => attribute value
* ...
* ),
* 'content' => The link text
- * 'fields' => the data from which content and attr's values are obtained
+ * 'fields' => (optionnal) the data from which content and attr's values are obtained
* );
* the special attribute 'href' might be a string or an array. If href is an array it
* will be generated by getActionUrl. See getActionUrl comment for array format.
+ */
+ function printLink($link) {
+ $tag = "<a ";
+ foreach ($link['attr'] as $attr => $value) {
+ if ($attr == 'href' and is_array($value)) {
+ $tag.= 'href="'. htmlentities($this->getActionUrl($value, $link['fields'])).'" ';
+ }
+ else {
+ $tag.= htmlentities($attr).'="'. value($value, $link['fields'], 'html') .'" ';
+ }
+ }
+ $tag.= ">". value($link['content'], $link['fields'], 'html') ."</a>\n";
+ echo $tag;
+ }
+
+ /**
+ * Display a list of links
+ * @param $links An associative array of links to print. See printLink function for
+ * the links array format.
* @param $class An optional class or list of classes seprated by a space
* WARNING: This field is NOT escaped! No user should be able to inject something here, use with care.
*/
function printLinksList($links, $class='') {
echo "<ul class=\"{$class}\">\n";
foreach ($links as $link) {
- $tag = "\t<li><a ";
- foreach ($link['attr'] as $attr => $value) {
- if ($attr == 'href' and is_array($value)) {
- $tag.= 'href="'. htmlentities($this->getActionUrl($value, $link['fields'])).'" ';
- }
- else {
- $tag.= htmlentities($attr).'="'. value($value, $link['fields'], 'html') .'" ';
- }
- }
- $tag.= ">". value($link['content'], $link['fields'], 'html') ."</a></li>\n";
- echo $tag;
+ echo "\t<li>";
+ $this->printLink($link);
+ echo "</li>\n";
}
echo "</ul>\n";
}
@@ -1723,15 +1734,18 @@ function getActionUrl(&$action, &$fields) {
$urlvars = array();
}
- if (isset($urlvars['subject'])) {
+ /* set server, database and schema parameter if not presents */
+ if (isset($urlvars['subject']))
$subject = value($urlvars['subject'], $fields);
- if (isset($_REQUEST['server']) && $subject != 'root') {
- $urlvars['server'] = $_REQUEST['server'];
- if (isset($_REQUEST['database']) && $subject != 'server') {
- $urlvars['database'] = $_REQUEST['database'];
- if (isset($_REQUEST['schema']) && $subject != 'database') {
- $urlvars['schema'] = $_REQUEST['schema'];
- }
+ else
+ $subject = '';
+
+ if (isset($_REQUEST['server']) and !isset($urlvars['server']) and $subject != 'root') {
+ $urlvars['server'] = $_REQUEST['server'];
+ if (isset($_REQUEST['database']) and !isset($urlvars['database']) and $subject != 'server') {
+ $urlvars['database'] = $_REQUEST['database'];
+ if (isset($_REQUEST['schema']) and !isset($urlvars['schema']) and $subject != 'database') {
+ $urlvars['schema'] = $_REQUEST['schema'];
}
}
}
@@ -1798,6 +1812,8 @@ function printUrlVars(&$vars, &$fields) {
* Add this action to the multi action form
* ), ...
* );
+ * @param $place Place where the $actions are displayed. Like 'display-browse', where 'display' is the file (display.php)
+ * and 'browse' is the place inside that code (doBrowse).
* @param $nodata (optional) Message to display if data set is empty.
* @param $pre_fn (optional) Name of a function to call for each row,
* it will be passed two params: $rowdata and $actions,
@@ -1808,8 +1824,15 @@ function printUrlVars(&$vars, &$fields) {
* The function must not must not store urls because
* they are relative and won't work out of context.
*/
- function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) {
- global $data, $conf, $misc, $lang;
+ function printTable(&$tabledata, &$columns, &$actions, $place, $nodata = null, $pre_fn = null) {
+ global $data, $conf, $misc, $lang, $plugin_manager;
+
+ // Action buttons hook's place
+ $plugin_functions_parameters = array(
+ 'actionbuttons' => &$actions,
+ 'place' => $place
+ );
+ $plugin_manager->do_hook('actionbuttons', $plugin_functions_parameters);
if ($has_ma = isset($actions['multiactions']))
$ma = $actions['multiactions'];
@@ -1887,12 +1910,9 @@ function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn =
echo "<td></td>\n";
} else {
echo "<td class=\"opbutton{$id}\">";
- echo "<a href=\"{$action['url']}";
- if ($action['url'] === '') echo '?';
- $misc->printUrlVars($action['vars'], $tabledata->fields);
- if (isset($action['target']))
- echo "\" target=\"{$action['target']}";
- echo "\">{$action['title']}</a></td>\n";
+ $action['fields'] = $tabledata->fields;
+ $this->printLink($action);
+ echo "</td>\n";
}
}
break;
@@ -1943,7 +1963,7 @@ function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn =
echo "\t\t<option value=\"\">--</option>\n";
foreach($actions as $k => $a)
if (isset($a['multiaction']))
- echo "\t\t<option value=\"{$a['multiaction']}\"", ($ma['default'] == $k? ' selected="selected"': ''), ">{$a['title']}</option>\n";
+ echo "\t\t<option value=\"{$a['multiaction']}\"", ($ma['default'] == $k? ' selected="selected"': ''), ">{$a['content']}</option>\n";
echo "\t</select>\n";
echo "<input type=\"submit\" value=\"{$lang['strexecute']}\" />\n";
echo $misc->form;
@@ -10,7 +10,7 @@ class PluginManager {
* Attributes
*/
private $plugins_list = array();
- private $available_hooks = array('toplinks', 'tabs', 'trail', 'navlinks' /* wip, more hooks to come in next commits */);
+ private $available_hooks = array('toplinks', 'tabs', 'trail', 'navlinks', 'actionbuttons' /* wip, more hooks to come in next commits */);
private $actions = array();
private $hooks = array();
View
@@ -226,7 +226,7 @@ function attPre(&$rowdata) {
}
$actions=array();
- $misc->printTable($attrs, $column, $actions, null, 'attPre');
+ $misc->printTable($attrs, $column, $actions, 'colproperties-colproperties', null, 'attPre');
echo "<br />\n";
View
@@ -464,13 +464,22 @@ function cnPre(&$rowdata) {
$actions = array(
'drop' => array(
- 'title' => $lang['strdrop'],
- 'url' => "constraints.php?action=confirm_drop&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
- 'vars' => array('constraint' => 'conname', 'type' => 'contype'),
- ),
+ 'content' => $lang['strdrop'],
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'constraints.php',
+ 'urlvars' => array (
+ 'action' => 'confirm_drop',
+ 'table' => $_REQUEST['table'],
+ 'constraint' => field('conname'),
+ 'type' => field('contype')
+ )
+ )
+ )
+ )
);
- $misc->printTable($constraints, $columns, $actions, $lang['strnoconstraints'], 'cnPre');
+ $misc->printTable($constraints, $columns, $actions, 'constraints-constraints', $lang['strnoconstraints'], 'cnPre');
$navlinks = array (
array (
View
@@ -51,7 +51,7 @@ function doDefault($msg = '') {
$actions = array();
- $misc->printTable($conversions, $columns, $actions, $lang['strnoconversions']);
+ $misc->printTable($conversions, $columns, $actions, 'conversions-conversions', $lang['strnoconversions']);
}
/**
Oops, something went wrong.

0 comments on commit 4f77054

Please sign in to comment.