Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

InlineDiff

Summary: Shows the difference between 2 versions by highlighting the changes in markup on word level.
Version: 2008-01-17
Prerequisites: PmWiki 2.2
Status: stable
Maintainer: Anno
Categories: Administration, Editing

Description

PmWiki's built in function for page history currently shows a comparison between each 2 lines of 2 versions, but without any highlighting. If the lines are long and the changes small, it is sometimes very difficult to see what actually changed.

This recipe integrates the http://pear.php.net/package/Text_Diff package into the PmWiki original function to provide the highlighting so one can immediately spot the differences. You have to press "Show changes to markup" on the history page, to see the highlighting.

Example of markup highlighting:

Installation

1. Extract the contents of the pagerevinline1.2.zipΔ file to the cookbook/ folder, preserving the directory structure:

 cookbook/pagerevinline/pagerevinline.php
                       /Text/Diff.php		
                            /Diff/Renderer.php
                                 /Renderer/inline.php
                                 /Engine/native.php

2. Add this to your local/config.php file:

 if ($action=='diff') 
	include_once("$FarmD/cookbook/pagerevinline/pagerevinline.php");

If you would like to default to the markup view in the page history, add these lines instead:

 if(!isset($_REQUEST['source'])) $DiffShow['source'] ='y';
 if ($action=='diff') 
	include_once("$FarmD/cookbook/pagerevinline/pagerevinline.php");

(This exact sequence is important in order for the "Show changes to markup/preview" links to work properly.)

Release Notes

  • 2008-01-17 v1.2 (pagerevinline1.2.zipΔ): Implemented the improvements by Petko and EemeliAro, and upgraded to Text_Diff-0.3.2
  • 2007-05-14 v1.1 (pagerevinline1.1.zipΔ): Upon suggestion of Scott the recipe now uses the $FarmD variable throughout the files

Integration with Limit Diffs Per Page

From 2008-11-16 on, this recipe can be automatically integrated with the Limit Diffs Per Page recipe. To do it, copy the InlineDiff dirs/files to the cookbook/pagerevinline and install LDPP. --Petko

Comments

2007-09-17, Maddes:
I do not get inline diffs for the output, only for the markup.
This is the intended behavior. --Anno

Also then I get some assert errors in native.php on line 202.
I'm using PmWiki 2.1.27, is this the reason for these problems?
Probably, this has been developed fro the 2.2 version of PmWiki --Anno

Is it possible to extend the cookbook also for the output changes?
This would be difficult to do and I have no plans to do it --Anno
Personal contact via http://www.maddes.net/contact.php

Great recipe, thanks a lot! :-) --Henning May 16, 2007, at 10:33 AM

After recognizing the importance of the correct sequence of includes, I have tried to point it out in the recipe documentation here. I hope that will help others to avoid the mistake I made. --Henning June 04, 2007, at 11:11 AM

This is a very nice recipe! I did a small change in the beginning, the CSS definitions of the ins and del markups: otherwise elements in the sidebar/header/footer also change bgcolor:

 SDV($HTMLStylesFmt['diffinline'], " 
   .diffmarkup del { background:#fcc; }\n
   .diffmarkup ins { background:#cfc; }\n");

Thanks! --Petko August 19, 2007, at 04:28 PM

Excellent recipe, thanks! I've made a small adjustment on my site to it, as the Text_Diff_Renderer_inline by default splits words on white space only. This is fine for normal text, but wiki pages tend to often have changes to the markup, which is mostly from a slightly different set of characters. Hence, I've replaced line 142 of Diff/Renderer/inline.php with the following:

## begin edit by Eemeli, was:
## $nextpos = strcspn(substr($string, $pos + $spaces), " \n");
$s = substr($string, $pos + $spaces);
$nextpos = strspn($s, "!@#$%^&*()=+[]{}'\\:|");
if ( $nextpos == 0 ) $nextpos = strcspn($s, " \n!@#$%^&*()=+[]{}'\\:|");
## end edit

Which should let InlineDiff see blocks of markup as separate words instead of as part of whatever word they're next to. --EemeliAro January 16, 2008, at 06:20 PM

April 7, 2008 - Very good script with nice output! I made two changes on my installation:

Deleted lines

Deleted lines are displayed without the <del> tags. I've edited lines 108-110 of pagerevinline.php to inclde the tags:

echo "<div class='diffmarkup'><del>",
str_replace("\n","<br />",htmlspecialchars(join("\n",$in))),
"</del></div>";

Hide "changed from"

Since the "Changed to" block also contains the "from" information, I could not see any point of displaying the old text as well. So before including pagerevinline.php in config.php, I added:

if ($DiffShow['source'] == 'y' || $_REQUEST['source'] == 'y') {
   SDV($DiffDelFmt['c'],"<div style='display:none;'>");

   SDV($DiffAddFmt['c'],"</div>
      <div class='difftype'>\$[Changed line \$DiffLines:]</div>
      <div class='diffchange'>");
}

This will hide the "Changed lines ..." block. Jantah

See Also

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on November 16, 2008, at 05:19 PM