forked from moodleou/moodle-mod_ouwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed-wikihistory.php
148 lines (131 loc) · 5.38 KB
/
feed-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
<?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
*/
global $ouwiki_nologin;
$ouwiki_nologin = true;
require_once(dirname(__FILE__) . '/../../config.php');
require($CFG->dirroot.'/mod/ouwiki/basicpage.php');
$magic = required_param('magic', PARAM_RAW);
if ($magic != $subwiki->magic) {
header('HTTP/1.0 404 not found');
die('Incorrect magic number');
}
$newpages = optional_param('type', '', PARAM_ALPHA) == 'pages';
$rss = optional_param('format', '', PARAM_RAW) === 'rss';
// Get basic wiki parameters
$wikiparams = ouwiki_display_wiki_parameters('', $subwiki, $cm);
// Get changes
if ($newpages) {
$changes = ouwiki_get_subwiki_recentpages($subwiki->id, 0, OUWIKI_FEEDSIZE);
$wikiparams = $wikiparams . '&type=pages';
} else {
$changes = ouwiki_get_subwiki_recentchanges($subwiki->id, 0, OUWIKI_FEEDSIZE);
}
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$oldbrowser =
(!preg_match('/Opera/', $useragent) && preg_match('/MSIE [456]/', $useragent)) ||
preg_match('/Firefox\/1\./', $useragent);
if ($oldbrowser) {
header('Content-Type: text/xml; charset=UTF-8');
} else if ($rss) {
header('Content-Type: application/rss+xml; charset=UTF-8');
} else {
header('Content-Type: application/atom+xml; charset=UTF-8');
}
$a = new StdClass;
$a->course = htmlspecialchars($course->shortname);
$a->name = htmlspecialchars($ouwiki->name);
$a->subtitle = get_string($newpages ? 'tab_index_pages' : 'tab_index_changes', 'ouwiki');
$feedtitle = get_string('feedtitle', 'ouwiki', $a);
$feedlink = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$feeddescription=get_string('feeddescription'. ($newpages ? 'pages' : 'changes'), 'ouwiki');
// Domain name, used for IDs (we assume this is owned by site operator in 2007)
$domainname = preg_replace('/^.*\/\/(www\.)?(.*?)\/.*$/', '$2', $CFG->wwwroot);
$id = 'tag:'.$domainname.',2007:ouwiki/'.$ouwiki->id.'/wikihistory/'.($newpages ? 'pages' : 'changes');
$pagelink = $CFG->wwwroot . '/mod/ouwiki/wikihistory.php?' . $wikiparams;
print '<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="'.$CFG->wwwroot.'/mod/ouwiki/feed.xsl"?>';
if ($rss) {
print '
<rss version="2.0">
<channel>
<title>'.$feedtitle.'</title>
<description>'.$feeddescription.'</description>
<link>' . $pagelink . '</link>
<pubDate>' . date('r', !empty($changes) ? reset($changes)->timecreated : time()). '</pubDate>';
} else {
print '
<feed xmlns="http://www.w3.org/2005/Atom">
<link rel="self" href="'.$feedlink.'"/>
<title>'.$feedtitle.'</title>
<subtitle>'.$feeddescription.'</subtitle>
<link href="' . $pagelink . '"/>
<updated>' . date('c', !empty($changes) ? reset($changes)->timecreated : time()) . '</updated>
<author>
<name>Wiki system</name>
</author>
<id>'.$id.'</id>';
}
foreach ($changes as $change) {
$pageparams = ouwiki_display_wiki_parameters($change->title, $subwiki, $cm);
$a = new StdClass;
$a->name = htmlspecialchars(fullname($change));
$a->date = ouwiki_nice_date($change->timecreated);
$itemtitle = $ouwiki->name . ' - ' . ($change->title === ''
? get_string('startpage', 'ouwiki') : htmlspecialchars($change->title));
$itemlink = $CFG->wwwroot.'/mod/ouwiki/view.php?'.$pageparams;
if (!empty($change->previousversionid)) {
$a->url = $CFG->wwwroot.'/mod/ouwiki/diff.php?'.$pageparams.'&v1='.
$change->previousversionid.'&v2='.$change->versionid;
$a->main = get_string('feedchange', 'ouwiki', $a);
} else {
$a->main = get_string('feednewpage', 'ouwiki', $a);
}
$itemdescription = get_string('feeditemdescriptiondate', 'ouwiki', $a);
if ($rss) {
// The 'permalink' guid just points to the wiki history page but with a unique-ifying versionid on end
print '
<item>
<title>'.$itemtitle.'</title>
<link>'.$itemlink.'</link>
<pubDate>'.date('r', $change->timecreated).'</pubDate>
<description>'.htmlspecialchars($itemdescription).'</description>
<guid>'.$CFG->wwwroot.'/mod/ouwiki/wikihistory.php?'.$wikiparams.'#v'.$change->versionid.'</guid>
</item>';
} else {
print '
<entry>
<title>'.$itemtitle. '</title>
<link href="'.$itemlink.'"/>
<id>'.$id.'/'.$change->versionid.'</id>
<updated>'.date('c', $change->timecreated).'</updated>
<summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">'.$itemdescription.'</div></summary>
</entry>';
}
}
if ($rss) {
print '</channel></rss>';
} else {
print '</feed>';
}