7 * This file is part of GForge.
9 * GForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * GForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 require_once ('WikiSearchEngine.class.php') ;
26 class GforgeWikiPlugin extends Plugin {
27 function GforgeWikiPlugin () {
29 $this->name = "wiki" ;
30 $this->text = "Wiki" ; // To show in the tabs, use...
31 $this->installdir = 'wiki';
32 // $this->hooks[] = "user_personal_links";//to make a link to the user's personal wiki
33 // $this->hooks[] = "usermenu" ;
34 $this->hooks[] = "groupmenu";
35 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
36 $this->hooks[] = "groupisactivecheckboxpost" ; //
37 // $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
38 // $this->hooks[] = "userisactivecheckboxpost" ; //
39 $this->hooks[] = 'search_engines';
40 $this->hooks[] = 'full_search_engines';
41 $this->hooks[] = 'cssfile';
42 $this->hooks[] = 'activity';
45 function CallHook ($hookname, &$params) {
46 global $G_SESSION,$HTML;
47 $use_wikiplugin = getIntFromRequest('use_wikiplugin');
48 if ($hookname == "usermenu") {
50 if ( ($G_SESSION) && ($G_SESSION->usesPlugin("wiki")) ) {
51 echo ' | ' . $HTML->PrintSubMenu (array ($text),
52 array ('/wiki/u/'. urlencode($G_SESSION->getUnixName()).'/HomePage' ));
54 $this->hooks["usermenu"] = "" ;
55 //$param = "?off=true";
58 } elseif ($hookname == "groupmenu") {
59 $group_id=$params['group'];
60 $project = &group_get_object($group_id);
61 if (!$project || !is_object($project))
63 if ($project->isError())
65 if (!$project->isProject())
67 if ( $project->usesPlugin ( $this->name ) ) {
68 $params['TITLES'][]=$this->text;
69 $params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
71 $this->hooks["groupmenu"] = "";
72 //$params['TITLES'][]=$this->text." [Off]";
73 //$params['DIRS'][]='/plugins/wiki/index.php?off=true';
76 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
77 } elseif ($hookname == "groupisactivecheckbox") {
78 //Check if the group is active
79 $group_id=$params['group'];
80 $group = &group_get_object($group_id);
83 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
84 // checked or unchecked?
85 if ( $group->usesPlugin ( $this->name ) ) {
86 echo "checked=\"checked\"";
91 echo "<strong>Use ".$this->text." Plugin</strong>";
94 } elseif ($hookname == "groupisactivecheckboxpost") {
95 $group_id=$params['group'];
96 $group = &group_get_object($group_id);
97 if ( getIntFromRequest('use_wikiplugin') == 1 ) {
98 $group->setPluginUse ( $this->name );
100 $group->setPluginUse ( $this->name, false );
102 } elseif ($hookname == "userisactivecheckbox") {
103 //check if user is active
104 $user = $params['user'];
107 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
108 // checked or unchecked?
109 if ( $user->usesPlugin ( $this->name ) ) {
110 echo "checked=\"checked\"";
113 echo " /> Use ".$this->text." Plugin";
116 } elseif ($hookname == "userisactivecheckboxpost") {
117 $user = $params['user'];
118 if ( getIntFromRequest('use_wikiplugin') == 1 ) {
119 $user->setPluginUse ( $this->name );
121 $user->setPluginUse ( $this->name, false );
125 echo ' <input type="checkbox" name="use_wikiplugin" value="1" ';
126 // checked or unchecked?
127 if ( $user->usesPlugin ( $this->name ) ) {
128 echo "checked=\"checked\"";
131 echo " /> Use ".$this->text." Plugin";
134 } elseif ($hookname == "user_personal_links") {
135 $userid = $params['user_id'];
136 $user = user_get_object($userid);
137 $user_name = $user->getUnixName();
138 //check if the user has the plugin activated
139 if ($user->usesPlugin($this->name)) {
141 echo util_make_link ('/wiki/u/'.urlencode($user_name).'/HomePage',
142 _('View personal wiki'));
145 } elseif ($hookname == 'search_engines') {
146 // FIXME: when the hook is called, the group_id is not set.
147 // So I use the global variable instead.
148 $group_id = $GLOBALS['group_id'];
150 $group = group_get_object($group_id);
151 if ($group->usesPlugin('wiki')) {
152 $params->addSearchEngine(
153 SEARCH__TYPE_IS_WIKI,
154 new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
155 'WikiHtmlSearchRenderer',
156 _("This project's wiki"), $group_id)
160 } elseif ($hookname == 'full_search_engines') {
161 // FIXME: when the hook is called, the group_id is not set.
162 // So I use the global variable instead.
163 $group_id = $GLOBALS['group_id'];
164 $group = &group_get_object($group_id);
165 if ($group->usesPlugin ( $this->name)) {
166 require_once('plugins/wiki/include/WikiHtmlSearchRenderer.class.php');
167 $wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
168 $validLength = (strlen($params->words) >= 3);
169 if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
170 $html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
174 } elseif ($hookname == 'cssfile') {
175 if (strncmp($_SERVER['REQUEST_URI'], '/wiki/', 6) == 0) {
176 echo '<link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
177 echo '<link rel="stylesheet" type="text/css" href="/wiki/themes/gforge/gforge.css" />';
178 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-fullscreen.css" media="screen" title="Fullscreen" />';
179 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-autonumbering.css" title="Autonumbering" />';
180 echo "\n".'<link rel="alternate stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-rereading.css" title="Rereading Mode" />';
181 echo "\n".'<link rel="stylesheet" type="text/css" href="/wiki/themes/gforge/gforge-print.css" media="print" />';
182 echo "\n".'<base href="'.PHPWIKI_BASE_URL.'" />';
185 } elseif ($hookname == 'activity') {
186 $group_id = $GLOBALS['group_id'];
187 $group = &group_get_object($group_id);
188 if ($group->usesPlugin ( $this->name)) {
189 // Add activities from the wiki plugin if active.
190 // Only major edits are included.
191 $params['ids'][] = 'wiki';
192 $params['texts'][] = $this->text;
194 if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {
196 $pat = '_g'.$group_id.'_';
197 $len = strlen($pat)+1;
198 $wres = db_query_params ('SELECT plugin_wiki_page.id AS id,
199 substring(plugin_wiki_page.pagename from $1) AS pagename,
200 plugin_wiki_version.version AS version,
201 plugin_wiki_version.mtime AS activity_date,
202 plugin_wiki_version.minor_edit AS minor_edit,
203 plugin_wiki_version.versiondata AS versiondata
204 FROM plugin_wiki_page, plugin_wiki_version
205 WHERE plugin_wiki_page.id=plugin_wiki_version.id
206 AND mtime BETWEEN $2 AND $3
208 AND substring(plugin_wiki_page.pagename from 0 for $1) = $4
209 ORDER BY mtime DESC',
216 while ($arr =& db_fetch_array($wres)) {
217 $group_name = $group->getUnixName();
218 $data = unserialize($arr['versiondata']);
219 if (!isset($cache[$data['author']])) {
220 $r = db_query_params ('SELECT user_name FROM users WHERE realname = $1',
221 array ($data['author']));
222 if ($a = db_fetch_array($r)) {
223 $cache[$data['author']] = $a['user_name'];
225 $cache[$data['author']] = '';
228 $arr['section'] = 'wiki';
229 $arr['user_name'] = $cache[$data['author']];
230 $arr['realname'] = $data['author'];
231 $arr['icon']=html_image("ic/wiki20g.png","20","20",array("border"=>"0","alt"=>"Wiki"));
232 $arr['title'] = 'Wiki Page '.$arr['pagename'];
233 $arr['link'] = '/wiki/g/'.$group_name.'/'.$arr['pagename'];
234 $arr['description']= $arr['title'];
235 $params['results'][] = $arr;
245 // c-file-style: "bsd"