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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
<?php
# Lifter001: DONE
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/*
wiki.php - (No longer so) Simple WikiWikiWeb in Stud.IP
@module wiki
@author Tobias Thelen <tthelen@uos.de>
Copyright (C) 2003 Tobias Thelen <tthelen@uni-osnabrueck.de>
Contains code (regex for WikiWord detection) from Blast Wiki http://www.roboticboy.com/wiki/ (GPL'd)
Contains code (diff routine) from PukiWiki http://www.pukiwiki.org (GPL'd)
This program 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.
This program 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require '../lib/bootstrap.php';
page_open(["sess" => "Seminar_Session", "auth" => "Seminar_Default_Auth", "perm" => "Seminar_Perm", "user" => "Seminar_User"]);
$auth->login_if(Request::get('again') && ($auth->auth["uid"] == "nobody"));
include ('lib/seminar_open.php'); // initialise Stud.IP-Session
// -- here you have to put initialisations for the current page
require_once 'lib/wiki.inc.php';
$view = Request::get('view');
$keyword = Request::get('keyword');
$version = Request::int('version');
$cmd = Request::option('cmd');
if ($view === 'wikiprint') {
printWikiPage($keyword, $version);
page_close();
die();
} elseif ($view === 'wikiprintall') {
printAllWikiPages(Context::getId(), Context::getHeaderLine());
page_close();
die();
} elseif ($view === 'export_pdf') {
exportWikiPagePDF($keyword, $version);
} elseif ($view === 'exportall_pdf') {
exportAllWikiPagesPDF('all', Request::option('sortby'));
}
checkObject(); // do we have an open object?
checkObjectModule("wiki"); //are we allowed to use this module here?
object_set_visit_module("wiki");
PageLayout::setHelpKeyword("Basis.Wiki"); // Hilfeseite im Hilfewiki
PageLayout::setTitle(Context::getHeaderLine() . " - " . _("Wiki"));
if (in_array(Request::get('view'), words('listnew listall export'))) {
Navigation::activateItem('/course/wiki/'.$view);
} else if ($keyword) {
Navigation::activateItem('/course/wiki/show');
} else {
Navigation::activateItem('/course/wiki/start');
}
if (Request::option('wiki_comments') === 'none') { // don't show comments
$show_wiki_comments = 'none';
} else if ($user->cfg->WIKI_COMMENTS_ENABLE) { // show all comments
$show_wiki_comments = 'all';
} else { // show comments as icons
$show_wiki_comments = 'icon';
}
URLHelper::addLinkParam('wiki_comments', $show_wiki_comments);
ob_start();
// ---------- Start of main WikiLogic
if ($view === 'listall') {
//
// list all pages, default sorting = alphabetically
//
listPages('all', Request::option('sortby'));
} else if ($view === 'listnew') {
//
// list new pages, default sorting = newest first
//
listPages('new', Request::option('sortby'));
} else if ($view === 'diff') {
//
// show one large diff-file containing all changes
//
showDiffs($keyword, Request::option('versionssince'));
} else if ($view === 'combodiff') {
//
// show one large diff-file containing all changes
//
showComboDiff($keyword);
} else if ($view === 'pageversions') {
//
// show versions of a wiki page
//
listPageVersions($keyword, Request::option('sortby'));
} else if ($view === 'export') {
//
// show export dialog
//
exportWiki();
} else if ($view === 'search') {
searchWiki(Request::get('searchfor'), Request::get('searchcurrentversions'), Request::get('keyword'), Request::get('localsearch'));
} else if ($view === 'edit') {
//
// show page for editing
//
// prevent malformed urls: keyword must be set
if (!$keyword) {
throw new InvalidArgumentException(_('Es wurde keine zu editierende Seite übergeben!'));
}
$wikiData = getWikiPage($keyword, 0); // always get newest page
if ($wikiData && !$wikiData->isEditableBy($GLOBALS['user'])) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Seiten zu editieren!'));
}
// set lock
setWikiLock(null, $user->id, Context::getId(), $keyword);
// show form
wikiEdit($keyword, $wikiData, $user->id);
} else if ($view === 'editnew') {
//
// edit a new page
//
$range_id = Context::getId();
$ancestor = Request::get('origin') ? : Request::get('ancestor_select');
if (!$ancestor) {
$ancestor = null;
}
$edit_perms = CourseConfig::get($range_id)->WIKI_COURSE_EDIT_RESTRICTED ? 'tutor' : 'autor';
if (!$perm->have_studip_perm($edit_perms, $range_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, in dieser Veranstaltung Seiten zu editieren!'));
}
// prevent malformed urls: keyword must be set
if (!$keyword) {
throw new InvalidArgumentException(_('Es wurde keine zu editierende Seite übergeben!'));
}
$wikiData = getWikiPage($keyword, 0); // always get newest page
// warning in the case of an existing wiki page
if ($wikiData && !$wikiData->isNew()) {
PageLayout::postInfo(sprintf(
_('Die Wiki-Seite "%s" existiert bereits. Änderungen hier überschreiben diese Seite!'),
htmlReady($keyword)
));
}
// set lock
setWikiLock(null, $user->id, Context::getId(), $keyword);
//show form
wikiEdit($keyword, $wikiData, $user->id, Request::get('lastpage'), $ancestor);
} else {
// Default action: Display WikiPage (+ logic for submission)
//
if (empty($keyword)) {
$keyword = 'WikiWikiWeb'; // display Start page as default
}
releaseLocks($keyword); // kill old locks
$special = '';
if (Request::submitted('submit')) {
//
// Page was edited and submitted
//
if (Request::get('ancestor')) {
$ancestor = Request::get('ancestor');
} else {
$ancestor = WikiPage::findLatestPage(Context::getId(), $keyword)->ancestor ?: null;
}
submitWikiPage($keyword, $version, Studip\Markup::purifyHtml(Request::get('body')), $user->id, Context::getId(), $ancestor);
$version = ''; // $version="" means: get latest
} else if ($cmd === 'abortedit') { // Editieren abgebrochen
//
// Editing page was aborted
//
// kill lock (set when starting to edit)
releasePageLocks($keyword, $user->id);
// if editing new page was aborted, display last page again
$keyword = Request::get('lastpage', $keyword);
} else if ($cmd === 'really_delete') {
//
// Delete was confirmed -> really delete
//
$keyword = deleteWikiPage($keyword, $version, Context::getId());
$version = ''; // show latest version
} else if ($cmd === 'really_delete_all') {
//
// Delete all was confirmed -> delete entire page
//
$keyword = deleteAllWikiPage($keyword, Context::getId());
$version = ''; // show latest version
}
//
// Show Page
//
$page = WikiPage::findLatestPage(Context::getId(), $keyword);
if (!$page || $page->isVisibleTo($GLOBALS['user']->id)) {
showWikiPage($keyword, $version, $special, $show_wiki_comments, Request::get('hilight'));
} else {
throw new AccessDeniedException(sprintf(
_('Sie haben keine Berechtigung, die Seite %s zu lesen!'),
$keyword
));
}
} // end default action
$layout = $GLOBALS['template_factory']->open('layouts/base');
$layout->content_for_layout = ob_get_clean();
if (in_array($cmd, words('show abortedit really_delete really_delete_all'))) {
// redirect to normal view to avoid duplicate edits on reload or back/forward
header('Location: ' . URLHelper::getURL('', compact('keyword')));
} else {
echo $layout->render();
}
// Save data back to database.
page_close();
|