diff --git a/codepot/etc/codepot.mysql b/codepot/etc/codepot.mysql index 88e30b4e..df49d05e 100644 --- a/codepot/etc/codepot.mysql +++ b/codepot/etc/codepot.mysql @@ -50,7 +50,7 @@ CREATE TABLE wiki ( CONSTRAINT wiki_projectid FOREIGN KEY (projectid) REFERENCES project(id) ON DELETE RESTRICT ON UPDATE CASCADE -) charset=utf8 engine=InnoDB; +) charset=utf8 engine=InnoDB; CREATE TABLE wiki_attachment ( projectid VARCHAR(32) NOT NULL, diff --git a/codepot/src/codepot/controllers/wiki.php b/codepot/src/codepot/controllers/wiki.php index ba748f7c..1545e7db 100644 --- a/codepot/src/codepot/controllers/wiki.php +++ b/codepot/src/codepot/controllers/wiki.php @@ -342,6 +342,11 @@ class Wiki extends Controller } else { + if ($mode == 'update') + { + $this->form_validation->set_rules ( + 'wiki_original_name', 'original name', 'required|max_length[255]'); + } $this->form_validation->set_rules ( 'wiki_projectid', 'project ID', 'required|alpha_dash|max_length[32]'); $this->form_validation->set_rules ( @@ -358,19 +363,31 @@ class Wiki extends Controller if ($this->input->post('wiki')) { $wiki->projectid = $this->input->post('wiki_projectid'); - $wiki->name = $this->input->post('wiki_name'); + if ($mode == 'update') + { + $wiki->name = $this->input->post('wiki_original_name'); + $new_wiki_name = $this->input->post('wiki_name'); + } + else + { + $wiki->name = $this->input->post('wiki_name'); + $new_wiki_name = NULL; + } $wiki->text = $this->input->post('wiki_text'); $wiki->attachments = array(); $wiki->delete_attachments = array(); if ($this->form_validation->run()) { + // $new_wiki_name is not needed if it's not different from the orignal name + if ($mode == 'update' && $wiki->name == $new_wiki_name) $new_wiki_name = NULL; + $delatts = $this->input->post('wiki_delete_attachment'); if (!empty($delatts)) { foreach ($delatts as $att) { - $atpos = strpos ($att, '@'); + $atpos = strpos ($att, '@'); if ($atpos === FALSE) continue; $attinfo['name'] = $this->converter->HexToAscii( @@ -384,27 +401,30 @@ class Wiki extends Controller ); } } - + $atts = $this->wikis->getAttachments ( $login['id'], $project, $wiki->name); if ($atts === FALSE) { $data['wiki'] = $wiki; $data['message'] = 'DATABASE ERROR'; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); return; } $wiki->attachments = $atts; - if (strpos ($wiki->name, ':') !== FALSE) + // disallow : # [ ] | + if (strpbrk ($wiki->name, ':#[]|') !== FALSE || + (!is_null($new_wiki_name) && strpbrk ($new_wiki_name, ':#[]|') !== FALSE)) { - $data['message'] = $this->lang->line('WIKI_MSG_NAME_NO_COLON'); + $data['message'] = $this->lang->line('WIKI_MSG_NAME_DISALLOWED_CHARS'); $data['wiki'] = $wiki; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); return; } - if ($this->wikihelper->_is_reserved ($wiki->name, FALSE)) + if ($this->wikihelper->_is_reserved ($wiki->name, FALSE) || + (!is_null($new_wiki_name) && $this->wikihelper->_is_reserved ($new_wiki_name, FALSE))) { $data['message'] = sprintf ( $this->lang->line('WIKI_MSG_RESERVED_WIKI_NAME'), @@ -428,17 +448,16 @@ class Wiki extends Controller $wiki->new_attachments = $extra; $result = ($mode == 'update')? - $this->wikis->update ($login['id'], $wiki): + $this->wikis->update ($login['id'], $wiki, $new_wiki_name): $this->wikis->create ($login['id'], $wiki); - if ($result === FALSE) { - foreach ($extra as $att) - @unlink ($att['fullencpath']); + // delete uploaded attachments if database operation failed. + foreach ($extra as $att) @unlink ($att['fullencpath']); $data['message'] = 'DATABASE ERROR'; $data['wiki'] = $wiki; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); } else { @@ -447,16 +466,39 @@ class Wiki extends Controller foreach ($wiki->delete_attachments as $att) @unlink (CODEPOT_ATTACHMENT_DIR . "/{$att->encname}"); - redirect ("wiki/show/{$project->id}/" . - $this->converter->AsciiToHex($wiki->name)); + if ($mode == 'update' && !is_null($new_wiki_name)) + { + // renamed. redirect to a newly named page. + redirect ("wiki/show/{$project->id}/" . + $this->converter->AsciiToHex($new_wiki_name)); + } + else + { + redirect ("wiki/show/{$project->id}/" . + $this->converter->AsciiToHex($wiki->name)); + } } } } else { + if ($mode == 'update') + { + $atts = $this->wikis->getAttachments ( + $login['id'], $project, $wiki->name); + if ($atts === FALSE) + { + $data['wiki'] = $wiki; + $data['message'] = 'DATABASE ERROR'; + $this->load->view ($this->VIEW_EDIT, $data); + return; + } + $wiki->attachments = $atts; + } + $data['message'] = $this->lang->line('MSG_FORM_INPUT_INCOMPLETE'); $data['wiki'] = $wiki; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); } } else @@ -479,7 +521,7 @@ class Wiki extends Controller else { $data['wiki'] = $wiki; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); } } else @@ -489,7 +531,7 @@ class Wiki extends Controller $wiki->text = ''; $data['wiki'] = $wiki; - $this->load->view ($this->VIEW_EDIT, $data); + $this->load->view ($this->VIEW_EDIT, $data); } } diff --git a/codepot/src/codepot/language/english/wiki_lang.php b/codepot/src/codepot/language/english/wiki_lang.php index 9a4b3e3f..53973ad2 100644 --- a/codepot/src/codepot/language/english/wiki_lang.php +++ b/codepot/src/codepot/language/english/wiki_lang.php @@ -5,7 +5,7 @@ $lang['WIKI_MORE_NEW_ATTACHMENTS'] = 'Add more'; $lang['WIKI_MSG_ATTACHMENT_NAME_NO_COLON'] = 'Attachment name containing a colon'; $lang['WIKI_MSG_FAILED_TO_READ_ATTACHMENT'] = 'Failed to read wiki attachment - %s'; -$lang['WIKI_MSG_NAME_NO_COLON'] = 'Wiki name containing a colon'; +$lang['WIKI_MSG_NAME_DISALLOWED_CHARS'] = 'Wiki name contains disallowed characters'; $lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = 'No wiki pages available'; $lang['WIKI_MSG_NO_SUCH_PAGE'] = 'No such wiki page - %s'; $lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = 'No such wiki attachment - %s'; diff --git a/codepot/src/codepot/language/korean/wiki_lang.php b/codepot/src/codepot/language/korean/wiki_lang.php index 21b4a2dd..b17bd6ca 100644 --- a/codepot/src/codepot/language/korean/wiki_lang.php +++ b/codepot/src/codepot/language/korean/wiki_lang.php @@ -5,7 +5,7 @@ $lang['WIKI_MORE_NEW_ATTACHMENTS'] = '첨부파일 추가'; $lang['WIKI_MSG_ATTACHMENT_NAME_NO_COLON'] = '첨부파일이름에 콜론기호를 포함할 수 없습니다'; $lang['WIKI_MSG_FAILED_TO_READ_ATTACHMENT'] = '위키 첨부파일을 읽을 수 없습니다 - %s'; -$lang['WIKI_MSG_NAME_NO_COLON'] = '위키이름에 콜론기호를 포함할 수 없습니다'; +$lang['WIKI_MSG_NAME_DISALLOWED_CHARS'] = '위키이름에 허용되지 않는 문자가 포함되어 있습니다'; $lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = '사용할 수 있는 위키 페이지가 없습니다'; $lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다 - %s'; $lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = '위키 첨부파일을 찾을 수 없습니다 - %s'; diff --git a/codepot/src/codepot/models/filemodel.php b/codepot/src/codepot/models/filemodel.php index 5b99c061..bcda008d 100644 --- a/codepot/src/codepot/models/filemodel.php +++ b/codepot/src/codepot/models/filemodel.php @@ -60,7 +60,7 @@ class FileModel extends Model $this->db->insert ('log'); $this->db->trans_complete (); - return $this->db->trans_status(); + return $this->db->trans_status(); } function update ($userid, $file) @@ -84,12 +84,12 @@ class FileModel extends Model $this->db->insert ('log'); $this->db->trans_complete (); - return $this->db->trans_status(); + return $this->db->trans_status(); } function delete ($userid, $file) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('projectid', $file->projectid); $this->db->where ('name', $file->name); diff --git a/codepot/src/codepot/models/logmodel.php b/codepot/src/codepot/models/logmodel.php index db0f5fee..45671004 100644 --- a/codepot/src/codepot/models/logmodel.php +++ b/codepot/src/codepot/models/logmodel.php @@ -152,7 +152,7 @@ class LogModel extends Model function write ($log) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->set ('type', $log->type); $this->db->set ('action', $log->action); @@ -176,7 +176,7 @@ class LogModel extends Model function delete ($log) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('id', $log->id); $this->db->delete ('log'); @@ -195,7 +195,7 @@ class LogModel extends Model function purge () { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $now = time(); $one_month_ago = $now - (24 * 60 * 60 * 30); diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index b8621a08..76a57bfa 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -97,7 +97,7 @@ class ProjectModel extends Model { // TODO: check if userid can do this.. - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->set ('id', $project->id); $this->db->set ('name', $project->name); @@ -209,7 +209,7 @@ class ProjectModel extends Model { // TODO: check if userid can do this.. - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('id', $project->id); $this->db->set ('name', $project->name); @@ -266,7 +266,7 @@ class ProjectModel extends Model function delete ($userid, $project, $force = FALSE) { // TODO: check if userid can do this.. - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). if ($force) { diff --git a/codepot/src/codepot/models/sitemodel.php b/codepot/src/codepot/models/sitemodel.php index 1c6bcff5..efd58f8d 100644 --- a/codepot/src/codepot/models/sitemodel.php +++ b/codepot/src/codepot/models/sitemodel.php @@ -59,7 +59,7 @@ class SiteModel extends Model function create ($userid, $site) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->set ('id', $site->id); $this->db->set ('name', $site->name); @@ -84,7 +84,7 @@ class SiteModel extends Model function update ($userid, $site) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('id', $site->id); $this->db->set ('name', $site->name); @@ -107,7 +107,7 @@ class SiteModel extends Model function delete ($userid, $site) { - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('id', $site->id); $this->db->delete ('site'); diff --git a/codepot/src/codepot/models/usermodel.php b/codepot/src/codepot/models/usermodel.php index 12abb5e1..6798e951 100644 --- a/codepot/src/codepot/models/usermodel.php +++ b/codepot/src/codepot/models/usermodel.php @@ -37,14 +37,14 @@ class UserModel extends Model { $icon_name_set = strlen($settings->icon_name) > 0; - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('userid', $userid); $query = $this->db->get ('user_settings'); if ($this->db->trans_status() === FALSE) { - $this->db->trans_complete (); + $this->db->trans_rollback (); return FALSE; } @@ -86,7 +86,7 @@ class UserModel extends Model return TRUE; /* affected_rows() does not seem to work reliably ... - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $this->db->where ('userid', $userid); $this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); diff --git a/codepot/src/codepot/models/wikimodel.php b/codepot/src/codepot/models/wikimodel.php index d5dbe52b..e092a33d 100644 --- a/codepot/src/codepot/models/wikimodel.php +++ b/codepot/src/codepot/models/wikimodel.php @@ -63,7 +63,7 @@ class WikiModel extends Model { $this->db->trans_start (); - $this->db->select ('name,encname,createdon,createdby'); + $this->db->select ('name,encname,createdon,createdby'); $this->db->where ('projectid', $project->id); $this->db->where ('wikiname', $wikiname); $this->db->where ('name', $name); @@ -98,7 +98,7 @@ class WikiModel extends Model function create ($userid, $wiki) { // TODO: check if userid can do this.. - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $now = date('Y-m-d H:i:s'); @@ -141,7 +141,7 @@ class WikiModel extends Model $this->db->set ('createdon', $now); $this->db->set ('createdby', $userid); $this->db->insert ('wiki_attachment'); - } + } $this->db->set ('createdon', $now); $this->db->set ('type', 'wiki'); @@ -161,15 +161,59 @@ class WikiModel extends Model return TRUE; } - function update ($userid, $wiki) + function update ($userid, $wiki, $new_wiki_name = NULL) { // TODO: check if userid can do this.. - $this->db->trans_begin (); + $this->db->trans_begin (); // manual transaction. not using trans_start(). $now = date('Y-m-d H:i:s'); + if (!is_null($new_wiki_name) && $wiki->name != $new_wiki_name) + { + // there is a change in name. + // rename the wiki document and its attachments + + // check if the new name exists. + $this->db->where ('projectid', $wiki->projectid); + $this->db->where ('name', $new_wiki_name); + $query = $this->db->get ('wiki'); + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_rollback (); + return FALSE; + } + + $result = $query->result (); + if (!empty($result)) + { + // the new name exists in the table. + $this->db->trans_rollback (); + return FALSE; + } + + $this->db->where ('projectid', $wiki->projectid); + $this->db->where ('name', $wiki->name); + $this->db->set ('name', $new_wiki_name); + $this->db->set ('updatedon', $now); + $this->db->set ('updatedby', $userid); + $this->db->update ('wiki'); + + // attachment renaming isn't needed because the + // database table has a proper trigger set. + //$this->db->where ('projectid', $wiki->projectid); + //$this->db->where ('wikiname', $wiki->name); + //$this->db->set ('wikiname', $new_wiki_name); + //$this->db->update ('wiki_attachment'); + + $effective_wiki_name = $new_wiki_name; + } + else + { + $effective_wiki_name = $wiki->name; + } + $this->db->where ('projectid', $wiki->projectid); - $this->db->where ('name', $wiki->name); + $this->db->where ('name', $effective_wiki_name); $this->db->set ('text', $wiki->text); $this->db->set ('updatedon', $now); $this->db->set ('updatedby', $userid); @@ -178,7 +222,7 @@ class WikiModel extends Model foreach ($wiki->delete_attachments as $att) { $this->db->where ('projectid', $wiki->projectid); - $this->db->where ('wikiname', $wiki->name); + $this->db->where ('wikiname', $effective_wiki_name); $this->db->where ('name', $att->name); $this->db->where ('encname', $att->encname); $this->db->delete ('wiki_attachment'); @@ -199,20 +243,29 @@ class WikiModel extends Model foreach ($wiki->new_attachments as $att) { $this->db->set ('projectid', $wiki->projectid); - $this->db->set ('wikiname', $wiki->name); + $this->db->set ('wikiname', $effective_wiki_name); $this->db->set ('name', $att['name']); $this->db->set ('encname', $att['encname']); $this->db->set ('createdon', $now); $this->db->set ('createdby', $userid); $this->db->insert ('wiki_attachment'); - } - + } + + // TODO: put rename message + //$this->db->set ('createdon', $now); + //$this->db->set ('type', 'wiki'); + //$this->db->set ('action', 'rename'); + //$this->db->set ('projectid', $wiki->projectid); + //$this->db->set ('userid', $userid); + //$this->db->set ('message', $effective_wiki_name); + //$this->db->insert ('log'); + $this->db->set ('createdon', $now); $this->db->set ('type', 'wiki'); $this->db->set ('action', 'update'); $this->db->set ('projectid', $wiki->projectid); $this->db->set ('userid', $userid); - $this->db->set ('message', $wiki->name); + $this->db->set ('message', $effective_wiki_name); $this->db->insert ('log'); if ($this->db->trans_status() === FALSE) diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index 78557fdf..29b94711 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -248,7 +248,7 @@ if ($login['settings'] != NULL && if ($is_octet_stream || in_array (strtolower($fileext), array ('png', 'jpg', 'gif', 'tif', 'bmp', 'ico'))) { - $img = @imagecreatefromstring ($file['content']); + $img = @imagecreatefromstring ($file['content']); if ($img !== FALSE) { @imagedestroy ($img); diff --git a/codepot/src/codepot/views/wiki_edit.php b/codepot/src/codepot/views/wiki_edit.php index 44c4180f..3ccdbbc0 100644 --- a/codepot/src/codepot/views/wiki_edit.php +++ b/codepot/src/codepot/views/wiki_edit.php @@ -104,10 +104,11 @@ $this->load->view (