-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-wiki-summary.php
196 lines (166 loc) · 6.23 KB
/
generate-wiki-summary.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
<?php
$opts = array(
'list' => 'recentchanges',
'rclimit' => 500,
'rcend' => date('YmdHis', $startDate),
'rcprop' => 'user|comment|title|sizes|timestamp|ids',
'rcshow' => '!redirect'
);
$changedPages = array();
$changes = mw_request('query', $opts);
if($changes && property_exists($changes, 'query') && property_exists($changes->query, 'recentchanges')) {
foreach($changes->query->recentchanges as $change) {
if(!array_key_exists($change->title, $changedPages)) {
$changedPages[$change->title] = array(
'changes' => array(array(
'user' => $change->user,
'timestamp' => $change->timestamp,
'comment' => $change->comment,
'oldid' => $change->old_revid,
'curid' => $change->revid
)),
'latestid' => $change->revid,
'oldestid' => $change->old_revid,
'type' => $change->type
);
} else {
$changedPages[$change->title]['changes'][] = array(
'user' => $change->user,
'timestamp' => $change->timestamp,
'comment' => $change->comment,
'oldid' => $change->old_revid,
'curid' => $change->revid
);
if($change->old_revid < $changedPages[$change->title]['oldestid'])
$changedPages[$change->title]['oldestid'] = $change->old_revid;
if($change->type == 'new')
$changedPages[$change->title]['type'] = 'new';
}
}
}
uasort($changedPages, function($a, $b) {
if (count($a['changes']) == count($b['changes'])) {
return 0;
}
return (count($a['changes']) > count($b['changes'])) ? -1 : 1;
});
$new = array();
$changed = array();
$newpeople = array();
$eventnotes = array();
$toc = array(
'new' => array(),
'edit' => array()
);
foreach($changedPages as $title=>$page) {
if(!in_array($page['type'], array('new','edit')))
continue;
ob_start();
$chp = preg_replace('/[^a-zA-Z0-9-]/', '-', $title);
$authors = [];
foreach(array_reverse($page['changes']) as $change) {
if(preg_match('/(prompted by .+) (https:\/\/indieweb(?:camp.com|.org)[^ ]+)? ?and dfn added by (.+)/', $change['comment'], $match)) {
$user = $match[3];
} else {
$user = $change['user'];
}
if(!in_array(strtolower($user), $authors)) {
$authors[] = strtolower($user);
}
}
// Summary
if($page['type'] == 'new') {
// Subpages of user-pages are excluded (e.g. custom CSS or personal test pages)
if(preg_match('/^user:/i', $title) && strpos($title, '/') === false)
$page['isuser'] = true;
else
$page['isuser'] = false;
$page['is_event_notes'] = false;
if (strpos($title, 'events/') === 0) {
// Pages starting with `events/` go in a separate section
// events/2022-10-26-hwc-pacific
$page['is_event_notes'] = true;
$item = mw_entry($title);
$summary = '';
if ($item && array_key_exists('summary', $item['properties'])) {
$summary = $item['properties']['summary'][0];
}
addEventToList($eventnotes, $title, $summary);
} else
// Hide user: and template: pages (only include user pages and other pages that don't begin with user: or template:)
if($page['isuser']
|| (!$page['isuser'] && !preg_match('/^(user|template|category):/i', $title))) {
echo '<h3><a href="' . Config::$wikiBaseURL . pageTitleToURL($title) . '">' . $title . '</a></h3>';
$item = mw_entry($title);
if($item && array_key_exists('summary', $item['properties'])) {
echo '<p>' . $item['properties']['summary'][0] . '</p>';
}
$first_edit = $page['changes'][count($page['changes'])-1];
if(preg_match('/(prompted by .+) (https:\/\/indieweb(?:camp.com|.org)[^ ]+)? ?and dfn added by (.+)/', $first_edit['comment'], $match)) {
$by = $match[3];
} else {
$by = $first_edit['user'];
}
$authors = array_diff($authors, [strtolower($by)]);
$authors_str = strtolower(join_with_and($authors));
echo '<p style="font-size:0.8em;">';
echo 'Created by ' . $by . ' on ' . date('l', strtotime($first_edit['timestamp']));
$num_changes = count($page['changes'])-1;
if(count($authors) > 1) {
echo ' with ' . $num_changes . ' more edit'.($num_changes == 1 ? '' : 's').' by ' . $authors_str;
} else {
if(count($page['changes']) > 1) {
echo ' and edited ' . $num_changes . ' more time'.($num_changes == 1 ? '' : 's');
}
}
echo '</p>';
}
} else {
if(count($changed) < 10) {
if(!preg_match('/^(user|template|mediawiki|category):/i', $title) && count($page['changes']) > 1) {
$authors_str = strtolower(join_with_and($authors));
$query = str_replace('&','&',http_build_query(array(
'title' => $title,
'action' => 'historysubmit',
'diff' => $page['latestid'],
'oldid' => $page['oldestid']
)));
echo '<li><b><a href="' . Config::$wikiBaseURL . pageTitleToURL($title) . '">' . $title . '</a></b> <a href="' . Config::$wikiURL . '?' . $query . '">' . count($page['changes']) . ' edit'.(count($page['changes']) == 1 ? '' : 's').'</a> by ' . $authors_str . '</li>';
}
}
}
$content = ob_get_clean();
if(trim($content)) {
if($page['type'] == 'new') {
if($page['isuser'])
$newpeople[] = $content;
else
$new[] = $content;
} else {
$changed[] = $content;
}
}
}
?>
<?php if(count($newpeople)): ?>
<h2 id="new-community-members">New Community Members</h2>
<p>From <a href="https://indieweb.org/wiki/index.php?title=Special%3ANewPages&namespace=2">IndieWeb Wiki: New User Pages</a>:</p>
<?= implode("\n", $newpeople) ?>
<?php endif; ?>
<?php if(count($new)): ?>
<h2 id="new-wiki-pages">Top New Wiki Pages</h2>
<p>From <a href="https://indieweb.org/wiki/index.php?title=Special%3ANewPages&namespace=0">IndieWeb Wiki: New Pages</a>:</p>
<?= implode("\n", $new) ?>
<?php endif; ?>
<?php if(count($eventnotes)): ?>
<h2 id="new-event-notes">New Event Notes</h2>
<p>From <a href="https://indieweb.org/wiki/index.php?title=Special%3ANewPages&namespace=0">IndieWeb Wiki: New Pages</a>:</p>
<?= buildEventNotes($eventnotes) ?>
<?php endif; ?>
<?php if(count($changed)): ?>
<h2 id="changed-wiki-pages">Top Edited Wiki Pages</h2>
<p>From <a href="https://indieweb.org/wiki/index.php?namespace=0&title=Special%3ARecentChanges">IndieWeb Wiki: Recent Changes</a>:</p>
<ul>
<?= implode("\n", $changed) ?>
</ul>
<?php endif; ?>