Page 1 of 1
Text Diff for wikipedia type feature
Posted: Sun Nov 04, 2007 3:13 pm
by arpowers
Hey guys,
I'm trying to put together a wikipedia type feature for a project..
I've gone through pretty much every text diffing script I could find on google, but I haven't found anything easy to use...
wikimedia : 'difference engine' .. very complex -- forget about it.
pear: 'text_diff' .. doesn't seem to work that well, maybe I'm confused.
anybody have suggestions on this?
Posted: Sun Nov 04, 2007 3:34 pm
by feyd
Why not just use the Wikimedia software? Or is this more of a development exercise for you to build it yourself?
Posted: Sun Nov 04, 2007 4:02 pm
by Weirdan
I'd use svn + diff parser instead.
Posted: Sun Nov 04, 2007 4:09 pm
by arpowers
I will check out SVN and diffparser...
I'm not using wikimedia because I need total control over: presentation and functionality and it is just way too bloated.
Thanks for the replies please keep them coming:)
Posted: Sun Nov 04, 2007 8:28 pm
by Weirdan
arpowers wrote:I will check out SVN and diffparser...
Basically it will manage all the versioning tasks for you... though interfacing with it could be somewhat hard to implement. There's php_svn extension in pecl - you could try that before resorting to pear's VersionControl_SVN. Though you will still need to parse diffs produced by svn somehow.
Posted: Sun Nov 04, 2007 8:33 pm
by Weirdan
btw, websvn might be of interest too:
http://websvn.tigris.org/
Posted: Sun Nov 04, 2007 8:47 pm
by Kieran Huggins
Posted: Sun Nov 04, 2007 9:29 pm
by arpowers
Thanks again for the replies.. kieren, weirdan
To follow,
I got the pear 'text_diff' working but isn't seeming to do what we want.. just returning changed lines in an array?
I assume some of our colleagues here have built something like this before??
its simply need a class or script that can take to text files, one old & with changes and find the differences between them... on a 'character by character' basis.
Everything I've looked at so far get changed lines.. which in itself can be screwed up if text is added and a new line is created..
as always.. you guys are awesome! thanks for the help
ap
also I don't understand why all the pear stuff needs to be written in php 4 syntax?
Posted: Sun Nov 04, 2007 9:52 pm
by feyd
Why do you want character-by-character differences?
Posted: Sun Nov 04, 2007 10:07 pm
by arpowers
good question..
basically just because I know its been done in the past, and I would like to build a solid system..
lately, though I've been thinking of figuring out the line to line implementation and then figuring the rest out later...
this little feature is more complicated than I initially thought!
Posted: Mon Nov 05, 2007 12:35 am
by Kieran Huggins
the unix command
bdiff might be what you're looking for.
[url=
http://ca.php.net/manual/en/function.shell-exec.php]shell_exec()[url] will give PHP access to the result, though you'll have to create temp files to feed to bdiff.
Posted: Mon Nov 05, 2007 7:14 am
by Ambush Commander
The relevant code in MediaWiki is DifferenceEngine, which performs word-by-word diffs and is reasonably isolated from the rest of the system so you should be able to grab it.
Posted: Mon Nov 05, 2007 10:16 am
by feyd
Character-by-character would imply binary level comparisons. Subversion (SVN) has this mark done well with its Delta-based algorithm.
Posted: Mon Nov 05, 2007 3:00 pm
by arpowers
Wow, finally a really nice solution to this problem...
The 'text_diff' solution from PEAR was the right idea...
Once I implemented this, It wasn't working how I would like, but I found a slightly hacked/modified version that converted the line parameter to a word parameter and rendered it...
output is really nice.
http://software.zuavra.net/inline-diff/
for future reference, I don't think the differenceEngine from wikimedia is a good solution to this problem, if you look at their code it is quite long and hard to understand (quickly) ...
the PEAR library is the way to go for the php solution..
Thanks for your help... great support from you guys..
AP
Posted: Mon Nov 05, 2007 3:47 pm
by Kieran Huggins
Update: the inline renderer is now a native part of the Text_Diff PEAR package. You don't need to use the hack presented here anymore. This page is kept for reference only.
So it's built-in? Sweet!