[Home]EditConflict

UseModWiki | RecentChanges | Preferences

Later on this page should be a novice-level explanation. For now, here is an explanation for other programmers.

December 16, 2000: After the following was written, the code was changed so that multiple edits by the same author do not conflict with each other. This allows users to use the back-page function to re-edit a page (without receiving a conflict message). If the user does not have a user-ID number (if they do not have a cookie), the IP address is used.


The basic idea is to use a timestamp in the edit page and check it before processing the posted page. If the timestamps don't match, redisplay the edit page, with a warning and a copy of what the user submitted.

Here's a more specific version:

1. Put the edit-page code in a subroutine, with is_conflict and new_text parameters. (For detected conflicts, is_conflict is true, but normal edits, is_conflict is false. new_text is used for conflicts.)

2. When you get the text for the edit page, also get the timestamp (could use revision number) of the page. Place the timestamp in a hidden form field.

3. In the edit code, if is_conflict is true, print the warning, and also display a textbox with new_text. (The new_text texbox is displayed so the user can cut/paste their additions into the regular textbox.)

4. In the post-handling code, get the submitted timestamp value, and compare it to the page's current value. (You need to open the page for reading to get the current value.)

5. If the timestamps are different, there is an edit conflict. Instead of displaying the "edit accepted" page, call the edit-page code again with is_conflict set, and new_text as the text submitted in the form. Note that conflicts can occur again, if another person saves again before the first person.

6. The user who receives the conflict can cut/paste text from their version (on the bottom) to the top textbox (the one which will be submitted). If the user is careless and just clicks SAVE again, their changes will be lost, not those of the previous author. (The SAVE button will be in a different place, so its pretty hard to click again accidentally.)

7. This EditConflict scheme even works for RecentChanges and ChangeSummary?, as long as the auto-updating code also updates the timestamp.

Note: I had terrible problems with the textboxes not working correctly until I used the "-override" feature of CGI.pm (which forces the textbox. Without the override, I would often get an older version in the same textbox. (I'm not sure how it happened, since I don't see changes in the HTML code.)


Feel free to try out editing conflicts by:

1. In two different browsers (like Netscape and MSIE), create a user-ID by visiting the Preferences page (follow the link on the linkbar). (Users with the same user-ID (or the same IP with no user-ID) will be considered the same user, and no conflict warnings will occur in that case.)

2. In each browser, open a browser window on the same page.

3. In each of the windows, click the EditText? link at the bottom of the page.

4. Type something in one of the windows (call it Window 1), and save it. (The page is not updated unless you change it.)

5. Type something in the other window (Window 2).

6. Try to save the new text from step 5. You will get the EditConflict warning. You can copy your added added text from the bottom textbox (what you submitted) to the top box (what will be saved).

7. (optional) With the EditConflict screen in Window 2, reopen Window 1 and edit the text again. Save the newer text in window 1. Save the text in window 2--you will get another EditConflict message, warning of a second conflict. Go back to step 6, and repeat until you stop saving in Window 1. (Future conflicts will repeat the same "new conflict" message.)

8. Save the text in Window 2, which contains the edits from Window 1 and whatever changes were merged (cut/pasted) from Window 2.


Edit Conflict Screen
When using revision number, top Textbox does not show the last saved text by previous author but show the text of the revision number.
When top Textbox shows the last edited text, we will see the last changed content with our current editing text.

 solution: modify the Old revision handling part of DoEdit() 
    if (!$isConflict && $revision ne '') <--- if($revision ne '') 

 DoEdit() {
  ...
  # Old revision handling
  $revision = &GetParam('revision', '');
  $revision =~ s/\D//g;  # Remove non-numeric chars
  if (!$isConflict && $revision ne '') {
    &OpenKeptRevisions('text_default');
    if (!defined($KeptRevisions{$revision})) {
      $revision = '';
      # Consider better solution like error message?
    } else {
      &OpenKeptRevision($revision);
      $header = Ts('Editing revision %s of ', $revision ) . $id;
    }
  }
  ...


UseModWiki | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited April 23, 2007 2:00 pm by MarkusLude (diff)
Search: