Index: claimnodeownership.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/claimnodeownership/claimnodeownership.install,v
retrieving revision 1.1
diff -u -F '^f' -r1.1 claimnodeownership.install
--- claimnodeownership.install	21 Oct 2009 05:48:29 -0000	1.1
+++ claimnodeownership.install	9 Jan 2011 06:35:14 -0000
@@ -13,6 +13,25 @@ function claimnodeownership_uninstall() 
 }
 
 function claimnodeownership_schema() {
+  $schema['claim_nodes'] = array(
+    'description' => t('Stores whether or not nodes are claimable.'),
+    'fields' => array(
+      'nid' => array(
+        'description' => 'The {node}.nid designated as claimable or not.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'claimable' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'size' => 'tiny',
+        'description' => 'Whether a node is claimable. (0 = Not claimable, 1 = Claimable)',
+      ),
+    ),
+    'primary key' => array('nid'),
+  );
   $schema['claim_history'] = array(
     'description' => t('TODO: please describe this table!'),
     'fields' => array(
@@ -40,6 +59,37 @@ function claimnodeownership_schema() {
     'primary key' => array('id'),
   );
 
-
   return $schema;
+}
+
+/*
+ * Add the claim_nodes table to track whether nodes are claimable.
+ */
+function claimnodeownership_update_6000() {
+    $schema['claim_nodes'] = array(
+    'description' => t('Stores whether or not nodes are claimable.'),
+    'fields' => array(
+      'nid' => array(
+        'description' => 'The {node}.nid designated as claimable or not.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'claimable' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'size' => 'tiny',
+        'description' => 'Whether a node is claimable. (0 = Not claimable, 1 = Claimable)',
+      ),
+    ),
+    'primary key' => array('nid'),
+  );
+
+  $ret = array();
+
+  if (!db_table_exists('claim_nodes')) {
+    db_create_table($ret, 'claim_nodes', $schema['claim_nodes']);
+  }
+  return $ret;
 }
\ No newline at end of file
Index: claimnodeownership.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/claimnodeownership/claimnodeownership.module,v
retrieving revision 1.1
diff -u -F '^f' -r1.1 claimnodeownership.module
--- claimnodeownership.module	21 Oct 2009 05:48:29 -0000	1.1
+++ claimnodeownership.module	9 Jan 2011 06:35:14 -0000
@@ -1,12 +1,23 @@
 <?php
 // $Id: claimnodeownership.module,v 1.1 2009/10/21 05:48:29 minghuiyu Exp $
-function claimnodeownership_menu() {
 
+
+
+/**
+ * Nodes are not claimable, by default.
+ */
+define('NODE_CLAIMABILITY', 0);
+
+/**
+ * Implementation of hook_menu().
+ */
+function claimnodeownership_menu() {
   $items['node/%node/claim'] = array(
     'title' => 'Claim Page Ownership',
     'page callback' => 'claimnodeownership_claim',
     'type' => MENU_LOCAL_TASK,
-    'access arguments' => array('claim ownership'),
+    'access callback' => 'claimnodeownership_access_claim',
+    'access arguments' => array(1),
     'weight' => 90,
   );
 
@@ -14,15 +25,23 @@ function claimnodeownership_menu() {
     'title' => 'Claim Page Ownership',
     'page callback' => 'claimnodeownership_admin_settings',
     'type' => MENU_NORMAL_ITEM,
-    'access arguments' => array('admin claiming ownership'),
+    'access arguments' => array('administer claim node ownership'),
     'weight' => 90,
   );
 
   return $items;
 }
 
+function claimnodeownership_access_claim($node) {
+  global $user;
+  return ($node->claimable) && ($node->uid != $user->uid) && (user_access('administer claim node ownership') || user_access('claim ownership of claimable content'));
+}
+
+/**
+ * Implementation of hook_perm().
+ */
 function claimnodeownership_perm() {
-  return array('claim ownership', 'admin claiming ownership');
+  return array('administer claim node ownership', 'claim ownership of claimable content');
 }
 
 function claimnodeownership_claim() {
@@ -32,6 +51,77 @@ function claimnodeownership_claim() {
   return $output;
 }
 
+/**
+ * Implementation of hook_form_alter().
+ */
+function claimnodeownership_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'node_type_form') {
+    $form['claimnodeownership'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Claim Node Ownership settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['claimnodeownership']['claimable'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Claimable'),
+      '#default_value' => variable_get('claimable_'. $form['#node_type']->type, NODE_CLAIMABILITY),
+      '#description' => t('Node can be claimed by those with the permission to do so.'),
+    );
+  }
+  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
+    $form['claimnodeownership'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Claim Node Ownership settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#access' => user_access('create url aliases'),
+    );
+    $form['claimnodeownership']['claimable'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Claimable'),
+      '#default_value' => $form['#node']->claimable,
+      '#description' => t('Node can be claimed by those with the permission to do so.'),
+    );
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function claimnodeownership_nodeapi(&$node, $op, $arg = 0) {
+  switch ($op) {
+    case 'load':
+      $result = db_query("SELECT claimable FROM {claim_nodes} WHERE nid = %d", $node->nid);
+      $node->claimable = db_result($result);
+      break;
+
+    case 'prepare':
+      if (!isset($node->claimable)) {
+        $node->claimable = variable_get('claimable_'. $node->type, NODE_CLAIMABILITY);
+      }
+      break;
+
+    case 'insert':
+      db_query("INSERT INTO {claim_nodes} (nid, claimable) VALUES (%d, %d)", $node->nid, $node->claimable);
+      break;
+
+    case 'delete':
+      db_query("DELETE FROM {claim_nodes} WHERE nid = %d", $node->nid);
+      break;
+
+    case 'update':
+      $result = db_query("SELECT claimable FROM {claim_nodes} WHERE nid = %d", $node->nid);
+      if (db_fetch_object($result)) {
+        db_query("UPDATE {claim_nodes} SET claimable = %d WHERE nid = %d", $node->claimable, $node->nid);
+      }
+      else {
+        db_query("INSERT INTO {claim_nodes} (nid, claimable) VALUES (%d, %d)", $node->nid, $node->claimable);
+      }
+      break;
+  }
+}
+
 function claimnodeownership_admin_settings() {
   return drupal_get_form('claimnodeownership_admin_settings_form');
 }
@@ -59,7 +149,7 @@ function claimnodeownership_admin_settin
     '#type' => 'checkboxes',
     '#title' => t('Email Notification'),
     '#default_value' => variable_get('claimnodeownership_notify', array()),
-    '#options' => array('admin' => t('Site Administrator'), 'author' => t('Node Author'),),
+    '#options' => array('admin' => t('Site Administrator'), 'author' => t('Node Author')),
     '#description' => t('Specify who will receive email notification upon a node ownership change is claimed.'),
     );
 
