-
Notifications
You must be signed in to change notification settings - Fork 33
/
wikihistory.php
279 lines (242 loc) · 9.43 KB
/
wikihistory.php
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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 'Wiki changes' page. Displays a list of recent changes to the wiki. You
* can choose to view all changes or only new pages.
*
* @copyright © 2007 The Open University
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package ouwiki
*//** */
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/mod/ouwiki/basicpage.php');
require_once($CFG->dirroot.'/mod/ouwiki/locallib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$newpages = optional_param('type', '', PARAM_ALPHA) == 'pages';
$from = optional_param('from', 0, PARAM_INT);
$url = new moodle_url('/mod/ouwiki/wikihistory.php', array('id' => $id));
$PAGE->set_url($url);
if ($id) {
if (!$cm = get_coursemodule_from_id('ouwiki', $id)) {
throw new moodle_exception('invalidcoursemodule');
}
// Checking course instance
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
if (!$ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance))) {
throw new moodle_exception('invalidcoursemodule');
}
$PAGE->set_cm($cm);
}
$context = context_module::instance($cm->id);
$PAGE->set_pagelayout('incourse');
require_course_login($course, true, $cm);
$ouwikioutput = $PAGE->get_renderer('mod_ouwiki');
// Get basic wiki parameters
$wikiparams = ouwiki_display_wiki_parameters('', $subwiki, $cm);
$tabparams = $newpages ? $wikiparams.'&type=pages' : $wikiparams;
// Get changes
if ($newpages) {
$changes = ouwiki_get_subwiki_recentpages($subwiki->id, $from, OUWIKI_PAGESIZE+1);
} else {
$changes = ouwiki_get_subwiki_recentchanges($subwiki->id, $from, OUWIKI_PAGESIZE+1);
}
// Check to see whether any change has been overwritten by being imported.
$overwritten = false;
foreach ($changes as $change) {
if (!empty($change->importversionid)) {
$overwritten = true;
break;
}
}
// Do header
$atomurl = $CFG->wwwroot.'/mod/ouwiki/feed-wikihistory.php?'.$wikiparams.
($newpages?'&type=pages' : '').'&magic='.$subwiki->magic;
$rssurl = $CFG->wwwroot.'/mod/ouwiki/feed-wikihistory.php?'.$wikiparams.
($newpages?'&type=pages' : '').'&magic='.$subwiki->magic.'&format=rss';
$meta = '<link rel="alternate" type="application/atom+xml" title="Atom feed" '.
'href="'.$atomurl.'" />';
// bug #3542
$wikiname = format_string(htmlspecialchars($ouwiki->name));
$title = $wikiname.' - '.get_string('wikirecentchanges', 'ouwiki');
echo $ouwikioutput->ouwiki_print_start($ouwiki, $cm, $course, $subwiki,
$from > 0
? get_string('wikirecentchanges_from', 'ouwiki', (int)($from/OUWIKI_PAGESIZE) + 1)
: get_string('wikirecentchanges', 'ouwiki'),
$context, null, false, false, $meta, $title);
// Print tabs for selecting all changes/new pages
$tabrow = array();
$tabrow[] = new tabobject('changes', 'wikihistory.php?'.$wikiparams,
get_string('tab_index_changes', 'ouwiki'));
$tabrow[] = new tabobject('pages', 'wikihistory.php?'.$wikiparams.'&type=pages',
get_string('tab_index_pages', 'ouwiki'));
$tabs = array();
$tabs[] = $tabrow;
print_tabs($tabs, $newpages ? 'pages' : 'changes');
print '<div id="ouwiki_belowtabs">';
if ($newpages) {
$pagetabname = get_string('tab_index_pages', 'ouwiki');
} else {
$pagetabname = get_string('tab_index_changes', 'ouwiki');
}
print get_accesshide($pagetabname, 'h1');
// On first page, show information
if (!$from) {
print get_string('advice_wikirecentchanges_'
.($newpages ? 'pages' : 'changes'
.(!empty($CFG->ouwikienablecurrentpagehighlight) ? '' : '_nohighlight')), 'ouwiki').'</p>';
}
$strdate = get_string('date');
$strtime = get_string('time');
$strpage = get_string('page', 'ouwiki');
$strperson = get_string('changedby', 'ouwiki');
$strview = get_string('view');
$strimport = '';
if ($overwritten) {
$strimport = get_string('importedfrom', 'ouwiki');
}
print "
<table class='generaltable'>
<thead>
<tr><th scope='col'>$strdate</th><th scope='col'>$strtime</th><th scope='col'>$strpage</th>".
($newpages?'':'<th><span class="accesshide">'.$strview.'</span></th>');
if ($ouwiki->enablewordcount) {
print "<th scope='col'>".get_string('words', 'ouwiki')."</th>";
}
if ($overwritten) {
print '<th scope="col">' . $strimport . '</th>';
}
print "
<th scope='col'>$strperson</th></tr></thead><tbody>
";
$strchanges = get_string('changes', 'ouwiki');
$strview = get_string('view');
$lastdate = '';
$count = 0;
foreach ($changes as $change) {
$count++;
if ($count > OUWIKI_PAGESIZE) {
break;
}
$pageparams = ouwiki_display_wiki_parameters($change->title, $subwiki, $cm);
$date = userdate($change->timecreated, get_string('strftimedate'));
if ($date == $lastdate) {
$date = '';
} else {
$lastdate = $date;
}
$time = ouwiki_recent_span($change->timecreated).userdate($change->timecreated, get_string('strftimetime')).'</span>';
$page = $change->title ? htmlspecialchars($change->title) : get_string('startpage', 'ouwiki');
if (!empty($change->previousversionid)) {
$changelink = " <small>(<a href='diff.php?$pageparams&v2={$change->versionid}&v1={$change->previousversionid}'>$strchanges</a>)</small>";
} else {
$changelink = ' <small>('.get_string('newpage', 'ouwiki').')</small>';
}
$current = '';
if ($change->versionid == $change->currentversionid || $newpages) {
$viewlink = "view.php?$pageparams";
if (!$newpages && !empty($CFG->ouwikienablecurrentpagehighlight)) {
$current =' class="current"';
}
} else {
$viewlink = "viewold.php?$pageparams&version={$change->versionid}";
}
$change->id = $change->userid;
if ($change->id) {
$userlink = ouwiki_display_user($change, $course->id);
} else {
$userlink = '';
}
if ($newpages) {
$actions = '';
$page = "<a href='$viewlink'>$page</a>";
} else {
$actions = "<td class='actions'><a href='$viewlink'>$strview</a>$changelink</td>";
}
// see bug #3611
if (!empty($current) && !empty($CFG->ouwikienablecurrentpagehighlight)) {
// current page so add accessibility stuff
$accessiblityhide = '<span class="accesshide">'.get_string('currentversionof', 'ouwiki').'</span>';
$dummy = $page;
$page = $accessiblityhide.$dummy;
}
print "
<tr$current>
<td class='ouw_leftcol'>$date</td><td>$time</td><td>$page</td>
$actions";
if ($ouwiki->enablewordcount) {
if (isset($change->previouswordcount)) {
$wordcountchanges = ouwiki_wordcount_difference($change->wordcount,
$change->previouswordcount, true);
} else {
// first page
$wordcountchanges = ouwiki_wordcount_difference($change->wordcount, 0, false);
}
print "<td>$wordcountchanges</td>";
}
if ($overwritten) {
if (!empty($change->importversionid)) {
$selectedouwiki = ouwiki_get_wiki_details($change->importversionid);
print '<td>';
if ($selectedouwiki->courseshortname) {
print $selectedouwiki->courseshortname. '<br/>';
}
print $selectedouwiki->name;
if ($selectedouwiki->group) {
print '<br/>';
print '[[' .$selectedouwiki->group. ']]';
} else if ($selectedouwiki->user) {
print '<br/>';
print '[[' .$selectedouwiki->user. ']]';
}
print '</td>';
} else {
print '<td></td>';
}
}
print "
<td class='ouw_rightcol'>$userlink</td>
</tr>";
}
print '</tbody></table>';
if (empty($changes)) {
echo get_string('nowikipages', 'ouwiki');
}
if ($count > OUWIKI_PAGESIZE || $from > 0) {
// Fix double htmlspecialchars for ampersand in "Older changes" and "Newer changes" links.
$tabparams = str_replace('&', '&', $tabparams);
print '<div class="ouw_paging"><div class="ouw_paging_prev"> ';
if ($from > 0) {
$jump = $from - OUWIKI_PAGESIZE;
if ($jump < 0) {
$jump = 0;
}
print link_arrow_left(get_string('previous', 'ouwiki'),
'wikihistory.php?'.$tabparams. ($jump > 0 ? '&from='.$jump : ''));
}
print '</div><div class="ouw_paging_next">';
if ($count > OUWIKI_PAGESIZE) {
$jump = $from + OUWIKI_PAGESIZE;
print link_arrow_right(get_string('next', 'ouwiki'),
'wikihistory.php?'.$tabparams. ($jump > 0 ? '&from='.$jump : ''));
}
print '</div></div>';
}
$pageversion = ouwiki_get_current_page($subwiki, $pagename);
echo $ouwikioutput->get_link_back_to_wiki($cm);
echo $ouwikioutput->get_bottom_buttons($subwiki, $cm, $context, $pageversion, false);
// Footer
ouwiki_print_footer($course, $cm, $subwiki);