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->hooks[] = "user_personal_links"; //to make a link to the user's personal wiki
34 // $this->hooks[] = "usermenu" ;
35 $this->hooks[] = "groupmenu";
36 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
37 $this->hooks[] = "groupisactivecheckboxpost" ; //
38 $this->hooks[] = "project_admin_plugins"; // to show up in the project admin page
39 // $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
40 // $this->hooks[] = "userisactivecheckboxpost" ; //
41 $this->hooks[] = 'search_engines';
42 $this->hooks[] = 'full_search_engines';
43 $this->hooks[] = 'cssfile';
44 $this->hooks[] = 'activity';
47 function CallHook ($hookname, & $params) {
48 global $G_SESSION,$HTML;
49 if (is_array($params) && isset($params['group']))
50 $group_id=$params['group'];
51 $use_wikiplugin = getIntFromRequest('use_wikiplugin');
52 if ($hookname == "usermenu") {
54 if ( ($G_SESSION) && ($G_SESSION->usesPlugin("wiki")) ) {
55 $param = '?id=' . $G_SESSION->getId() . '&type=u';
56 echo ' | ' . $HTML->PrintSubMenu (array ($text),
57 array ('/wiki/u/'. $user_name.'/HomePage' ));
59 $this->hooks["usermenu"] = "" ;
60 //$param = "?off=true";
63 } elseif ($hookname == "groupmenu") {
64 $project = &group_get_object($group_id);
65 if (!$project || !is_object($project))
67 if ($project->isError())
69 if (!$project->isProject())
71 if ( $project->usesPlugin ( $this->name ) ) {
72 $params['TITLES'][]=$this->text;
73 $params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
75 $this->hooks["groupmenu"] = "";
76 //$params['TITLES'][]=$this->text." [Off]";
77 //$params['DIRS'][]='/plugins/wiki/index.php?off=true';
80 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
81 } elseif ($hookname == "groupisactivecheckbox") {
82 //Check if the group is active
83 $group = &group_get_object($group_id);
86 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
87 // checked or unchecked?
88 if ( $group->usesPlugin ( $this->name ) ) {
89 echo "checked=\"checked\"";
94 echo "<strong>Use ".$this->text." Plugin</strong>";
97 } elseif ($hookname == "groupisactivecheckboxpost") {
98 $group = &group_get_object($group_id);
99 if ( $use_wikiplugin == 1 ) {
100 $group->setPluginUse ( $this->name );
102 $group->setPluginUse ( $this->name, false );
104 } elseif ($hookname == "project_admin_plugins") {
105 // this displays the link in the project admin options page to its administration page.
106 $group_id = $params['group_id'];
107 $group = &group_get_object($group_id);
108 if ( $group->usesPlugin ( $this->name ) ) {
109 echo '<p><a href="/plugins/wiki/wikiadmin.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _('Wiki Admin') . '</a></p>';
111 } elseif ($hookname == "userisactivecheckbox") {
112 //check if user is active
113 $user = $params['user'];
116 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
117 // checked or unchecked?
118 if ( $user->usesPlugin ( $this->name ) ) {
119 echo "checked=\"checked\"";
122 echo " /> Use ".$this->text." Plugin";
125 } elseif ($hookname == "userisactivecheckboxpost") {
126 $user = $params['user'];
127 if ( getIntFromRequest('use_wikiplugin') == 1 ) {
128 $user->setPluginUse ( $this->name );
130 $user->setPluginUse ( $this->name, false );
134 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
135 // checked or unchecked?
136 if ( $user->usesPlugin ( $this->name ) ) {
137 echo "checked=\"checked\"";
140 echo " /> Use ".$this->text." Plugin";
143 } elseif ($hookname == "user_personal_links") {
144 $userid = $params['user_id'];
145 $user = user_get_object($userid);
146 $text = $params['text'];
147 //check if the user has the plugin activated
148 if ($user->usesPlugin($this->name)) {
150 <a href="/plugins/wiki/index.php?id=' . $userid . '&type=u">' . _("View Personal Wiki") .'</a></p>';
152 } elseif ($hookname == 'search_engines') {
153 // FIXME: when the hook is called, the group_id is not set.
154 // So I use the global variable instead.
155 $group_id = $GLOBALS['group_id'];
157 $group = group_get_object($group_id);
158 if (!$group || !is_object($group)) {
161 if ($group->usesPlugin('wiki')) {
162 $searchManager = $params['object'];
163 $searchManager->addSearchEngine(
164 SEARCH__TYPE_IS_WIKI,
165 new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
166 'WikiHtmlSearchRenderer',
167 _("This projects's wiki"), $group_id)
171 } elseif ($hookname == 'full_search_engines') {
172 // FIXME: when the hook is called, the group_id is not set.
173 // So I use the global variable instead.
174 $group_id = $GLOBALS['group_id'];
175 $group = &group_get_object($group_id);
176 if ($group->usesPlugin ( $this->name)) {
177 require_once('plugins/wiki/common/WikiHtmlSearchRenderer.class.php');
178 $wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
179 $validLength = (strlen($params->words) >= 3);
180 if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
181 $html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
185 } elseif ($hookname == 'cssfile') {
186 if (strncmp(preg_replace('/^\/+/', '/', $_SERVER['REQUEST_URI']), '/wiki/', 6) == 0) {
187 echo '<link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
188 echo '<link rel="stylesheet" type="text/css" href="/wiki/themes/gforge/gforge.css" />';
189 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-fullscreen.css" media="screen" title="Fullscreen" />';
190 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-autonumbering.css" title="Autonumbering" />';
191 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-rereading.css" title="Rereading Mode" />';
192 echo "\n".'<link rel="stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-print.css" media="print" />';
193 echo "\n".'<base href="'.PHPWIKI_BASE_URL.'" />';
196 } elseif ($hookname == 'activity') {
197 $group = &group_get_object($group_id);
198 if ($group->usesPlugin ( $this->name)) {
199 // Add activities from the wiki plugin if active.
200 // Only major edits are included.
201 $params['ids'][] = 'wiki';
202 $params['texts'][] = $this->text;
204 if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {
206 $pat = '_g'.$group_id.'_';
207 $len = strlen($pat)+1;
208 $wres = db_query_params ('SELECT plugin_wiki_page.id AS id,
209 substring(plugin_wiki_page.pagename from $1) AS pagename,
210 plugin_wiki_version.version AS version,
211 plugin_wiki_version.mtime AS activity_date,
212 plugin_wiki_version.minor_edit AS minor_edit,
213 plugin_wiki_version.versiondata AS versiondata
214 FROM plugin_wiki_page, plugin_wiki_version
215 WHERE plugin_wiki_page.id=plugin_wiki_version.id
216 AND mtime BETWEEN $2 AND $3
218 AND substring(plugin_wiki_page.pagename from 0 for $1) = $4
219 ORDER BY mtime DESC',
226 while ($arr = db_fetch_array($wres)) {
227 $group_name = $group->getUnixName();
228 $data = unserialize($arr['versiondata']);
229 if (!isset($cache[$data['author']])) {
230 $r = db_query_params ('SELECT user_name FROM users WHERE realname = $1',
231 array ($data['author']));
233 if ($a = db_fetch_array($r)) {
234 $cache[$data['author']] = $a['user_name'];
236 $cache[$data['author']] = '';
239 $arr['user_name'] = $cache[$data['author']];
240 $arr['realname'] = $data['author'];
241 $arr['icon']=html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
242 $arr['title'] = 'Wiki Page '.$arr['pagename'];
243 $arr['link'] = '/wiki/g/'.$group_name.'/'.$arr['pagename'];
244 $arr['description']= $arr['title'];
245 $params['results'][] = $arr;
255 // c-file-style: "bsd"