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 along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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';
43 $this->hooks[] = 'site_admin_option_hook';
46 function CallHook ($hookname, & $params) {
47 global $G_SESSION,$HTML;
48 if (is_array($params) && isset($params['group']))
49 $group_id=$params['group'];
50 if ($hookname == "groupmenu") {
51 $project = group_get_object($group_id);
52 if (!$project || !is_object($project))
54 if ($project->isError())
56 if (!$project->isProject())
58 if ( $project->usesPlugin ( $this->name ) ) {
59 $params['TITLES'][]=$this->text;
60 $params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
61 $params['ADMIN'][]='';
63 $this->hooks["groupmenu"] = "";
64 //$params['TITLES'][]=$this->text." [Off]";
65 //$params['DIRS'][]='/wiki/index.php?off=true';
68 if (isset($params['toptab'])) {
69 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
71 } elseif ($hookname == "project_admin_plugins") {
72 // this displays the link in the project admin options page to its administration page.
73 $group_id = $params['group_id'];
74 $group = group_get_object($group_id);
75 if ( $group->usesPlugin ( $this->name ) ) {
76 echo '<p><a href="/wiki/wikiadmin.php?group_id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _('Wiki Admin') . '</a></p>';
78 } elseif ($hookname == 'search_engines') {
79 // FIXME: when the hook is called, the group_id is not set.
80 // So I use the global variable instead.
81 $group_id = $GLOBALS['group_id'];
83 $group = group_get_object($group_id);
84 if (!$group || !is_object($group)) {
87 if ($group->usesPlugin('wiki')) {
88 $searchManager = $params['object'];
89 $searchManager->addSearchEngine(
91 new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
92 'WikiHtmlSearchRenderer',
93 _("This project's wiki"), $group_id)
97 } elseif ($hookname == 'full_search_engines') {
98 // FIXME: when the hook is called, the group_id is not set.
99 // So I use the global variable instead.
100 $group_id = $GLOBALS['group_id'];
101 $group = group_get_object($group_id);
102 if ($group->usesPlugin ( $this->name)) {
103 global $gfwww, $gfcommon, $gfplugins;
104 require_once('plugins/wiki/common/WikiHtmlSearchRenderer.class.php');
105 $wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
106 $validLength = (strlen($params->words) >= 3);
107 if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
108 $html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
112 } elseif ($hookname == 'cssfile') {
113 if (defined('PHPWIKI_BASE_URL')) {
114 use_stylesheet('/wiki/themes/fusionforge/fusionforge.css');
115 use_stylesheet('/wiki/themes/fusionforge/fusionforge-print.css', 'print');
116 echo '<link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
117 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-fullscreen.css" media="screen" title="Fullscreen" />';
118 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-autonumbering.css" title="Autonumbering" />';
119 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-rereading.css" title="Rereading Mode" />';
120 echo "\n".'<base href="'.PHPWIKI_BASE_URL.'" />';
123 } elseif ($hookname == "project_public_area") {
124 $project = group_get_object($params['group_id']);
125 if (!$project || !is_object($project)) {
128 if ($project->isError()) {
131 if ( $project->usesPlugin ( $this->name ) ) {
132 echo '<div class="public-area-box">';
133 print '<a href="'. util_make_url ('/wiki/g/'.$project->getUnixName().'/HomePage').'">';
134 print html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
139 } elseif ($hookname == 'activity') {
140 $group = group_get_object($params['group_id']);
141 if (!$group || !is_object($group)) {
144 if ($group->isError()) {
147 if ($group->usesPlugin ( $this->name)) {
148 // Add activities from the wiki plugin if active.
149 // Only major edits are included.
150 $params['ids'][] = 'wiki';
151 $params['texts'][] = $this->text;
153 if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {
155 $pat = '_g'.$group_id.'_';
156 $len = strlen($pat)+1;
157 $wres = db_query_params ("SELECT plugin_wiki_page.id AS id,
158 substring(plugin_wiki_page.pagename from $len) AS pagename,
159 plugin_wiki_version.version AS version,
160 plugin_wiki_version.mtime AS activity_date,
161 plugin_wiki_version.minor_edit AS minor_edit,
162 plugin_wiki_version.versiondata AS versiondata
163 FROM plugin_wiki_page, plugin_wiki_version
164 WHERE plugin_wiki_page.id=plugin_wiki_version.id
165 AND mtime BETWEEN $1 AND $2
167 AND substring(plugin_wiki_page.pagename from 0 for $len) = $3
168 ORDER BY mtime DESC",
169 array ($params['begin'],
174 while ($arr = db_fetch_array($wres)) {
175 $group_name = $group->getUnixName();
176 $data = unserialize($arr['versiondata']);
177 if (!isset($cache[$data['author']])) {
178 $r = db_query_params ('SELECT user_name, user_id FROM users WHERE realname = $1',
179 array ($data['author']));
181 if ($a = db_fetch_array($r)) {
182 $cache[$data['author']] = $a['user_name'];
183 $cache[$data['author_id']] = $a['user_id'];
185 $cache[$data['author']] = '';
186 $cache[$data['author_id']] = '';
189 $arr['user_name'] = $cache[$data['author']];
190 $arr['user_id'] = $cache[$data['author_id']];
191 $arr['realname'] = $data['author'];
192 $arr['icon']=html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
193 $arr['title'] = 'Wiki Page '.$arr['pagename'];
194 $arr['link'] = '/wiki/g/'.$group_name.'/'.rawurlencode($arr['pagename']);
195 $arr['description']= $arr['title'];
196 $params['results'][] = $arr;
203 function site_admin_option_hook($params) {
204 echo '<li>'.util_make_link('/wiki/wikilist.php', _('List of active wikis in Forge')).'</li>';
210 // c-file-style: "bsd"