Attached is a patch that uses javascript instead of HTTP referer to see when a user has moved away from the node they were in the process of editing.
When a node is being checked out, javascript is injected in the edit node form that fires a ajax request to checkout_release() when the page is being unloaded. This works well when the person editing has moved away from the current edit page within the same site or loaded a new website. It does not rely on HTTP referers being present. Below is the diff of checkout.module with the changes.

74,78c74
<   $items[] = array('path' => 'checkout/unload/'.arg(2), 
<        'callback' => 'checkout_pageunload',
<        'callback arguments' => array(arg(2)),
<        'access' => TRUE,
<        'type' => MENU_CALLBACK);         
---
> 
130,134d126
<         else {
<           drupal_add_js(
<           "$(window).unload( function(){ $.get('".base_path()."checkout/unload/".$node->nid."');return false;} );",
<           'inline');
<         }
171a162,163
>  * Implementation of hook_exit().
>  *
175,178c168,177
< function checkout_pageunload($nid) {
<   global $user;
<   if ($user->uid) {
<     if (db_result(db_query("SELECT 1 FROM {checkout} WHERE nid = %d and uid = %d", $nid, $user->uid))) {
---
> function checkout_exit() {
>   global $user;
> 
>   if ($user->uid) {
>     $edit_types = array('edit', 'classify', 'outline');
>     $request = array_reverse(explode('/', request_uri()));
>     $referer = array_reverse(explode('/', referer_uri()));
>   
>     if (!in_array($request[0], $edit_types) && in_array($referer[0], $edit_types)) {
>       $nid = $referer[1];
209a208
> 

Comments

anitar’s picture

Assigned: anitar » Unassigned
Status: Active » Needs review
smk-ka’s picture

Version: 5.x-1.0 » 5.x-2.x-dev
Status: Needs review » Needs work

Very nice approach, however I wouldn't like to completely rely on JavaScript being present, that is, I would like to see the regular unlocking mechanism still as a fallback solution. To avoid the database overhead of nodes being unlocked twice, I've already been thinking about adding a flag to the session variables once the new unload handler has been fired -- this way the non-JavaScript handler would just return not doing anything.

Anyway, this is something for the 2.x branch.

pomliane’s picture

Status: Needs work » Closed (won't fix)

This version of Checkout (Content locking) is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.