=====Edit Handler=====
>>==See also:==
Documentation: ""EditHandlerInfo"">>This is the development page for the edit handler.::c::
Since there are a number of issues with the edit handler in Wikka version 1.1.6.0 (one actually introduced with that version) I'm creating this development page to tackle them. --JavaWoman
====Current Edit Handler====
For reference, the code of the current (version 1.1.6.0) edit handler is as follows:
%%(php;1)
tag))) {
echo 'The page name is invalid. Valid page names must start with a letter and contain only letters and numbers.';
}
elseif ($this->HasAccess("write") && $this->HasAccess("read"))
{
if ($newtag = $_POST['newtag']) $this->Redirect($this->Href('edit', $newtag));
if ($_POST)
{
// strip CRLF line endings down to LF to achieve consistency ... plus it saves database space.
// Note: these codes must remain enclosed in double-quotes to work! -- JsnX
$body = str_replace("\r\n", "\n", $_POST['body']);
$body = preg_replace("/\n[ ]{4}/", "\n\t", $body); # @@@ FIXME: misses first line and multiple sets of four spaces - JW 2005-01-16
// we don't need to escape here, we do that just before display (i.e., treat note just like body!)
$note = trim($_POST['note']);
// only if saving:
if ($_POST['submit'] == 'Store')
{
// check for overwriting
if ($this->page)
{
if ($this->page['id'] != $_POST['previous'])
{
$error = 'OVERWRITE ALERT: This page was modified by someone else while you were editing it. '."\n".'Please copy your changes and re-edit this page.';
}
}
// store
if (!$error)
{
// only save if new body differs from old body
if ($body != $this->page['body']) {
// add page (revisions)
$this->SavePage($this->tag, $body, $note);
// now we render it internally so we can write the updated link table.
$this->ClearLinkTable();
$this->StartLinkTracking();
$dummy = $this->Header();
$dummy .= $this->Format($body);
$dummy .= $this->Footer();
$this->StopLinkTracking();
$this->WriteLinkTable();
$this->ClearLinkTable();
}
// forward
$this->Redirect($this->Href());
}
}
}
// fetch fields
if (!$previous = $_POST['previous']) $previous = $this->page['id'];
if (!$body) $body = $this->page['body'];
$body = preg_replace("/\n[ ]{4}/", "\n\t", $body); # @@@ FIXME: misses first line and multiple sets of four spaces - JW 2005-01-16
if ($result = mysql_query("describe ".$this->config['table_prefix']."pages tag")) {
$field = mysql_fetch_assoc($result);
if (preg_match("/varchar\((\d+)\)/", $field['Type'], $matches)) $maxtaglen = $matches[1];
}
else
{
$maxtaglen = 75;
}
// preview?
if ($_POST['submit'] == 'Preview') # preview page
{
$previewButtons =
"\n".
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// so we use htmlspecialchars on the edit note (as on the body)
' Note on your edit. '."\n".
''."\n".
''."\n".
''."\n";
$output .= '
Preview
'."\n";
$output .= $this->Format($body);
$output .=
$this->FormOpen('edit')."\n".
''."\n".
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// hence htmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities!
''."\n";
$output .=
" \n".
$previewButtons.
$this->FormClose()."\n";
}
elseif (!$this->page && strlen($this->tag) > $maxtaglen) # rename page
{
$this->tag = substr($this->tag, 0, $maxtaglen); // truncate tag to feed a backlinks-handler with the correct value. may be omited. it only works if the link to a backlinks-handler is built in the footer.
$output = '
Tag too long! $maxtaglen characters max.
'."\n";
$output .= 'FYI: Clicking on Rename will automatically truncate the tag to the correct size.
'."\n";
}
// append a comment?
if ($_REQUEST['appendcomment'])
{
$body = trim($body)."\n\n----\n\n--".$this->GetUserName().' ('.strftime("%c").')';
}
$output .=
$this->FormOpen('edit').
''."\n".
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// hence htmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities!
' '."\n".
//note add Edit
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// so we use htmlspecialchars on the edit note (as on the body)
' Please add a note on your edit. '."\n".
//finish
' '."\n".
$this->FormClose();
if ($this->GetConfigValue('gui_editor') == 1) {
$output .=
''."\n".
''."\n";
$output .= ''."\n";
}
}
echo $output;
}
else
{
$message = 'You don\'t have write access to this page. You might need to register an account to get write access. '."\n".
" \n".
'View formatting code for this page'.
" \n";
echo $message;
}
?>
%%
As TimoK stated on his user page, "I found the code quite hard to read". Clearly, it's not very well-structured, which makes it also hard to tackle the various problems with it.
====Current issues====
In no particular order, but numbered to make it easier to refer to them:
~1)Bad structure makes the code hard to understand and fix (see TimoK)
~1)The function of some of the code is unclear - possibly it is never used and could (should) be eliminated
~1)Various statements lead to **notice**s because of reference to undefined variables
~1)Indents consisting of (4) spaces are translated into tabs in only a limited number of cases (only the first group of 4 spaces at the start of a line, and not on the first line of the page (see ""Indenting not working properly in handlers/page/edit.php"" on WikkaBugs)
~1)The code generated is not actually valid XHTML; in particular the ##'."\n".
''."\n".
''."\n";
}
}
echo $output;
}
else
{
$message = 'You don\'t have write access to this page. You might need to register an account to get write access. '."\n".
" \n".
'View formatting code for this page'.
" \n";
echo $message;
}
?>
%%
----
CategoryDevelopmentHandlers