/** * Rename an existing family tree * * @param unknown_type $args user, name, newname * @return FTE_SUCCESS, FTE_INVALID_ARG, FTE_NOT_LOGGED_IN, FTE_NOT_AUTHORIZED, FTE_NOT_FOUND, FTE_DUP_KEY, FTE_DB_ERROR */ function wfRenameFamilyTree($args) { global $wgAjaxCachePolicy, $wgUser; // set cache policy $wgAjaxCachePolicy->setPolicy(0); // validate input arguments $status = FTE_SUCCESS; $args = AjaxUtil::getArgs($args); if (!@$args['user'] || !@$args['name'] || !@$args['newname']) { $status = FTE_INVALID_ARG; } else { if (!$wgUser->isLoggedIn()) { $status = FTE_NOT_LOGGED_IN; } else { if ($wgUser->isBlocked() || wfReadOnly() || $args['user'] != $wgUser->getName()) { $status = FTE_NOT_AUTHORIZED; } else { $db =& wfGetDB(DB_MASTER); $db->begin(); $db->ignoreErrors(true); $status = FamilyTreeUtil::renameFamilyTree($db, $args['user'], $args['name'], $args['newname']); if ($status == FTE_SUCCESS) { $db->commit(); } else { $db->rollback(); } } } } // return status return "<rename status=\"{$status}\"></rename>"; }
private function renameTree() { global $wgUser; if ($this->name && $this->newName) { $db =& wfGetDB(DB_MASTER); $db->ignoreErrors(true); $status = FamilyTreeUtil::renameFamilyTree($db, $wgUser->getName(), $this->name, $this->newName); $db->ignoreErrors(false); if ($status == FTE_DUP_KEY) { $msg = 'You already have a tree named ' . $this->newName; } else { if ($status != FTE_SUCCESS) { $msg = 'Error renaming ' . $this->name; } else { $msg = $this->name . ' was renamed to ' . $this->newName; } } $this->show($msg); } else { $label = 'new name'; $field = $label . ': <input type="text" name="newName"/>'; $this->showInputForm('Rename tree: ' . $this->name, $field, 'go', 'Go'); } }