Diff view while editing a page

Last edited by NilsLindenberg:
v.0.1
Sat, 26 Jul 2008 09:33 UTC [diff]


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 (version 0.1)

The following files need to be edited (backup recommended).

handlers/edit.php

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

    // 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).

    // 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
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki