organic groups support
dugh - August 9, 2008 - 16:37
| Project: | Wikitools |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
It would be nice to have a separate wiki for each group. You can do that now, but freelinking links will link to any page regardless of group.
You could just add one option, whether to link to pages in other groups or not.
Here is a related issue for og support in the freelinking module.
http://drupal.org/node/106852

#1
I have this working by adding the group ids to the query string of the freelinking url (freelinking/Pagename?gids[]=424), but it's not really done in a manner that will work for everyone.
I attached my copies of the modified freelinking & wikitools modules.
It has these limitations:
I am using the latest 5.x version of the organic groups module. I have my wiki content type set as being able to be posted to groups. This forces people to choose a group when submitting a wiki page (unless you are admin).
I am using freelinking and wikitools, with 'hijack freelinking' checked.
I am not using wikiword links (don't like them).
I unchecked 'Unique Titles' in wikitools preferences, to allow pages of the same title to be submitted (would need to be fixed properly eventually).
My code also only supports one group per wiki page. If you check off a wiki page as being in multiple groups, only the first group will show up. This is an og module limitation, but could be overcome.
I am using global_redirect module too and of course pathauto. I have a pathauto node path for wiki pages like this: [type-name]/[ogname-raw]/[title-raw].
Here is the code:
In freelinking.module around 278 I changed the $replacement line to this:
$groupcontext = '';if (module_exists('og') && $group = og_get_group_context()) {
$groupcontext = "gids[]=".$group->nid;
}
$replacement = l($phrase, 'freelinking/' .
rawurlencode($freelink),
array('class' => 'freelinking'),
$groupcontext);
Make a similar change a little lower if you want wikiwords to work as well with groups.
This is not really necessary since wikitools overrides this, but I also add this around line 368 near the end of function _freelinking_make_link before the call to _freelinking_store:
if ($gids = $_REQUEST['gids']) {foreach ($gids as $gid) {
$freelink['args'] .= "&gids[]=".$gid;
}
}
Changes to wikitools.module:
Change the wikitools_create_url function (around line 589) to this:
function wikitools_create_url($type, $title) {$query = 'edit[title]='. urlencode($title);
if ($gids = $_REQUEST['gids']) {
foreach ($gids as $gid) {
$query .= "&gids[]=".$gid;
}
}
return url("node/add/$type", $query);
}
The other fix (around line 432 in wikitools.module inside wikitools_handle_request function:
if (!isset($_REQUEST['gids']) || !module_exists('og')) {
$result = db_query("SELECT nid, type FROM {node} WHERE LOWER(title) = LOWER('%s')", $page_name);
} else {
//TODO: add support for multi-group nodes
$gid = intval(current($_REQUEST['gids']));
$sql = "SELECT n.nid, n.type FROM {node} n ";
$sql .= "INNER JOIN {og_ancestry} oga ON n.nid = oga.nid ";
$sql .= "WHERE LOWER(n.title) = LOWER('%s') ";
$sql .= "AND oga.group_nid = %d";
$result = db_query($sql, $page_name, $gid);
}
So now if you have a link like [[PageName]] and multiple groups have wiki pages with that name, it will go to the correct one in the current group, or if no page of that name exists in the group, it will make it so that when you create the page, the current group will be pre-selected.
One other issue with the code - if you have a link to a page that doesn't exist in current group but does in another, the link will go the other group's page. If you don't want that to happen, uncheck 'Automatic Redirect' in the wikitools preferences. Actually if you uncheck that, it will list the pages from other groups, but still display the link to add a new page with that name in your own group.