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[] = "groupmenu";
34 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
35 $this->hooks[] = "groupisactivecheckboxpost" ; //
36 $this->hooks[] = "project_admin_plugins"; // to show up in the project admin page
37 $this->hooks[] = 'search_engines';
38 $this->hooks[] = 'full_search_engines';
39 $this->hooks[] = 'cssfile';
40 $this->hooks[] = 'activity';
43 function CallHook ($hookname, $params) {
44 global $G_SESSION,$HTML;
45 if (is_array($params) && isset($params['group']))
46 $group_id=$params['group'];
47 $use_wikiplugin = getIntFromRequest('use_wikiplugin');
48 if ($hookname == "groupmenu") {
49 $project = &group_get_object($group_id);
50 if (!$project || !is_object($project))
52 if ($project->isError())
54 if (!$project->isProject())
56 if ( $project->usesPlugin ( $this->name ) ) {
57 $params['TITLES'][]=$this->text;
58 $params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
60 $this->hooks["groupmenu"] = "";
61 //$params['TITLES'][]=$this->text." [Off]";
62 //$params['DIRS'][]='/plugins/wiki/index.php?off=true';
65 if (isset($params['toptab'])) {
66 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
68 } elseif ($hookname == "groupisactivecheckbox") {
69 //Check if the group is active
70 $group = &group_get_object($group_id);
73 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
74 // checked or unchecked?
75 if ( $group->usesPlugin ( $this->name ) ) {
76 echo "checked=\"checked\"";
81 echo "<strong>Use ".$this->text." Plugin</strong>";
84 } elseif ($hookname == "groupisactivecheckboxpost") {
85 $group = &group_get_object($group_id);
86 if ( $use_wikiplugin == 1 ) {
87 $group->setPluginUse ( $this->name );
89 $group->setPluginUse ( $this->name, false );
91 } elseif ($hookname == "project_admin_plugins") {
92 // this displays the link in the project admin options page to its administration page.
93 $group_id = $params['group_id'];
94 $group = &group_get_object($group_id);
95 if ( $group->usesPlugin ( $this->name ) ) {
96 echo '<p><a href="/plugins/wiki/wikiadmin.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _('Wiki Admin') . '</a></p>';
98 } elseif ($hookname == 'search_engines') {
99 // FIXME: when the hook is called, the group_id is not set.
100 // So I use the global variable instead.
101 $group_id = $GLOBALS['group_id'];
103 $group = group_get_object($group_id);
104 if (!$group || !is_object($group)) {
107 if ($group->usesPlugin('wiki')) {
108 $searchManager = $params['object'];
109 $searchManager->addSearchEngine(
110 SEARCH__TYPE_IS_WIKI,
111 new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
112 'WikiHtmlSearchRenderer',
113 _("This projects's wiki"), $group_id)
117 } elseif ($hookname == 'full_search_engines') {
118 // FIXME: when the hook is called, the group_id is not set.
119 // So I use the global variable instead.
120 $group_id = $GLOBALS['group_id'];
121 $group = &group_get_object($group_id);
122 if ($group->usesPlugin ( $this->name)) {
123 global $gfwww, $gfcommon, $gfplugins;
124 require_once('plugins/wiki/common/WikiHtmlSearchRenderer.class.php');
125 $wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
126 $validLength = (strlen($params->words) >= 3);
127 if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
128 $html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
132 } elseif ($hookname == 'cssfile') {
133 if (strncmp(preg_replace('/^\/+/', '/', $_SERVER['REQUEST_URI']), '/wiki/', 6) == 0) {
134 echo '<link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
135 echo '<link rel="stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge.css" />';
136 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-fullscreen.css" media="screen" title="Fullscreen" />';
137 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-autonumbering.css" title="Autonumbering" />';
138 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-rereading.css" title="Rereading Mode" />';
139 echo "\n".'<link rel="stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-print.css" media="print" />';
140 echo "\n".'<base href="'.PHPWIKI_BASE_URL.'" />';
143 } elseif ($hookname == 'activity') {
144 $group = &group_get_object($group_id);
145 if ($group->usesPlugin ( $this->name)) {
146 // Add activities from the wiki plugin if active.
147 // Only major edits are included.
148 $params['ids'][] = 'wiki';
149 $params['texts'][] = $this->text;
151 if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {
153 $pat = '_g'.$group_id.'_';
154 $len = strlen($pat)+1;
155 $wres = db_query_params ("SELECT plugin_wiki_page.id AS id,
156 substring(plugin_wiki_page.pagename from $len) AS pagename,
157 plugin_wiki_version.version AS version,
158 plugin_wiki_version.mtime AS activity_date,
159 plugin_wiki_version.minor_edit AS minor_edit,
160 plugin_wiki_version.versiondata AS versiondata
161 FROM plugin_wiki_page, plugin_wiki_version
162 WHERE plugin_wiki_page.id=plugin_wiki_version.id
163 AND mtime BETWEEN $1 AND $2
165 AND substring(plugin_wiki_page.pagename from 0 for $len) = $3
166 ORDER BY mtime DESC",
167 array ($params['begin'],
172 while ($arr = db_fetch_array($wres)) {
173 $group_name = $group->getUnixName();
174 $data = unserialize($arr['versiondata']);
175 if (!isset($cache[$data['author']])) {
176 $r = db_query_params ('SELECT user_name FROM users WHERE realname = $1',
177 array ($data['author']));
179 if ($a = db_fetch_array($r)) {
180 $cache[$data['author']] = $a['user_name'];
182 $cache[$data['author']] = '';
185 $arr['user_name'] = $cache[$data['author']];
186 $arr['realname'] = $data['author'];
187 $arr['icon']=html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
188 $arr['title'] = 'Wiki Page '.$arr['pagename'];
189 $arr['link'] = '/wiki/g/'.$group_name.'/'.urlencode($arr['pagename']);
190 $arr['description']= $arr['title'];
191 $params['results'][] = $arr;
201 // c-file-style: "bsd"