views:

81

answers:

2

I'm working on a project constructing an online collaboration tool. Looking at Wikipedia, I noticed that user-generated itterations of a page can easily be compared to each other; the comparison highlights the differences.

Conceptually, what would I need to implement to do pretty much exactly the same?

A: 

You'll need a versioned datastore and a diffing algorithm.

Store versions of your resources by giving each resource a revision number. When a user edits a resource, instead of replacing the resource, save the edit as a new entry in your datastore with a new, higher revision number. When you want to retrieve the resource, return the one with the highest revision.

Instead of a revision number you could use timestamps. Not only do timestamps always increase, but the revision number itself could be used to identify when the resource was modified.

Choose a diff algorithm based on how you're storing the resources. Wikitext is usually linewise, so if users are editing that, it would make sense to use a linewise diff like the standard Unix diff utility. If the resources are XML, you may wish to find an XML-specific diff algorithm so that it would be clear to users where the differences are.

a paid nerd
+1  A: 

Composited from the good advice:

The easiest way is to just use any of the already existing wiki engines. There are plenty of good wiki engines. Don't reinvent the wheel.

For example, StackOverflow itself is a custom built wiki. Look at the edit viewer on Stack Overflow to see how well its functionality meets the one described in the question.

Kriem