enhanced the wiki edit view to be able to rename the page itself

This commit is contained in:
hyung-hwan 2015-03-25 07:29:18 +00:00
parent 2702b84b81
commit 0d499dcd2b
12 changed files with 146 additions and 50 deletions

View File

@ -50,7 +50,7 @@ CREATE TABLE wiki (
CONSTRAINT wiki_projectid FOREIGN KEY (projectid) REFERENCES project(id) CONSTRAINT wiki_projectid FOREIGN KEY (projectid) REFERENCES project(id)
ON DELETE RESTRICT ON UPDATE CASCADE ON DELETE RESTRICT ON UPDATE CASCADE
) charset=utf8 engine=InnoDB; ) charset=utf8 engine=InnoDB;
CREATE TABLE wiki_attachment ( CREATE TABLE wiki_attachment (
projectid VARCHAR(32) NOT NULL, projectid VARCHAR(32) NOT NULL,

View File

@ -342,6 +342,11 @@ class Wiki extends Controller
} }
else else
{ {
if ($mode == 'update')
{
$this->form_validation->set_rules (
'wiki_original_name', 'original name', 'required|max_length[255]');
}
$this->form_validation->set_rules ( $this->form_validation->set_rules (
'wiki_projectid', 'project ID', 'required|alpha_dash|max_length[32]'); 'wiki_projectid', 'project ID', 'required|alpha_dash|max_length[32]');
$this->form_validation->set_rules ( $this->form_validation->set_rules (
@ -358,19 +363,31 @@ class Wiki extends Controller
if ($this->input->post('wiki')) if ($this->input->post('wiki'))
{ {
$wiki->projectid = $this->input->post('wiki_projectid'); $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->text = $this->input->post('wiki_text');
$wiki->attachments = array(); $wiki->attachments = array();
$wiki->delete_attachments = array(); $wiki->delete_attachments = array();
if ($this->form_validation->run()) 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'); $delatts = $this->input->post('wiki_delete_attachment');
if (!empty($delatts)) if (!empty($delatts))
{ {
foreach ($delatts as $att) foreach ($delatts as $att)
{ {
$atpos = strpos ($att, '@'); $atpos = strpos ($att, '@');
if ($atpos === FALSE) continue; if ($atpos === FALSE) continue;
$attinfo['name'] = $this->converter->HexToAscii( $attinfo['name'] = $this->converter->HexToAscii(
@ -384,27 +401,30 @@ class Wiki extends Controller
); );
} }
} }
$atts = $this->wikis->getAttachments ( $atts = $this->wikis->getAttachments (
$login['id'], $project, $wiki->name); $login['id'], $project, $wiki->name);
if ($atts === FALSE) if ($atts === FALSE)
{ {
$data['wiki'] = $wiki; $data['wiki'] = $wiki;
$data['message'] = 'DATABASE ERROR'; $data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
return; return;
} }
$wiki->attachments = $atts; $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; $data['wiki'] = $wiki;
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
return; 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 ( $data['message'] = sprintf (
$this->lang->line('WIKI_MSG_RESERVED_WIKI_NAME'), $this->lang->line('WIKI_MSG_RESERVED_WIKI_NAME'),
@ -428,17 +448,16 @@ class Wiki extends Controller
$wiki->new_attachments = $extra; $wiki->new_attachments = $extra;
$result = ($mode == 'update')? $result = ($mode == 'update')?
$this->wikis->update ($login['id'], $wiki): $this->wikis->update ($login['id'], $wiki, $new_wiki_name):
$this->wikis->create ($login['id'], $wiki); $this->wikis->create ($login['id'], $wiki);
if ($result === FALSE) if ($result === FALSE)
{ {
foreach ($extra as $att) // delete uploaded attachments if database operation failed.
@unlink ($att['fullencpath']); foreach ($extra as $att) @unlink ($att['fullencpath']);
$data['message'] = 'DATABASE ERROR'; $data['message'] = 'DATABASE ERROR';
$data['wiki'] = $wiki; $data['wiki'] = $wiki;
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
} }
else else
{ {
@ -447,16 +466,39 @@ class Wiki extends Controller
foreach ($wiki->delete_attachments as $att) foreach ($wiki->delete_attachments as $att)
@unlink (CODEPOT_ATTACHMENT_DIR . "/{$att->encname}"); @unlink (CODEPOT_ATTACHMENT_DIR . "/{$att->encname}");
redirect ("wiki/show/{$project->id}/" . if ($mode == 'update' && !is_null($new_wiki_name))
$this->converter->AsciiToHex($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 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['message'] = $this->lang->line('MSG_FORM_INPUT_INCOMPLETE');
$data['wiki'] = $wiki; $data['wiki'] = $wiki;
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
} }
} }
else else
@ -479,7 +521,7 @@ class Wiki extends Controller
else else
{ {
$data['wiki'] = $wiki; $data['wiki'] = $wiki;
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
} }
} }
else else
@ -489,7 +531,7 @@ class Wiki extends Controller
$wiki->text = ''; $wiki->text = '';
$data['wiki'] = $wiki; $data['wiki'] = $wiki;
$this->load->view ($this->VIEW_EDIT, $data); $this->load->view ($this->VIEW_EDIT, $data);
} }
} }

View File

@ -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_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_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_PAGES_AVAILABLE'] = 'No wiki pages available';
$lang['WIKI_MSG_NO_SUCH_PAGE'] = 'No such wiki page - %s'; $lang['WIKI_MSG_NO_SUCH_PAGE'] = 'No such wiki page - %s';
$lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = 'No such wiki attachment - %s'; $lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = 'No such wiki attachment - %s';

View File

@ -5,7 +5,7 @@ $lang['WIKI_MORE_NEW_ATTACHMENTS'] = '첨부파일 추가';
$lang['WIKI_MSG_ATTACHMENT_NAME_NO_COLON'] = '첨부파일이름에 콜론기호를 포함할 수 없습니다'; $lang['WIKI_MSG_ATTACHMENT_NAME_NO_COLON'] = '첨부파일이름에 콜론기호를 포함할 수 없습니다';
$lang['WIKI_MSG_FAILED_TO_READ_ATTACHMENT'] = '위키 첨부파일을 읽을 수 없습니다 - %s'; $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_PAGES_AVAILABLE'] = '사용할 수 있는 위키 페이지가 없습니다';
$lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다 - %s'; $lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다 - %s';
$lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = '위키 첨부파일을 찾을 수 없습니다 - %s'; $lang['WIKI_MSG_NO_SUCH_ATTACHMENT'] = '위키 첨부파일을 찾을 수 없습니다 - %s';

View File

@ -60,7 +60,7 @@ class FileModel extends Model
$this->db->insert ('log'); $this->db->insert ('log');
$this->db->trans_complete (); $this->db->trans_complete ();
return $this->db->trans_status(); return $this->db->trans_status();
} }
function update ($userid, $file) function update ($userid, $file)
@ -84,12 +84,12 @@ class FileModel extends Model
$this->db->insert ('log'); $this->db->insert ('log');
$this->db->trans_complete (); $this->db->trans_complete ();
return $this->db->trans_status(); return $this->db->trans_status();
} }
function delete ($userid, $file) 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 ('projectid', $file->projectid);
$this->db->where ('name', $file->name); $this->db->where ('name', $file->name);

View File

@ -152,7 +152,7 @@ class LogModel extends Model
function write ($log) 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 ('type', $log->type);
$this->db->set ('action', $log->action); $this->db->set ('action', $log->action);
@ -176,7 +176,7 @@ class LogModel extends Model
function delete ($log) 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->where ('id', $log->id);
$this->db->delete ('log'); $this->db->delete ('log');
@ -195,7 +195,7 @@ class LogModel extends Model
function purge () function purge ()
{ {
$this->db->trans_begin (); $this->db->trans_begin (); // manual transaction. not using trans_start().
$now = time(); $now = time();
$one_month_ago = $now - (24 * 60 * 60 * 30); $one_month_ago = $now - (24 * 60 * 60 * 30);

View File

@ -97,7 +97,7 @@ class ProjectModel extends Model
{ {
// TODO: check if userid can do this.. // 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 ('id', $project->id);
$this->db->set ('name', $project->name); $this->db->set ('name', $project->name);
@ -209,7 +209,7 @@ class ProjectModel extends Model
{ {
// TODO: check if userid can do this.. // 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->where ('id', $project->id);
$this->db->set ('name', $project->name); $this->db->set ('name', $project->name);
@ -266,7 +266,7 @@ class ProjectModel extends Model
function delete ($userid, $project, $force = FALSE) function delete ($userid, $project, $force = FALSE)
{ {
// TODO: check if userid can do this.. // TODO: check if userid can do this..
$this->db->trans_begin (); $this->db->trans_begin (); // manual transaction. not using trans_start().
if ($force) if ($force)
{ {

View File

@ -59,7 +59,7 @@ class SiteModel extends Model
function create ($userid, $site) 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 ('id', $site->id);
$this->db->set ('name', $site->name); $this->db->set ('name', $site->name);
@ -84,7 +84,7 @@ class SiteModel extends Model
function update ($userid, $site) 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->where ('id', $site->id);
$this->db->set ('name', $site->name); $this->db->set ('name', $site->name);
@ -107,7 +107,7 @@ class SiteModel extends Model
function delete ($userid, $site) 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->where ('id', $site->id);
$this->db->delete ('site'); $this->db->delete ('site');

View File

@ -37,14 +37,14 @@ class UserModel extends Model
{ {
$icon_name_set = strlen($settings->icon_name) > 0; $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); $this->db->where ('userid', $userid);
$query = $this->db->get ('user_settings'); $query = $this->db->get ('user_settings');
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)
{ {
$this->db->trans_complete (); $this->db->trans_rollback ();
return FALSE; return FALSE;
} }
@ -86,7 +86,7 @@ class UserModel extends Model
return TRUE; return TRUE;
/* affected_rows() does not seem to work reliably ... /* 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->where ('userid', $userid);
$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); $this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num);

View File

@ -63,7 +63,7 @@ class WikiModel extends Model
{ {
$this->db->trans_start (); $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 ('projectid', $project->id);
$this->db->where ('wikiname', $wikiname); $this->db->where ('wikiname', $wikiname);
$this->db->where ('name', $name); $this->db->where ('name', $name);
@ -98,7 +98,7 @@ class WikiModel extends Model
function create ($userid, $wiki) function create ($userid, $wiki)
{ {
// TODO: check if userid can do this.. // 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'); $now = date('Y-m-d H:i:s');
@ -141,7 +141,7 @@ class WikiModel extends Model
$this->db->set ('createdon', $now); $this->db->set ('createdon', $now);
$this->db->set ('createdby', $userid); $this->db->set ('createdby', $userid);
$this->db->insert ('wiki_attachment'); $this->db->insert ('wiki_attachment');
} }
$this->db->set ('createdon', $now); $this->db->set ('createdon', $now);
$this->db->set ('type', 'wiki'); $this->db->set ('type', 'wiki');
@ -161,15 +161,59 @@ class WikiModel extends Model
return TRUE; return TRUE;
} }
function update ($userid, $wiki) function update ($userid, $wiki, $new_wiki_name = NULL)
{ {
// TODO: check if userid can do this.. // 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'); $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 ('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 ('text', $wiki->text);
$this->db->set ('updatedon', $now); $this->db->set ('updatedon', $now);
$this->db->set ('updatedby', $userid); $this->db->set ('updatedby', $userid);
@ -178,7 +222,7 @@ class WikiModel extends Model
foreach ($wiki->delete_attachments as $att) foreach ($wiki->delete_attachments as $att)
{ {
$this->db->where ('projectid', $wiki->projectid); $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 ('name', $att->name);
$this->db->where ('encname', $att->encname); $this->db->where ('encname', $att->encname);
$this->db->delete ('wiki_attachment'); $this->db->delete ('wiki_attachment');
@ -199,20 +243,29 @@ class WikiModel extends Model
foreach ($wiki->new_attachments as $att) foreach ($wiki->new_attachments as $att)
{ {
$this->db->set ('projectid', $wiki->projectid); $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 ('name', $att['name']);
$this->db->set ('encname', $att['encname']); $this->db->set ('encname', $att['encname']);
$this->db->set ('createdon', $now); $this->db->set ('createdon', $now);
$this->db->set ('createdby', $userid); $this->db->set ('createdby', $userid);
$this->db->insert ('wiki_attachment'); $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 ('createdon', $now);
$this->db->set ('type', 'wiki'); $this->db->set ('type', 'wiki');
$this->db->set ('action', 'update'); $this->db->set ('action', 'update');
$this->db->set ('projectid', $wiki->projectid); $this->db->set ('projectid', $wiki->projectid);
$this->db->set ('userid', $userid); $this->db->set ('userid', $userid);
$this->db->set ('message', $wiki->name); $this->db->set ('message', $effective_wiki_name);
$this->db->insert ('log'); $this->db->insert ('log');
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)

View File

@ -248,7 +248,7 @@ if ($login['settings'] != NULL &&
if ($is_octet_stream || if ($is_octet_stream ||
in_array (strtolower($fileext), array ('png', 'jpg', 'gif', 'tif', 'bmp', 'ico'))) in_array (strtolower($fileext), array ('png', 'jpg', 'gif', 'tif', 'bmp', 'ico')))
{ {
$img = @imagecreatefromstring ($file['content']); $img = @imagecreatefromstring ($file['content']);
if ($img !== FALSE) if ($img !== FALSE)
{ {
@imagedestroy ($img); @imagedestroy ($img);

View File

@ -104,10 +104,11 @@ $this->load->view (
</div> </div>
<div class='form_input_field'> <div class='form_input_field'>
<?php <?php
$extra = ($mode == 'update')? 'readonly="readonly"': ''; $extra = 'maxlength="80" size="40" id="wiki_edit_mainarea_name"';
$extra .= 'maxlength="80" size="40" id="wiki_edit_mainarea_name"'; //$extra .= ($mode == 'update')? ' readonly="readonly"': '';
?> ?>
<?=form_input('wiki_name', set_value('wiki_name', $wiki->name), $extra)?> <?=form_input('wiki_name', set_value('wiki_name', $wiki->name), $extra)?>
<?=($mode == 'update')? form_hidden('wiki_original_name', set_value('wiki_original_name', $wiki->name)): ''?>
</div> </div>
<div class='form_input_label'> <div class='form_input_label'>