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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
<?php
/**
* wiki.php - wiki controller (currently only a helper)
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @since 3.3
*/
require_once 'lib/wiki.inc.php';
class WikiController extends AuthenticatedController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$this->keyword = Request::get('keyword');
$this->range_id = Context::getId();
if (Navigation::hasItem('/course/wiki/show')) {
Navigation::activateItem('/course/wiki/show');
}
}
/**
* Display dialog to create a new wiki page.
*/
public function create_action()
{
$this->wiki_page_names = Array();
$wiki_pages = WikiPage::findLatestPages(Context::getId());
$wiki_pages->filter(function ($wikipage) use (&$wiki_page_names) {
$wikipage->keyword === 'WikiWikiWeb' ?: $this->wiki_page_names[] = $wikipage->keyword;
});
natcasesort($this->wiki_page_names);
$wikistartpage = WikiPage::findLatestPage(Context::getId(), 'WikiWikiWeb');
if ($wikistartpage) {
array_unshift($this->wiki_page_names, 'WikiWikiWeb');
}
getShowPageInfobox($this->keyword, true);
}
/**
* change course permissions of wiki pages
*/
public function change_courseperms_action()
{
if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Berechtigungen Wiki-Seiten zu ändern!'));
}
// prevent malformed urls: keyword must be set
if (!$this->keyword) {
throw new InvalidArgumentException(_('Es wurde keine Seite übergeben!'));
}
PageLayout::setTitle(_('Wiki-Einstellungen ändern'));
$this->restricted = CourseConfig::get($this->range_id)->WIKI_COURSE_EDIT_RESTRICTED;
getShowPageInfobox($this->keyword, true);
}
/**
* store course permissions of wiki pages
*/
public function store_courseperms_action()
{
CSRFProtection::verifyUnsafeRequest();
if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Berechtigungen Wiki-Seiten zu ändern!'));
}
// prevent malformed urls: keyword must be set
if (!$this->keyword) {
throw new InvalidArgumentException(_('Es wurde keine Seite übergeben!'));
}
CourseConfig::get($this->range_id)->store(
'WIKI_COURSE_EDIT_RESTRICTED',
Request::int('courseperms')
);
PageLayout::postSuccess(_('Die veranstaltungsbezogenen Berechtigungen auf die Wiki-Seiten wurden geändert!'));
$this->redirect(URLHelper::getURL('wiki.php', ['keyword' => $this->keyword]));
}
/**
* change page permission of a single wiki page
*/
public function change_page_config_action()
{
if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Berechtigungen Wiki-Seiten zu ändern!'));
}
// prevent malformed urls: keyword must be set
if (!$this->keyword) {
throw new InvalidArgumentException(_('Es wurde keine Seite übergeben!'));
}
$page = WikiPage::findLatestPage($this->range_id, $this->keyword);
$this->page = $page;
$this->validKeywords = array_filter(
WikiPage::findLatestPages($this->range_id)->pluck("keyword"),
function ($keyword) use ($page) {
if ($keyword === 'WikiWikiWeb') {
return false;
} else {
return $page->isValidAncestor($keyword);
}
}
);
natcasesort($this->validKeywords);
$wikistartpage = WikiPage::findLatestPage(Context::getId(), 'WikiWikiWeb');
if ($wikistartpage) {
array_unshift($this->validKeywords, 'WikiWikiWeb');
}
PageLayout::setTitle(_('Seiten-Einstellungen ändern'));
$this->config = $page->config;
getShowPageInfobox($this->keyword, true);
}
/**
* store page config of a wiki page
*/
public function store_page_config_action()
{
CSRFProtection::verifyUnsafeRequest();
if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Berechtigungen von Wiki-Seiten zu ändern!'));
}
// prevent malformed urls: keyword must be set
if (!$this->keyword) {
throw new InvalidArgumentException(_('Es wurde keine Seite übergeben!'));
}
$this->store_pageperms();
$this->store_page_ancestor();
PageLayout::postSuccess(sprintf(
_('Die Einstellungen für Wiki-Seite "%s" wurden geändert!'),
htmlReady($this->keyword)
));
$this->redirect(URLHelper::getURL('wiki.php', ['keyword' => $this->keyword]));
}
/**
* store page permissions of a wiki page
*/
public function store_pageperms()
{
$wiki_page_config = new WikiPageConfig([$this->range_id, $this->keyword]);
$wiki_page_config->read_restricted = Request::int('page_read_perms');
$wiki_page_config->edit_restricted = Request::int('page_edit_perms');
if (Request::int('page_global_perms') || $wiki_page_config->isDefault()) {
WikiPageConfig::deleteBySQL('range_id = ? AND keyword = ?', [$this->range_id, $this->keyword]);
} else {
$wiki_page_config->store();
}
}
/**
* store page ancestor of a wiki page
*/
public function store_page_ancestor()
{
$wikipage = WikiPage::findLatestPage(Context::getId(), $this->keyword);
if ($wikipage) {
if ($wikipage->isEditableBy($GLOBALS['user'])) {
$ancestor = Request::get('ancestor_select') ?: null;
if ($wikipage->isValidAncestor($ancestor)) {
$wikipage->setAncestorForAllVersions($ancestor);
} else {
PageLayout::postInfo(_('Die Vorgängerseite konnte nicht gespeichert werden.'));
}
$wikipage->store();
} else {
PageLayout::postInfo(_('Keine Änderung vorgenommen, da zwischenzeitlich die Editier-Berechtigung entzogen wurde.'));
}
}
}
public function store_action($version)
{
$body = Studip\Markup::purifyHtml(Request::get('body'));
$ancestor = WikiPage::findLatestPage(Context::getId(), $this->keyword)->ancestor;
submitWikiPage($this->keyword, $version, $body, $GLOBALS['user']->id, $this->range_id, $ancestor);
$latest_version = getLatestVersion($this->keyword, $this->range_id);
if (Request::isXhr()) {
$this->render_json([
'version' => $latest_version['version'],
'body' => $latest_version['body'],
'messages' => implode(PageLayout::getMessages()) ?: false,
'zusatz' => getZusatz($latest_version),
]);
} else {
// Yeah, wait for the whole trailification of the wiki...
}
}
public function version_check_action($version)
{
$latest_version = getLatestVersion($this->keyword, $this->range_id);
if (!$latest_version && $version > 1) {
$this->response->add_header('X-Studip-Error', _('Diese Wiki-Seite existiert nicht mehr!'));
$this->render_json(false);
} elseif ($latest_version && $version != $latest_version['version']) {
$error = _('Die von Ihnen bearbeitete Seite ist nicht mehr aktuell.') . ' ';
$error .= _('Falls Sie dennoch speichern, überschreiben Sie die getätigte Änderung und es wird unter Umständen zu Datenverlusten kommen.');
$this->response->add_header('X-Studip-Error', $error);
$this->response->add_header('X-Studip-Confirm', _('Möchten Sie Ihre Version dennoch speichern?'));
$this->render_json(null);
} else {
$this->render_json(true);
}
}
public function info_action()
{
// prevent malformed urls: keyword must be set
if (!$this->keyword) {
throw new InvalidArgumentException(_('Es wurde keine Seite übergeben!'));
}
$this->last_page = WikiPage::findLatestPage($this->range_id, $this->keyword);
$this->last_user = User::find($this->last_page['user_id']);
$this->first_page = getWikiPage($this->keyword, 1);
$this->first_user = User::find($this->first_page['user_id']);
$this->backlinks = getBacklinks($this->keyword);
$page = WikiPage::findLatestPage($this->range_id, $this->keyword);
$this->descendants = $page->children;
PageLayout::setTitle(_('Informationen zur Wikiseite'));
getShowPageInfobox($this->keyword, true);
}
/**
* This action is responsible for importing wiki pages into the wiki
* of a course from another course.
*/
public function import_action($course_id = null)
{
$edit_perms = CourseConfig::get($course_id)->WIKI_COURSE_EDIT_RESTRICTED ? 'tutor' : 'autor';
if (!$GLOBALS['perm']->have_studip_perm($edit_perms, $course_id)) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, Änderungen an Wikiseiten vorzunehmen!'));
}
$this->course = Course::find($course_id);
if (!$this->course) {
PageLayout::postError(
_('Die ausgewählte Veranstaltung wurde nicht gefunden!')
);
}
$all_semesters = Semester::getAll();
$all_semester_ids = [];
foreach ($all_semesters as $semester) {
$all_semester_ids[] = $semester->id;
}
$this->course_search = new QuickSearch(
'selected_course_id',
new MyCoursesSearch(
'Seminar_id',
$GLOBALS['perm']->get_perm(),
[
'userid' => $GLOBALS['user']->id,
'semtypes' => [],
'exclude' => [$course_id],
'semesters' => $all_semester_ids,
],
's.`Seminar_id` IN (
SELECT range_id FROM wiki
WHERE range_id = s.`Seminar_id`
)'
)
);
$this->course_search->fireJSFunctionOnSelect(
"function() {jQuery(this).closest('form').submit();}"
);
//The following steps are identical for the search and the import.
if (Request::submitted('selected_course_id') || Request::submitted('import')) {
CSRFProtection::verifyUnsafeRequest();
//Search for wiki pages in the selected course:
$this->selected_course_id = Request::option('selected_course_id');
$this->selected_course = Course::find($this->selected_course_id);
if (!$this->selected_course) {
$this->bad_course_search = true;
return;
}
$this->wiki_pages = WikiPage::findLatestPages(
$this->selected_course->id
);
$this->show_wiki_page_form = true;
}
//The import required additional functionality:
if (Request::submitted('import')) {
CSRFProtection::verifyUnsafeRequest();
$this->selected_wiki_page_ids = Request::getArray('selected_wiki_page_ids');
if (!$this->selected_wiki_page_ids) {
PageLayout::postInfo(_('Es wurden keine Wikiseiten ausgewählt!'));
return;
}
$selected_wiki_pages = [];
foreach ($this->selected_wiki_page_ids as $id) {
$wiki_page = WikiPage::find(json_decode($id, true));
if ($wiki_page) {
$selected_wiki_pages[] = $wiki_page;
}
}
if (!$selected_wiki_pages) {
PageLayout::postError(_('Es wurden keine Wikiseiten gefunden!'));
return;
}
$errors = [];
foreach ($selected_wiki_pages as $selected_page) {
$latest_version = WikiPage::findLatestPage(
$this->course->id,
$selected_page->keyword
);
$new_page = new WikiPage();
$new_page->range_id = $this->course->id;
$new_page->user_id = $selected_page->user_id;
$new_page->keyword = $selected_page->keyword;
$new_page->body = $selected_page->body;
$new_page->chdate = $selected_page->chdate;
$new_page->version = $latest_version ? $latest_version->version + 1 : 1;
if (!$new_page->store()) {
$errors[] = sprintf(
_('Fehler beim Import der Wikiseite %s!'),
$new_page->keyword
);
}
}
if ($errors) {
PageLayout::postError(
_('Die folgenden Fehler traten beim Import auf:'),
$errors
);
} else {
$this->show_wiki_page_form = false;
$this->success = true;
PageLayout::postSuccess(
ngettext(
'Die Wikiseite wurde importiert! Sie ist unter dem Navigationspunkt "Alle Seiten" erreichbar.',
'Die Wikiseiten wurden importiert! Sie sind unter dem Navigationspunkt "Alle Seiten" erreichbar.',
count($selected_wiki_pages)
)
);
}
}
}
}
|