4 * Wiki Search Engine for Fusionforge
6 * Copyright 2006 (c) Alain Peyrat
8 * This file is part of Fusionforge.
10 * Fusionforge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Fusionforge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Fusionforge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 require_once $gfplugins.'wiki/common/WikiSearchEngine.class.php';
28 class GforgeWikiPlugin extends Plugin {
29 function GforgeWikiPlugin () {
31 $this->name = "wiki" ;
32 $this->text = "Wiki" ; // To show in the tabs, use...
33 $this->installdir = 'wiki';
34 $this->hooks[] = "groupmenu";
35 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
36 $this->hooks[] = "groupisactivecheckboxpost" ; //
37 $this->hooks[] = "project_admin_plugins"; // to show up in the project admin page
38 $this->hooks[] = 'search_engines';
39 $this->hooks[] = 'full_search_engines';
40 $this->hooks[] = 'cssfile';
41 $this->hooks[] = 'project_public_area';
42 $this->hooks[] = 'activity';
45 function CallHook ($hookname, & $params) {
46 global $G_SESSION,$HTML;
47 if (is_array($params) && isset($params['group']))
48 $group_id=$params['group'];
49 if ($hookname == "groupmenu") {
50 $project = group_get_object($group_id);
51 if (!$project || !is_object($project))
53 if ($project->isError())
55 if (!$project->isProject())
57 if ( $project->usesPlugin ( $this->name ) ) {
58 $params['TITLES'][]=$this->text;
59 $params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
61 $this->hooks["groupmenu"] = "";
62 //$params['TITLES'][]=$this->text." [Off]";
63 //$params['DIRS'][]='/wiki/index.php?off=true';
66 if (isset($params['toptab'])) {
67 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
69 } elseif ($hookname == "project_admin_plugins") {
70 // this displays the link in the project admin options page to its administration page.
71 $group_id = $params['group_id'];
72 $group = group_get_object($group_id);
73 if ( $group->usesPlugin ( $this->name ) ) {
74 echo '<p><a href="/wiki/wikiadmin.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _('Wiki Admin') . '</a></p>';
76 } elseif ($hookname == 'search_engines') {
77 // FIXME: when the hook is called, the group_id is not set.
78 // So I use the global variable instead.
79 $group_id = $GLOBALS['group_id'];
81 $group = group_get_object($group_id);
82 if (!$group || !is_object($group)) {
85 if ($group->usesPlugin('wiki')) {
86 $searchManager = $params['object'];
87 $searchManager->addSearchEngine(
89 new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
90 'WikiHtmlSearchRenderer',
91 _("This projects's wiki"), $group_id)
95 } elseif ($hookname == 'full_search_engines') {
96 // FIXME: when the hook is called, the group_id is not set.
97 // So I use the global variable instead.
98 $group_id = $GLOBALS['group_id'];
99 $group = group_get_object($group_id);
100 if ($group->usesPlugin ( $this->name)) {
101 global $gfwww, $gfcommon, $gfplugins;
102 require_once('plugins/wiki/common/WikiHtmlSearchRenderer.class.php');
103 $wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
104 $validLength = (strlen($params->words) >= 3);
105 if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
106 $html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
110 } elseif ($hookname == 'cssfile') {
111 if (defined('PHPWIKI_BASE_URL')) {
112 echo '<link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
113 echo "\n".' <link rel="stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge.css" />';
114 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-fullscreen.css" media="screen" title="Fullscreen" />';
115 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-autonumbering.css" title="Autonumbering" />';
116 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-rereading.css" title="Rereading Mode" />';
117 echo "\n".'<link rel="stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-print.css" media="print" />';
118 echo "\n".'<base href="'.PHPWIKI_BASE_URL.'" />';
121 } elseif ($hookname == "project_public_area") {
122 $project = group_get_object($params['group_id']);
123 if (!$project || !is_object($project)) {
126 if ($project->isError()) {
129 if ( $project->usesPlugin ( $this->name ) ) {
130 echo '<div class="public-area-box">';
131 print '<a href="'. util_make_url ('/wiki/g/'.$project->getUnixName().'/HomePage').'">';
132 print html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
137 } elseif ($hookname == 'activity') {
138 $group = group_get_object($group_id);
139 if ($group->usesPlugin ( $this->name)) {
140 // Add activities from the wiki plugin if active.
141 // Only major edits are included.
142 $params['ids'][] = 'wiki';
143 $params['texts'][] = $this->text;
145 if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {
147 $pat = '_g'.$group_id.'_';
148 $len = strlen($pat)+1;
149 $wres = db_query_params ("SELECT plugin_wiki_page.id AS id,
150 substring(plugin_wiki_page.pagename from $len) AS pagename,
151 plugin_wiki_version.version AS version,
152 plugin_wiki_version.mtime AS activity_date,
153 plugin_wiki_version.minor_edit AS minor_edit,
154 plugin_wiki_version.versiondata AS versiondata
155 FROM plugin_wiki_page, plugin_wiki_version
156 WHERE plugin_wiki_page.id=plugin_wiki_version.id
157 AND mtime BETWEEN $1 AND $2
159 AND substring(plugin_wiki_page.pagename from 0 for $len) = $3
160 ORDER BY mtime DESC",
161 array ($params['begin'],
166 while ($arr = db_fetch_array($wres)) {
167 $group_name = $group->getUnixName();
168 $data = unserialize($arr['versiondata']);
169 if (!isset($cache[$data['author']])) {
170 $r = db_query_params ('SELECT user_name, user_id FROM users WHERE realname = $1',
171 array ($data['author']));
173 if ($a = db_fetch_array($r)) {
174 $cache[$data['author']] = $a['user_name'];
175 $cache[$data['author_id']] = $a['user_id'];
177 $cache[$data['author']] = '';
178 $cache[$data['author_id']] = '';
181 $arr['user_name'] = $cache[$data['author']];
182 $arr['user_id'] = $cache[$data['author_id']];
183 $arr['realname'] = $data['author'];
184 $arr['icon']=html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
185 $arr['title'] = 'Wiki Page '.$arr['pagename'];
186 $arr['link'] = '/wiki/g/'.$group_name.'/'.urlencode($arr['pagename']);
187 $arr['description']= $arr['title'];
188 $params['results'][] = $arr;
198 // c-file-style: "bsd"