Re: [PHP] Multi-User Text-Editing

2004-09-07 Thread Daniel Schierbeck
Okay, i got the general idea, now it all comes down to the actual 
writing. I'm making a function that compares two strings (the one in the 
source i read used an exec() call, but i'd like to do it all in PHP) 
per-line. This poses some difficulties. Here's the scenario:

I want to determine whether or not two lines are identical.
If they're not:
- Has the line simply been edited?
- Is it a completely new line?
- Has the line been deleted?
To do so i'll have to run a loop, checking each line. But here's where 
the problem is:

?php
$str1 = NEWTXT
Once there was a Bar
It was red
It had some Foo
Underneath its Foobar
NEWTXT;
$str2 = OLDTXT
Once there was a Bar
It had some Foo
Underneath its Foobar
OLDTXT;
$arr1 = explode('\n', $str1);
$arr2 = explode('\n', $str2);
$count = 0;
foreach ($arr1 as $line_num = $line) {
if (isset($arr2[$count]  ($line === $arr2[$count]))) {
echo Unchanged \ . $line . \\n;
} elseif ($line !== $arr2[$count]) {
echo Changed to \ . $line . \ from \ . $arr2[$count] . 
\\n;
} elseif (!isset($arr2[$count])) {
echo Added \ . $line . \, was  . $arr2[$count] . \\n;
}
$count++;
}
?
Then i'd get something like this:
Unchanged Once there was a Bar
Changed to It was red from It had some Foo
Changed to It had some Foo from Underneath its Foobar
Added Underneath its Foobar
Where the second, third and fourth line is wrong - i added a line 
between There was a Bar and It had some Foo...

How should i do this?










--
Daniel Schierbeck
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multi-User Text-Editing

2004-09-07 Thread Wouter van Vliet
 ?php
 
 $str1 = NEWTXT
 Once there was a Bar
 It was red
 It had some Foo
 Underneath its Foobar
 NEWTXT;
 
 $str2 = OLDTXT
 Once there was a Bar
 It had some Foo
 Underneath its Foobar
 OLDTXT;
 
 $arr1 = explode('\n', $str1);
 $arr2 = explode('\n', $str2);
 
 $count = 0;
 
 foreach ($arr1 as $line_num = $line) {
 if (isset($arr2[$count]  ($line === $arr2[$count]))) {
 echo Unchanged \ . $line . \\n;
 } elseif ($line !== $arr2[$count]) {
 echo Changed to \ . $line . \ from \ . $arr2[$count] 
 . \\n;
 } elseif (!isset($arr2[$count])) {
 echo Added \ . $line . \, was  . $arr2[$count] . 
 \\n;
 }
 
 $count++;
 }
 
 ?
 
 Then i'd get something like this:
 
 Unchanged Once there was a Bar
 Changed to It was red from It had some Foo
 Changed to It had some Foo from Underneath its Foobar
 Added Underneath its Foobar
 
 Where the second, third and fourth line is wrong - i added a line
 between There was a Bar and It had some Foo...
 
 How should i do this?

Add something that goes to the next line in one file and stays on the
same line in the other whenver an addition is found - and use
http://nl2.php.net/manual/en/function.levenshtein.php or
http://nl2.php.net/manual/en/function.similar-text.php instead of !=
to see if a line has changed. I've never used it myself, but the
return value gives you a number indicating how different the strings
are. If they're very different AND the number of lines is not equal
you know for almost sure it's an addition.

Have fun finding the difference!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multi-User Text-Editing

2004-09-07 Thread Michal Migurski
 Okay, i got the general idea, now it all comes down to the actual
 writing. I'm making a function that compares two strings (the one in the
 source i read used an exec() call, but i'd like to do it all in PHP)
 per-line. This poses some difficulties. Here's the scenario:

Tavi Wiki just calls out to the diff command using exec(), which is a lazy
way of doing it. The wiki at c2.com does this too. Not sure what mediawiki
(Raditha's suggestion) does. If you want to implement your own version of
diff in PHP, you can start at the explanation here:
http://c2.com/cgi/wiki?DiffAlgorithm

Also there is this:
http://pear.php.net/package/Text_Diff

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Multi-User Text-Editing

2004-09-06 Thread Daniel Schierbeck
I'm developing a site with information about songs, albums and artists. 
I would like to have the song lyrics as well, but i don't know how i 
should approach it.

What i want is basically a way for many users to update, add or delete 
parts of a text (the lyric). It will probably only be 'trusted' users 
that'll be able to do it (users that has added more than x 
artists/albums/songs). How can i make a CVS-like system, where you can 
see the changes people made, maybe roll back to an earlier version etc. 
etc.?

I think i'll use MySQL, but if you think it's easier to use XML or 
something else, that'll be fine with me (as long as it's generally 
available).

Thank you in advance guys :)
--
Daniel Schierbeck
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread Michal Migurski
 What i want is basically a way for many users to update, add or delete
 parts of a text (the lyric). It will probably only be 'trusted' users
 that'll be able to do it (users that has added more than x
 artists/albums/songs). How can i make a CVS-like system, where you can
 see the changes people made, maybe roll back to an earlier version etc.
 etc.?

You've just described a wiki - one example of a wiki that is written in
PHP and MySQL is http://tavi.sourceforge.net. The code is a little
spaghetti-like, but you should be able to look through the database schema
to understand how they implement the multi-user text editing, and how to
handle the related problems of locking and revision control.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread Daniel Schierbeck
Michal Migurski wrote:
What i want is basically a way for many users to update, add or delete
parts of a text (the lyric). It will probably only be 'trusted' users
that'll be able to do it (users that has added more than x
artists/albums/songs). How can i make a CVS-like system, where you can
see the changes people made, maybe roll back to an earlier version etc.
etc.?

You've just described a wiki - one example of a wiki that is written in
PHP and MySQL is http://tavi.sourceforge.net. The code is a little
spaghetti-like, but you should be able to look through the database schema
to understand how they implement the multi-user text editing, and how to
handle the related problems of locking and revision control.
-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html
Thanks, I'll look into it. Also the CVS-in-PHP thing.
--
Daniel Schierbeck
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread Daniel Schierbeck
Michal Migurski wrote:
What i want is basically a way for many users to update, add or delete
parts of a text (the lyric). It will probably only be 'trusted' users
that'll be able to do it (users that has added more than x
artists/albums/songs). How can i make a CVS-like system, where you can
see the changes people made, maybe roll back to an earlier version etc.
etc.?

You've just described a wiki - one example of a wiki that is written in
PHP and MySQL is http://tavi.sourceforge.net. The code is a little
spaghetti-like, but you should be able to look through the database schema
to understand how they implement the multi-user text editing, and how to
handle the related problems of locking and revision control.
-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html
Wow, confusing code - but i think i got the idea. Just one thing: After 
reading the code, it seems to me that every time someone makes a change 
to a record, a new row is inserted into the DB with the full text of the 
edited record - not just the changes. I saw that there was an automatic 
expiration function, but still, wouldn't it be a drag for the server?

--
Daniel Schierbeck
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread Michal Migurski
  You've just described a wiki - one example of a wiki that is written in
  PHP and MySQL is http://tavi.sourceforge.net. The code is a little
  spaghetti-like, but you should be able to look through the database schema
  to understand how they implement the multi-user text editing, and how to
  handle the related problems of locking and revision control.

 Wow, confusing code - but i think i got the idea. Just one thing: After
 reading the code, it seems to me that every time someone makes a change
 to a record, a new row is inserted into the DB with the full text of the
 edited record - not just the changes. I saw that there was an automatic
 expiration function, but still, wouldn't it be a drag for the server?

Yeah, that's what happens.

I think it's only a problem if you're storing truly stupendous amounts of
text, and then it's just a storage problem - drives are cheap.

If anything, storing the changes only would probably be a bigger processor
load, since viewing any one page would mean having to reconstruct the
content from all previous versions.  This way, the overhead of a diff is
only incurred when you want to view changes to a file between two given
versions.

I think the rationale behind CVS storing just diffs is that it has
branches and merges, while wiki text generally does not. Also (conjecture)
it may be a historical legacy of RCS, from a time when storage was not
quite so cheap.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread raditha dissanayake
Daniel Schierbeck wrote:
Michal Migurski wrote:
What i want is basically a way for many users to update, add or delete
parts of a text (the lyric). It will probably only be 'trusted' users
that'll be able to do it (users that has added more than x
artists/albums/songs). How can i make a CVS-like system, where you can
see the changes people made, maybe roll back to an earlier version etc.
etc.?

You've just described a wiki - one example of a wiki that is written in
PHP and MySQL is http://tavi.sourceforge.net.
Wow, confusing code - but i think i got the idea. Just one thing: 
After reading the code, it seems to me that every time someone makes a 
change to a record, a new row is inserted into the DB with the full 
text of the edited record - not just the changes. I saw that there was 
an automatic expiration function, but still, wouldn't it be a drag for 
the server?

Another wiki is the mediawiki projec the one that powers 
http://www.wikipedia.org/ this is probabl more complex than the one that 
you have already been referred to. BTW according to theory the time to 
retrieve a single record from a properly index database does not 
increase with the number of records in the table. Inserts on the other 
hand do get slowed down often significantly.

--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 128 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multi-User Text-Editing

2004-09-06 Thread zareef ahmed
Hi,

look at it 

http://www.freebsd.org/projects/cvsweb.html

may be usefull.


zareef ahmed
--- raditha dissanayake [EMAIL PROTECTED] wrote:

 Daniel Schierbeck wrote:
 
  Michal Migurski wrote:
 
  What i want is basically a way for many users to
 update, add or delete
  parts of a text (the lyric). It will probably
 only be 'trusted' users
  that'll be able to do it (users that has added
 more than x
  artists/albums/songs). How can i make a CVS-like
 system, where you can
  see the changes people made, maybe roll back to
 an earlier version etc.
  etc.?
 
 
 
  You've just described a wiki - one example of a
 wiki that is written in
  PHP and MySQL is http://tavi.sourceforge.net.
 
  Wow, confusing code - but i think i got the idea.
 Just one thing: 
  After reading the code, it seems to me that every
 time someone makes a 
  change to a record, a new row is inserted into the
 DB with the full 
  text of the edited record - not just the changes.
 I saw that there was 
  an automatic expiration function, but still,
 wouldn't it be a drag for 
  the server?
 
 
 Another wiki is the mediawiki projec the one that
 powers 
 http://www.wikipedia.org/ this is probabl more
 complex than the one that 
 you have already been referred to. BTW according to
 theory the time to 
 retrieve a single record from a properly index
 database does not 
 increase with the number of records in the table.
 Inserts on the other 
 hand do get slowed down often significantly.
 
 -- 
 Raditha Dissanayake.


 http://www.radinks.com/sftp/ |
 http://www.raditha.com/megaupload
 Lean and mean Secure FTP applet with | Mega Upload -
 PHP file uploader
 Graphical User Inteface. Just 128 KB | with progress
 bar.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


=
Zareef Ahmed :: A PHP Developer in Delhi(India).
Homepage :: http://www.zasaifi.com



__
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php