File: WikiPlugin.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (216 lines) | stat: -rw-r--r-- 8,672 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
 * WikiPlugin Class
 * Wiki Search Engine for Fusionforge
 *
 * Copyright 2006 (c) Alain Peyrat
 *
 * This file is part of Fusionforge.
 *
 * Fusionforge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Fusionforge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

global $gfplugins;
require_once $gfplugins.'wiki/common/WikiSearchEngine.class.php';

class FusionForgeWikiPlugin extends Plugin {
	function __construct() {
		$this->Plugin() ;
		$this->name = "wiki" ;
		$this->text = _("Wiki"); // To show in the tabs, use...
		$this->installdir = 'wiki';
		$this->hooks[] = "groupmenu";
		$this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
		$this->hooks[] = "groupisactivecheckboxpost";
		$this->hooks[] = "project_admin_plugins"; // to show up in the project admin page
		$this->hooks[] = 'search_engines';
		$this->hooks[] = 'full_search_engines';
		$this->hooks[] = 'cssfile';
		$this->hooks[] = 'project_public_area';
		$this->hooks[] = 'activity';
		$this->hooks[] = 'site_admin_option_hook';
	}

	function CallHook ($hookname, & $params) {
		if (is_array($params) && isset($params['group']))
			$group_id=$params['group'];
		if ($hookname == "groupmenu") {
			$project = group_get_object($group_id);
			if (!$project || !is_object($project))
				return;
			if ($project->isError())
				return;
			if (!$project->isProject())
				return;
			if ($project->usesPlugin($this->name)) {
				$params['TITLES'][]=$this->text;
				$params['DIRS'][]='/wiki/g/'.$project->getUnixName().'/HomePage';
			} else {
				$this->hooks["groupmenu"] = "";
				//$params['TITLES'][]=$this->text." [Off]";
				//$params['DIRS'][]='/wiki/index.php?off=true';
			}

			if (isset($params['toptab'])) {
				(($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
			}
		} elseif ($hookname == "project_admin_plugins") {
			// this displays the link in the project admin options page to its administration page.
			$group_id = $params['group_id'];
			$group = group_get_object($group_id);
			if ($group->usesPlugin($this->name)) {
				echo '<p><a href="/wiki/wikiadmin.php?group_id=' . $group->getID() . '&amp;type=admin&amp;pluginname=' . $this->name . '">' . _('Wiki Admin') . '</a></p>';
			}
		} elseif ($hookname == 'search_engines') {
			// FIXME: when the hook is called, the group_id is not set.
			// So I use the global variable instead.
			$group_id = $GLOBALS['group_id'];
			if ($group_id) {
				$group = group_get_object($group_id);
				if (!$group || !is_object($group)) {
					return;
				}
				if ($group->usesPlugin('wiki')) {
					$searchManager = $params['object'];
					$searchManager->addSearchEngine(
						SEARCH__TYPE_IS_WIKI,
						new WikiSearchEngine(SEARCH__TYPE_IS_WIKI,
								'WikiHtmlSearchRenderer',
						_("This project's wiki"), $group_id)
					);
				}
			}
		} elseif ($hookname == 'full_search_engines') {
			// FIXME: when the hook is called, the group_id is not set.
			// So I use the global variable instead.
			$group_id = $GLOBALS['group_id'];
			$group = group_get_object($group_id);
			if ($group->usesPlugin ( $this->name)) {
				global $gfwww, $gfcommon, $gfplugins;
				require_once 'plugins/wiki/common/WikiHtmlSearchRenderer.class.php';
				$wikiRenderer = new WikiHtmlSearchRenderer($params->words, $params->offset, $params->isExact, $params->groupId);
				$validLength = (strlen($params->words) >= 3);
				if ($validLength || (is_numeric($params->words) && $wikiRenderer->searchQuery->implementsSearchById())) {
					$html = $params->getPartResult($wikiRenderer, 'short_wiki', 'Wiki');
					return $html;
				}
			}
		} elseif ($hookname == 'cssfile') {
			if (defined('PHPWIKI_BASE_URL')) {
				use_stylesheet('/wiki/themes/fusionforge/fusionforge.css');
				use_stylesheet('/wiki/themes/fusionforge/fusionforge-print.css', 'print');

				echo '    <link rel="alternate" type="application/x-wiki" title="Edit this page!" href="'.$_SERVER['PHP_SELF'].'?action=edit" />';
				echo "\n".'    <link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-fullscreen.css" media="screen" title="Fullscreen" />';
				echo "\n".'    <link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-autonumbering.css" title="Autonumbering" />';
				echo "\n".'    <link rel="alternate stylesheet" type="text/css" href="/wiki/themes/fusionforge/fusionforge-rereading.css" title="Rereading Mode" />';
				echo "\n".'    <base href="'.PHPWIKI_BASE_URL.'" />';
				echo "\n";
			}
		} elseif ($hookname == "project_public_area") {
			$project = group_get_object($params['group_id']);
			if (!$project || !is_object($project)) {
				return;
			}
			if ($project->isError()) {
				return;
			}
			if ($project->usesPlugin($this->name)) {
				echo '<div class="public-area-box">';
				print '<a href="'. util_make_url ('/wiki/g/'.$project->getUnixName().'/HomePage').'">';
				print html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
				print ' Wiki';
				print '</a>';
				echo '</div>';
			}
		} elseif ($hookname == 'activity') {
			$group = group_get_object($params['group_id']);
			if (!$group || !is_object($group)) {
				return;
			}
			if ($group->isError()) {
				return;
			}
			if ($group->usesPlugin($this->name)) {
				// Add activities from the wiki plugin if active.
				// Only major edits are included.
				$params['ids'][] = 'wiki';
				$params['texts'][] = $this->text;

				if (count($params['show']) < 1 || array_search('wiki',$params['show']) !== false) {

					$pat = '_g'.$group_id.'_';
					$len = strlen($pat)+1;
                    $encoding = pg_client_encoding();
					// @ToDo: to remove after wiki tables convert
					pg_set_client_encoding("iso-8859-1");
					$wres = db_query_params ("SELECT plugin_wiki_page.id AS id,
							substring(plugin_wiki_page.pagename from $len) AS pagename,
							plugin_wiki_version.version AS version,
							plugin_wiki_version.mtime AS activity_date,
							plugin_wiki_version.minor_edit AS minor_edit,
							plugin_wiki_version.versiondata AS versiondata
						FROM plugin_wiki_page, plugin_wiki_version
						WHERE plugin_wiki_page.id=plugin_wiki_version.id
							AND mtime BETWEEN $1 AND $2
							AND minor_edit=0
							AND substring(plugin_wiki_page.pagename from 0 for $len) = $3
						ORDER BY mtime DESC",
                                                                 array ($params['begin'],
                                                                        $params['end'],
                                                                        $pat));
					// To remove after wiki tables convert
					pg_set_client_encoding($encoding);

					$cache = array();
					while ($arr = db_fetch_array($wres)) {
						$group_name = $group->getUnixName();
						$page_name = preg_replace('/%2f/i', '/', rawurlencode($arr['pagename']));
						$data = unserialize($arr['versiondata']);
						if (!isset($cache[$data['author']])) {
							$r = db_query_params ('SELECT user_name, user_id FROM users WHERE realname = $1',
										array ($data['author']));

							if ($a = db_fetch_array($r)) {
								$cache[$data['author']]['user_name'] = $a['user_name'];
								$cache[$data['author']]['user_id'] = $a['user_id'];
							} else {
								$cache[$data['author']]['user_name'] = '';
								$cache[$data['author']]['user_id'] = '';
							}
						}
						$arr['user_name'] = $cache[$data['author']]['user_name'];
						$arr['user_id'] = $cache[$data['author']]['user_id'];
						$arr['realname'] = $data['author'];
						$arr['icon']=html_image("ic/wiki20g.png","20","20",array("alt"=>"Wiki"));
						$arr['title'] = 'Wiki Page '.$arr['pagename'];
						$arr['link'] = '/wiki/g/'.$group_name.'/'.$page_name;
						$arr['description']= $arr['title'];
						$params['results'][] = $arr;
					}
				}
			}
		}		
	}

	function site_admin_option_hook($params) {
		echo '<li>'.util_make_link('/wiki/wikilist.php', _('List of active wikis in Forge')).'</li>';
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: