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

@ -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,13 +363,25 @@ class Wiki extends Controller
if ($this->input->post('wiki'))
{
$wiki->projectid = $this->input->post('wiki_projectid');
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))
{
@ -396,15 +413,18 @@ class Wiki extends Controller
}
$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);
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,13 +448,12 @@ 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;
@ -447,13 +466,36 @@ class Wiki extends Controller
foreach ($wiki->delete_attachments as $att)
@unlink (CODEPOT_ATTACHMENT_DIR . "/{$att->encname}");
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);

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_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';

View File

@ -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';

View File

@ -89,7 +89,7 @@ class FileModel extends Model
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);

View File

@ -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);

View File

@ -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)
{

View File

@ -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');

View File

@ -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);

View File

@ -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');
@ -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', $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,7 +243,7 @@ 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);
@ -207,12 +251,21 @@ class WikiModel extends Model
$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)

View File

@ -104,10 +104,11 @@ $this->load->view (
</div>
<div class='form_input_field'>
<?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)?>
<?=($mode == 'update')? form_hidden('wiki_original_name', set_value('wiki_original_name', $wiki->name)): ''?>
</div>
<div class='form_input_label'>