Wiki source for EditDiff


Show raw source

=====Diff view while editing a page=====
{{lastedit}}

If you edit a wikka-page, it might be interesting to see the differences between the last version and your draft. I need this ability, so I hacked together some code.

Please note: the following code has to be seen as an alpha, i.e. it works (with some problems) but the underlying code can be described as an awfull hack. Based on 1.1.6.6 (rev 1194) but should work with 1.1.6.5, too.

====Todo====
- the code is an ugly hack (see below). Problem that we can't give the needed params (in this case the IDs for the two revisions), since WAKKA::method does not allow params. Instead, the $_GET params are set within the edit-handler. A solution would be to allow params for method() or wee need to undertake an extra page redirect
- Second thing: since the edited version is not saved, we need to get the body to the diff handler in another way. Since it (may be) is larger then allowed for $_GET, we use an extra variable within the WAKKA-object. A solution would be to take a closer look into brians draft-framework (i.e. saving a draft before diff)
- Cosmetic: Heading and infobox are from the original diff-handler, i.e. the link for the edit-draft points into nowhere, the heading ma be missleading
- the timestamp for the edit-draft is a not formatted unix-timestamp for now (I have to look up the right function here)
- action params somehow get lost (at least from the edit thing, probably has to do with encoding)
- the diff button is located right from the cancel button, probably not a good choice
- there is no diff-button while using preview
- otherwise it seems to work ok :)


===The code (version 0.1)===
The following files need to be edited (backup recommended).

==handlers/edit.php==

before the line with "RENAME SCREEN" (line 235/236).

%%(php)
// DIFF Screen
elseif (isset($_POST['submit']) && $_POST['submit'] == 'Diff')
{
$_GET['b'] = $previous; #
$_GET['fastdiff'] = TRUE; #
$this->editbody = $this->hsc_secure($body);
$output .= $this->method('diff');
$output .=
$this->FormOpen('edit')."\n";

$preview_buttons = '<hr />'."\n";
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// so we use hsc_secure() on the edit note (as on the body)
if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled
{
$preview_buttons .= '<input size="'.MAX_EDIT_NOTE_LENGTH.'" type="text" name="note" value="'.$this->hsc_secure($note).'" '.$highlight_note.'/>'.LABEL_EDIT_NOTE.'<br />'."\n";
}
$preview_buttons .= '<input name="submit" type="submit" value="'.INPUT_SUBMIT_STORE.'" accesskey="'.ACCESSKEY_STORE.'" />'."\n".
'<input name="submit" type="submit" value="'.INPUT_SUBMIT_REEDIT.'" accesskey="'.ACCESSKEY_REEDIT.'" id="reedit_id" />'."\n".
'<input type="button" value="'.INPUT_BUTTON_CANCEL.'" onclick="document.location=\''.$this->href('').'\';" />'."\n";

$output .= '<input type="hidden" name="previous" value="'.$previous.'" />'."\n".
// We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them
// hence hsc_secure() instead of htmlspecialchars_ent() which UNescapes entities!
// JW/2007-02-20: why is this? wouldn't it be easier for the person editing to show actual characters instead of entities?
'<input type="hidden" name="body" value="'.$this->hsc_secure($body).'" />'."\n"; #427
$output .= "<br />\n".$preview_buttons.$this->FormClose()."\n";
}
%%

===handlers/diff.php===

The first two lines replace the original ones (starting line 58).

%%(php)
// load pages
if(isset($_GET['a'])) $pageA = $this->LoadPageById($_GET['a']); #312
if(isset($_GET['b'])) $pageB = $this->LoadPageById($_GET['b']); #312

// We have a diff-request for an (not yet saved) edit.
// This is not saved yet, so we have to construct the page-array
if(!isset($_GET['a']))
{
$pageA['body'] = $this->editbody;
$tmp = $this->GetUser();
$pageA['user'] = $tmp['name'];
$pageA['note'] = '';
$pageA['time'] = time();
$pageA['id'] = 'edit';
$pageA['tag'] = $pageB['tag'];
if (isset($_POST['note'])) $pageA['note'] = $this->hsc_secure($_POST['note']);
}
%%

----
CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki