function db_query($sql, $print = 0) { global $conn; if ($print) { print "<br>Query is: {$sql}<br>"; } return db_query_params($sql, array()); }
/** * getRolesId - Get the roles of the group. * * @return array Role ids of this group. */ function getRolesId() { $role_ids = array(); if (USE_PFO_RBAC) { $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1', array($this->getID())); while ($arr = db_fetch_array($res)) { $role_ids[] = $arr['role_id']; } $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1', array($this->getID())); while ($arr = db_fetch_array($res)) { $role_ids[] = $arr['role_id']; } } else { $res = db_query_params('SELECT role_id FROM role WHERE group_id=$1', array($this->getID())); while ($arr = db_fetch_array($res)) { $role_ids[] = $arr['role_id']; } } return array_unique($role_ids); }
function CallHook($hookname, &$params) { if (isset($params['group_id'])) { $group_id = $params['group_id']; } elseif (isset($params['group'])) { $group_id = $params['group']; } else { $group_id = null; } if ($hookname == "groupmenu") { $project = group_get_object($group_id); if (!$project || !is_object($project)) { return; } if ($project->isError()) { return; } if (!$project->isProject()) { return; } if ($project->usesPlugin($this->name)) { $params['TITLES'][] = $this->text; $params['DIRS'][] = util_make_url('/plugins/mediawiki/wiki/' . $project->getUnixName() . '/index.php'); $params['ADMIN'][] = ''; $params['TOOLTIPS'][] = _('Mediawiki Space'); } $params['toptab'] == $this->name ? $params['selected'] = count($params['TITLES']) - 1 : ''; } elseif ($hookname == "groupisactivecheckbox") { //Check if the group is active // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin $group = group_get_object($group_id); echo "<tr>"; echo "<td>"; echo ' <input type="checkbox" name="use_mediawikiplugin" value="1" '; // checked or unchecked? if ($group->usesPlugin($this->name)) { echo "checked"; } echo " /><br/>"; echo "</td>"; echo "<td>"; echo "<strong>Use " . $this->text . " Plugin</strong>"; echo "</td>"; echo "</tr>"; } elseif ($hookname == "groupisactivecheckboxpost") { // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page $group = group_get_object($group_id); $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin'); if ($use_mediawikiplugin == 1) { $group->setPluginUse($this->name); } else { $group->setPluginUse($this->name, false); } } elseif ($hookname == "project_public_area") { $project = group_get_object($group_id); if (!$project || !is_object($project)) { return; } if ($project->isError()) { return; } if (!$project->isProject()) { return; } if ($project->usesPlugin($this->name)) { echo '<div class="public-area-box">'; print '<a href="' . util_make_url('/plugins/mediawiki/wiki/' . $project->getUnixName() . '/index.php') . '">'; print html_abs_image(util_make_url('/plugins/mediawiki/wiki/' . $project->getUnixName() . '/skins/fusionforge/wiki.png'), '20', '20', array('alt' => 'Mediawiki')); print ' Mediawiki'; print '</a>'; echo '</div>'; } } elseif ($hookname == "role_get") { $role =& $params['role']; // Read access $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_read'); $right->SetAllowedValues(array('0', '1')); $right->SetDefaultValues(array('Admin' => '1', 'Senior Developer' => '1', 'Junior Developer' => '1', 'Doc Writer' => '1', 'Support Tech' => '1')); // Edit privileges $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_edit'); $right->SetAllowedValues(array('0', '1', '2', '3')); $right->SetDefaultValues(array('Admin' => '3', 'Senior Developer' => '2', 'Junior Developer' => '1', 'Doc Writer' => '3', 'Support Tech' => '0')); // File upload privileges $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_upload'); $right->SetAllowedValues(array('0', '1', '2')); $right->SetDefaultValues(array('Admin' => '2', 'Senior Developer' => '2', 'Junior Developer' => '1', 'Doc Writer' => '2', 'Support Tech' => '0')); // Administrative tasks $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_admin'); $right->SetAllowedValues(array('0', '1')); $right->SetDefaultValues(array('Admin' => '1', 'Senior Developer' => '0', 'Junior Developer' => '0', 'Doc Writer' => '0', 'Support Tech' => '0')); } elseif ($hookname == "role_normalize") { $role =& $params['role']; $new_sa =& $params['new_sa']; $new_pa =& $params['new_pa']; $projects = $role->getLinkedProjects(); foreach ($projects as $p) { $role->normalizePermsForSection($new_pa, 'plugin_mediawiki_read', $p->getID()); $role->normalizePermsForSection($new_pa, 'plugin_mediawiki_edit', $p->getID()); $role->normalizePermsForSection($new_pa, 'plugin_mediawiki_upload', $p->getID()); $role->normalizePermsForSection($new_pa, 'plugin_mediawiki_admin', $p->getID()); } } elseif ($hookname == "role_translate_strings") { $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_read'); $right->setDescription(_('Mediawiki read access')); $right->setValueDescriptions(array('0' => _('No reading'), '1' => _('Read access'))); $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_edit'); $right->setDescription(_('Mediawiki write access')); $right->setValueDescriptions(array('0' => _('No editing'), '1' => _('Edit existing pages only'), '2' => _('Edit and create pages'), '3' => _('Edit, create, move, delete pages'))); $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_upload'); $right->setDescription(_('Mediawiki file upload')); $right->setValueDescriptions(array('0' => _('No uploading'), '1' => _('Upload permitted'), '2' => _('Upload and re-upload'))); $right = new PluginSpecificRoleSetting($role, 'plugin_mediawiki_admin'); $right->setDescription(_('Mediawiki administrative tasks')); $right->setValueDescriptions(array('0' => _('No administrative access'), '1' => _('Edit interface, import XML dumps'))); } elseif ($hookname == "role_get_setting") { $role = $params['role']; $reference = $params['reference']; $value = $params['value']; switch ($params['section']) { case 'plugin_mediawiki_read': if ($role->hasPermission('project_admin', $reference)) { $params['result'] = 1; } else { $params['result'] = $value; } break; case 'plugin_mediawiki_edit': if ($role->hasPermission('project_admin', $reference)) { $params['result'] = 3; } else { $params['result'] = $value; } break; case 'plugin_mediawiki_upload': if ($role->hasPermission('project_admin', $reference)) { $params['result'] = 2; } else { $params['result'] = $value; } break; case 'plugin_mediawiki_admin': if ($role->hasPermission('project_admin', $reference)) { $params['result'] = 1; } else { $params['result'] = $value; } break; } } elseif ($hookname == "role_has_permission") { $value = $params['value']; switch ($params['section']) { case 'plugin_mediawiki_read': switch ($params['action']) { case 'read': default: $params['result'] |= $value >= 1; break; } break; case 'plugin_mediawiki_edit': switch ($params['action']) { case 'editexisting': $params['result'] |= $value >= 1; break; case 'editnew': $params['result'] |= $value >= 2; break; case 'editmove': $params['result'] |= $value >= 3; break; } break; case 'plugin_mediawiki_upload': switch ($params['action']) { case 'upload': $params['result'] |= $value >= 1; break; case 'reupload': $params['result'] |= $value >= 2; break; } break; case 'plugin_mediawiki_admin': switch ($params['action']) { case 'admin': default: $params['result'] |= $value >= 1; break; } break; } } elseif ($hookname == "list_roles_by_permission") { switch ($params['section']) { case 'plugin_mediawiki_read': switch ($params['action']) { case 'read': default: $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1'); break; } break; case 'plugin_mediawiki_edit': switch ($params['action']) { case 'editexisting': $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1'); break; case 'editnew': $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 2'); break; case 'editmove': $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 3'); break; } break; case 'plugin_mediawiki_upload': switch ($params['action']) { case 'upload': $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1'); break; case 'reupload': $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 2'); break; } break; case 'plugin_mediawiki_admin': switch ($params['action']) { case 'admin': default: $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1'); break; } break; } } elseif ($hookname == "project_admin_plugins") { $group_id = $params['group_id']; $group = group_get_object($group_id); if ($group->usesPlugin($this->name)) { echo util_make_link("/plugins/mediawiki/plugin_admin.php?group_id=" . $group->getID(), _("MediaWiki Plugin admin")) . "<br />"; } } elseif ($hookname == "clone_project_from_template") { $template = $params['template']; $project = $params['project']; $id_mappings = $params['id_mappings']; $sections = array('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin'); foreach ($template->getRoles() as $oldrole) { $newrole = RBACEngine::getInstance()->getRoleById($id_mappings['role'][$oldrole->getID()]); $oldsettings = $oldrole->getSettingsForProject($template); foreach ($sections as $section) { if (isset($oldsettings[$section][$template->getID()])) { $newrole->setSetting($section, $project->getID(), $oldsettings[$section][$template->getID()]); } } } } elseif ($hookname == 'group_delete') { $projectId = $params['group_id']; $projectObject = group_get_object($projectId); if ($projectObject->usesPlugin($this->name)) { //delete the files and db schema $schema = 'plugin_mediawiki_' . $projectObject->getUnixName(); // Sanitize schema name $schema = strtr($schema, "-", "_"); db_query_params('drop schema $1 cascade', array($schema)); exec('/bin/rm -rf ' . forge_get_config('projects_path', 'mediawiki') . '/' . $projectObject->getUnixName()); } } }
* * You should have received a copy of the GNU General Public License along * with FusionForge; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** This script will automatically dump Mediawiki databases to an XML file. * * It is intended to be started in a cronjob. */ require_once dirname(__FILE__) . '/../../../www/env.inc.php'; require_once $gfcommon . 'include/pre.php'; require_once $gfcommon . 'include/cron_utils.php'; $src_path = forge_get_config('src_path', 'mediawiki'); $master_path = forge_get_config('master_path', 'mediawiki'); // Get all projects that use the mediawiki plugin $project_res = db_query_params("SELECT g.unix_group_name,g.group_id from groups g, group_plugin gp, plugins p where g.group_id = gp.group_id and gp.plugin_id = p.plugin_id and p.plugin_name = \$1;", array("mediawiki")); if (!$project_res) { $err = "Error: Database Query Failed: " . db_error(); cron_debug($err); cron_entry(23, $err); exit; } // Loop over all projects that use the plugin while ($row = db_fetch_array($project_res)) { $project = $row['unix_group_name']; $project_id = $row['group_id']; $dump_file = forge_get_config('data_path') . "/plugins/mediawiki/dumps/{$project}.xml"; $ra = RoleAnonymous::getInstance(); if ($ra->hasPermission('plugin_mediawiki_read', $project_id)) { cron_debug("Dumping {$project}..."); $mwwrapper = forge_get_config('source_path') . "/plugins/mediawiki/bin/mw-wrapper.php";
exit(0); } require_once dirname(__FILE__) . '/../../../www/env.inc.php'; require_once $gfcommon . 'include/pre.php'; $projects_path = forge_get_config('projects_path', 'mediawiki'); array_shift($argv); foreach ($argv as $project) { echo "Removing project wiki of {$project}.\n"; $project_dir = "{$projects_path}/{$project}"; echo " Deleting project subdir {$project_dir}.\n"; if (!is_dir($project_dir)) { echo "{$project_dir} does not exist!\n"; } else { system("rm -rf {$project_dir}"); } $schema = "plugin_mediawiki_{$project}"; strtr($schema, "-", "_"); echo " Dropping database schema {$schema}.\n"; $res = db_query_params("DROP SCHEMA {$schema} CASCADE", array()); if (!$res) { echo db_error(); } $res = db_query_params('DELETE FROM plugin_mediawiki_interwiki WHERE iw_prefix=$1', array($project)); if (!$res) { echo db_error(); } } // Local Variables: // mode: php // c-file-style: "bsd" // End:
/** * */ function getDropRules() { if (!$this->drop_rules) { $res = db_query_params('SELECT * FROM plugin_taskboard_columns_sources WHERE target_taskboard_column_id=$1', array($this->getID())); if (!$res) { $this->setError('TaskBoardColumn: cannot get drop rules'); return false; } $this->drop_rules = array(); while ($row = db_fetch_array($res)) { if ($row['source_taskboard_column_id']) { $this->drop_rules[$row['source_taskboard_column_id']] = taskboard_column_source_get_object($row['source_taskboard_column_id'], $row['target_taskboard_column_id'], $row); } else { // drop rule by default $this->drop_rules['*'] = taskboard_default_column_source_get_object($row['target_taskboard_column_id'], $row); if (!$this->drop_rules_by_default) { $this->drop_rules_by_default = $this->drop_rules['*']; } } } db_free_result($res); } return $this->drop_rules; }
function ffmw_wrapper_fixup_searchpath($username) { db_query_params("ALTER ROLE {$username} SET search_path = public", array()); }
public static function getInstance() { if (isset(self::$_instance)) { return self::$_instance; } $c = __CLASS__; self::$_instance = new $c(); $res = db_query_params('SELECT r.role_id FROM pfo_role r, pfo_role_class c WHERE r.role_class = c.class_id AND c.class_name = "$1"', array('PFO_RoleLoggedIn')); if (!$res || !db_numrows($res)) { throw new Exception("No PFO_RoleLoggedIn role in the database"); } self::$_instance->_role_id = db_result($res, 0, 'role_id'); $hook_params = array(); $hook_params['role'] =& self::$_instance; plugin_hook("role_get", $hook_params); self::$_instance->fetchData(self::$_instance->_role_id); return self::$_instance; }
private function createDatabase($mediawiki_path) { $schema = strtr('plugin_mediawiki_' . $this->project_id, '-', '_'); $table_file = $mediawiki_path . '/maintenance/tables.sql'; $main_db = ForgeConfig::get('sys_dbname'); db_query('START TRANSACTION;'); try { $this->logger->info('Creating schema ' . $schema); $create_db = db_query_params('CREATE SCHEMA ' . $schema, array()); if (!$create_db) { throw new Exception('Error: Schema Creation Failed: ' . db_error()); } $this->logger->info('Updating mediawiki database.'); if (!file_exists($table_file)) { throw new Exception('Error: Couldn\'t find Mediawiki Database Creation File ' . $table_file); } $this->logger->info('Using schema: ' . $schema); $use_new_schema = db_query('USE ' . $schema); if (!$use_new_schema) { throw new Exception('Error: DB Query Failed: ' . db_error()); } $this->logger->info('Running db_query_from_file(' . $table_file . ')'); $add_tables = db_query_from_file($table_file); if (!$add_tables) { throw new Exception('Error: Mediawiki Database Creation Failed: ' . db_error()); } $this->logger->info('Updating list of mediawiki databases (' . $schema . ')'); db_query('USE ' . $main_db); $update = $this->dao->addDatabase($schema, $this->project_id); if (!$update) { throw new Exception('Error: Mediawiki Database list update failed: ' . mysql_error()); } } catch (Exception $e) { db_query('ROLLBACK;'); $this->logger->error($e->getMessage()); } db_query('COMMIT;'); $this->logger->info('Using schema: ' . $main_db); db_query('USE ' . $main_db); }
$err = "Error: DB Query Failed: " . db_error(); cron_debug($err); cron_entry(23, $err); db_rollback(); exit; } $creation_query = file_get_contents($table_file); $res = db_query_from_file($table_file); if (!$res) { $err = "Error: Mediawiki Database Creation Failed: " . db_error(); cron_debug($err); cron_entry(23, $err); db_rollback(); exit; } $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION {$schema}.default ( COPY = pg_catalog.english )", array()); if (!$res) { $err = "Error: DB Query Failed: " . db_error(); cron_debug($err); cron_entry(23, $err); db_rollback(); exit; } $dao = new MediawikiDao(); $update = $dao->addDatabase($schema, $this->project_id); if (!$update) { $err = 'Error: Mediawiki Database list update failed: (' . $schema . ':' . $this->project_id . ')' . mysql_error(); cron_debug($err); cron_entry(23, $err); db_rollback(); exit;
function save($target_resolution, $alert = '', $autoassign = 0) { if ($this->getSourceColumnID()) { $source_column_id = intval($this->getSourceColumnID()); $wsql = ' AND source_taskboard_column_id = ' . $source_column_id; } else { $source_column_id = 'NULL'; $wsql = ' AND source_taskboard_column_id is NULL'; } $res = db_query_params('SELECT * FROM plugin_taskboard_columns_sources WHERE target_taskboard_column_id=$1' . $wsql, array($this->getTargetColumnID())); if (!$res) { $this->setError('TaskBoardColumnSource: cannot save drop rule'); return false; } $row = db_fetch_array($res); if ($row) { // update rule $res = db_query_params("UPDATE plugin_taskboard_columns_sources SET target_resolution=\$1, alert=\$2, autoassign=\$3\n\t\t\t\tWHERE taskboard_column_source_id=\$4", array($target_resolution, $alert, $autoassign, $row['taskboard_column_source_id'])); } else { // insert rule $res = db_query_params("INSERT INTO plugin_taskboard_columns_sources(target_taskboard_column_id, source_taskboard_column_id, target_resolution, alert, autoassign) \n\t\t\t\tVALUES(\$1,{$source_column_id},\$2,\$3,\$4)", array($this->getTargetColumnID(), $target_resolution, $alert, $autoassign)); } if (!$res) { $this->setError('TaskBoardColumnSource: cannot save drop rule'); } }
/** * addColumn - add taskboard column * * @return boolean */ function addColumn($title, $title_bg_color, $column_bg_color, $max_tasks) { $res = db_query_params('SELECT COUNT(*) as count FROM plugin_taskboard_columns WHERE taskboard_id=$1', array($this->getID())); if (!$res) { return false; } $row = db_fetch_array($res); $order = intval($row['count']) + 1; db_free_result($res); $res = db_query_params('INSERT INTO plugin_taskboard_columns(taskboard_id, title, title_background_color, column_background_color, max_tasks, order_num) VALUES($1,$2,$3,$4,$5,$6)', array($this->getID(), $title, $title_bg_color, $column_bg_color, intval($max_tasks), $order)); if (!$res) { return false; } db_free_result($res); return true; }
/** * Update existing task artifact * * @param integer group artifact identifier (primary key) * @param integer identifier of assigned person * @param string resolution value (name) * @param string artifact summary * @param string artifact description * * @return string error message in case of fail */ function updateTask(&$artifact, $assigned_to, $resolution, $title = NULL, $description = NULL) { if (!$assigned_to) { $assigned_to = $artifact->getAssignedTo(); } $tracker_id = $artifact->ArtifactType->getID(); $extra_fields = $artifact->getExtraFieldData(); $fields_ids = $this->getFieldsIds($tracker_id); if (array_key_exists('resolution', $fields_ids)) { $elements = $this->getExtraFieldValues($tracker_id, 'resolution'); $resolution_field_id = $fields_ids['resolution']; if (array_key_exists($resolution, $elements)) { $extra_fields[$resolution_field_id] = $elements[$resolution]; } } if (!$title) { $title = htmlspecialchars_decode($artifact->getSummary()); } if (!$description) { $description = htmlspecialchars_decode($artifact->getDetails()); } $ret = $artifact->update($artifact->getPriority(), $artifact->getStatusId(), $assigned_to, $title, 100, '', $tracker_id, $extra_fields, $description); $user_id = user_getid(); if ($ret && $user_id == $assigned_to) { //$ret = $artifact->assignToMe(); $res = db_query_params('UPDATE artifact SET assigned_to=$1 WHERE artifact_id=$2', array($user_id, $artifact->getID())); if (!$res) { return 'Error updating assigned_to in artifact: ' . db_error(); } } if (!$ret) { return $artifact->getErrorMessage(); } return ''; }
public function getRoleById($role_id) { if (array_key_exists($role_id, $this->_cached_roles)) { return $this->_cached_roles[$role_id]; } if (USE_PFO_RBAC) { $res = db_query_params('SELECT c.class_name, r.home_group_id FROM pfo_role r, pfo_role_class c WHERE r.role_class = c.class_id AND r.role_id = $1', array($role_id)); if (!$res || !db_numrows($res)) { return NULL; } $class_id = db_result($res, 0, 'class_name'); switch ($class_id) { case 'PFO_RoleExplicit': $group_id = db_result($res, 0, 'home_group_id'); $group = group_get_object($group_id); $this->_cached_roles[$role_id] = new Role($group, $role_id); return $this->_cached_roles[$role_id]; case 'PFO_RoleAnonymous': $this->_cached_roles[$role_id] = RoleAnonymous::getInstance(); return $this->_cached_roles[$role_id]; case 'PFO_RoleLoggedIn': $this->_cached_roles[$role_id] = RoleLoggedIn::getInstance(); return $this->_cached_roles[$role_id]; default: throw new Exception("Not implemented"); } } else { $res = db_query_params('SELECT group_id FROM role r WHERE role_id = $1', array($role_id)); if (!$res || !db_numrows($res)) { return NULL; } $group_id = db_result($res, 0, 'group_id'); $group = group_get_object($group_id); return new Role($group, $role_id); } }
/** * @deprecated Fusionforge only. Please do not use it in Codendi */ public function fetchEvents($offset = 0, $limit = 10, $full = false, $filter_status = false, $filter_type = false, $filter_params = false) { $results = db_query_params('SELECT * FROM system_event WHERE type IN ($1) AND status IN($2) AND parameters=$3;', array($filter_type, $filter_status, $filter_params)); while ($row = db_fetch_array($results)) { $events[] = $row; } if (isset($events)) { return $events; } else { return null; } }