ViewDiff

Summary: Compare arbitrary revisions and view a particular version.
Version: 2011-05-13
Prerequisites: pmwiki 2.2.11+
Status: Beta
License: GPL2
Maintainer: Diafygi
Discussion: ViewDiff-Talk?

Questions

  • How can I see what a page looked like at a previous version?
    • Answer: Use the 'viewdiff' action and a timestamp to see that version.
  • How can I see the edits between two arbitrary versions of a page?
    • Answer: Use the 'viewdiff' action with two timestamps and compare the two versions

Description

ViewDiff is an action that creates a rendering of a page that based on a certain time in its history. It will also display the changes made to a page based on a second time.

Installation

To enable ViewDiff, save viewdiff.phpΔ in your cookbook folder, and include the following line in your config.php:

include_once("$FarmD/cookbook/viewdiff.php");

Use

By default ViewDiff creates a form on the History page where you can select two edits to compare. You can turn this option off by setting $ViewDiffCompare = 0; in your config.php file.

To use ViewDiff directly, simply call the action 'viewdiff' in your page url. This will display a temporary rendering of the current page at the current time.

http://example.com/wiki/Main/Home?action=viewdiff

You can also specify a time by including its unix timestamp in the url.

http://example.com/wiki/Main/Home?action=viewdiff&time=1122334455

You can compare two edits by including two times in the url separated by a colon.

http://example.com/wiki/Main/Home?action=viewdiff&time=1122334455:2233445566

This action also accepts PmWiki formated Edit IDs

http://example.com/wiki/Main/Home?action=viewdiff&time=diff:1122334455:2233445566:
or
http://example.com/wiki/Main/Home?action=viewdiff&time=diff:1122334455:2233445566:minor

You can also have two times in two different url variables

http://example.com/wiki/Main/Home?action=viewdiff&time1=1122334455&time2=2233445566
or
http://example.com/wiki/Main/Home?action=viewdiff&time1=diff:1122334455:2233445566:minor&time2=diff:3344556677:4455667788:minor
(This takes the times 1122334455 and 3344556677)

NOTE: This recipe does not revert (:include:) content to the previous time, only the markup on the current page.

Customization

You can add a link to ViewDiff from your PmWiki History page (on each edit's timestamp) by adding the following line of code to your config.php file:

$DiffStartFmt = "<div class='diffbox'><div class='difftime'>
  <div class='diffradio'>
  <input type='radio' id='time1:\$DiffId' name='time2' value='\$DiffId' onclick=\"hideradios()\" />&nbsp;</div>
  <div class='diffradio'>
  <input type='radio' id='time2:\$DiffId' name='time1' value='\$DiffId' onclick=\"hideradios()\" />&nbsp;</div>
  <a href='{\$PageUrl}?action=viewdiff&amp;time=\$DiffId'>\$DiffTime</a>
  \$[by] <span class='diffauthor' title='\$DiffHost'>\$DiffAuthor</span> - \$DiffChangeSum</div>";

You can also customize the output of ViewDiff by changing the following variables from their defaults:

$ViewDiffTimeFmt='D, d M Y H:i:s \G\M\T'
$ViewDiffStartFmt="<h1>View Differences</h1>\n<h3>\$ViewDiffTime1 (newer)</h3>\n<h3>\$ViewDiffTime2 (older)</h3>\n"
$ViewDiffChangesFmt="\$ViewDiffChanges\n"
$ViewDiffTextFmt="<hr />\n<div id='viewdiff'>\$ViewDiffText</div>\n"

Release Notes

  • 2011-05-13 - 0.5 - Re-added ability to use custom formats for History page.
  • 2010-02-18 - 0.4 - Removed internal diff-to-html function, uses pmwiki's DiffHTML() function (added in 2.2.11)
  • 2009-07-13 - 0.3.1 - Fixed XSS vulnerability (PITS/01109)
  • 2009-04-25 - 0.3 - Added comparison form to History Page
  • 2009-04-23 - 0.2 - Changed formatting, added second time variable, added html changes rendering
  • 2009-04-14 - 0.1 - Initial Release

Road Map

  • add history form added in version 2009-04-25 (0.3)
  • add better changes formatting fixed in version 2009-04-23 (0.2)
  • reorganize layout so it is more intuitive
  • add word-by-word changes instead of line-by-line changes added by pmwiki defaults for version 2.2.13+
  • add ability to revert (:include:) pages, too

See Also

PITS:
  • 01106 - separate diff rendering from history page rendering
  • 00642 - diff comparison of two arbitrarily selected versions
  • 00141 - view a specific revision of a page
  • 00796 - create links to individual changes on history page
  • 00571 - word level diffs

Mailing List:

Recipes:

Contributors

Comments

Thanks for this handy recipe! I noticed and fixed a small typo on line 79:

$DiffStartFmt = "...";

should have been

SDV($DiffStartFmt, "...");.

I also changed the $DiffStartFmt contents in the Customization section (above) to match the default (but with a link). Thanks again! rikblok? June 07, 2009, at 03:15 PM

I changed this back to $DiffStartFmt = "..."; in version 0.4 because pagerev.php is loaded (and default values for $DiffStartFmt) before the custom layout is loaded. This means that if SDV() is used, the radio buttons won't display. -Diafygi 2010/02/18

Thanks from me too; very handy feature that should go into core History feature. Only problem I had was the top Compare button and radio buttons were not right-aligned like the rest so I changed the CSS and remove div around the button.

.diffradiotitle { text-align:right; height:1.5em; clear:both; }
<input type='submit' value='\$[Compare]' />

-- BarryB?

If I use the comparison form and set my own value for $DiffStartFmt in the config file, my specified format has no effect. It would be nice if I could specify my own fmt (see PITS:00400: for how to prevent the IP address from being seen by all users) to enhance privacy. Will a future release allow me to both use the comparison form and to specify $DiffStartFmt? - RandyB May 11, 2011, at 04:22 PM

ViewDiff does write it's own custom $DiffStartFmt so it can include the radio buttons. I've updated viewdiff.php so it will accept custom $DiffStartFmt from the config file. Below is the $DiffStartFmt defined in viewdiff.php with the IP Host removed. You should be able to use this in your config file. -Diafygi May 13, 2011 at 11:19 AM
$DiffStartFmt = "  <div class='diffbox'><div class='difftime'>
	  <div class='diffradio'><input type='radio' id='time1:\$DiffId' name='time2' value='\$DiffId' onclick=\"hideradios()\" />&nbsp;</div>
      <div class='diffradio'><input type='radio' id='time2:\$DiffId' name='time1' value='\$DiffId' onclick=\"hideradios()\" />&nbsp;</div>
	  <a name='diff\$DiffGMT' href='#diff\$DiffGMT'>\$DiffTime</a>
      \$[by] \$DiffAuthor - \$DiffChangeSum</div>";

Thanks for adding that capability, and for the ready-to-plug-in PHP code! - RandyB May 13, 2011, at 10:41 AM

See discussion at ViewDiff-Talk?

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.