Implement watchlist emailing, but it's not tested yet.

We're getting there, hooray! :D
This commit is contained in:
Starbeamrainbowlabs 2019-12-23 18:57:52 +00:00
parent 86a9828565
commit 9cb4ecae1b
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 47 additions and 0 deletions

View File

@ -18,6 +18,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Optimisation: Don't load the statistics index if it's not needed (also esp. noticeable on wikis with lots of pages)
- Optimisation: Refactor `stas_split()` to be faster (informal testing shows ~18% → 4% total time)
- [Module Api] Optimisation: Remove `search::transliterate` because it has a huge overhead. Use `search::$literator->transliterate()` instead.
- [Module Api] Add new `absolute` and `html` optional boolean arguments to `render_timestamp()`
## v0.20
_Just 1 change since the previous beta release._

View File

@ -214,6 +214,52 @@ register_module([
$message .= " <a href='javascript:history.back();'>Go back</a> to your previous page, or <a href='?action=watchlist'>review your watchlist</a>.</a>";
exit(page_renderer::render_main("Watchlist update successful", "<p>$message</p>"));
});
if(!module_exists("edit")) {
error_log("[module/feature-watchlist] Note: Without the page-edit module, the feature-watchlist module doesn't make much sense. If you don't want anonymous people to edit your wiki, try the 'anonedits' setting.");
return false;
}
register_save_preprocessor(function($indexentry, $new_data, $old_data) {
global $version, $commit, $env, $settings;
$usernames = [];
foreach($settings->users as $username => $user_data) {
if(empty($user_data->watchlist))
continue;
if(!in_array($env->page, $user_data->watchlist))
continue;
$usernames[] = $username;
}
$chars_changed = strlen($new_data) - strlen($old_data);
$chars_changed_text = ($chars_changed < 0 ? "removes " : "adds ") . "$chars_changed characters";
// Calculate the stem from the current full URL by stripping everything after the question mark ('?')
$url_stem = full_url();
if(mb_strrpos($url_stem, "?") !== false) $url_steam = mb_substr($url_stem, mb_strrpos($url_stem, "?"));
email_users(
$usernames,
"{$env->page} was updated by {$env->user} - $settings->sitename",
"Hey there!
{$env->page} was updated by {$env->user} at ".render_timestamp(time(), true, false).", which $chars_changed_text.
View the latest revision here: {$url_stem}?page=".rawurlencode($env->page)."
---------- New page text ----------
$new_data
-----------------------------------
--$settings->sitename, powered by Pepperminty Wiki $version-".substr($commit, 0, 7)."
(P.S. Don't reply to this email, because it may not recieve a reply. Instead try contacting $settings->admindetails_name at $settings->admindetails_email, who is $settings->sitename's administrator if you have any issues.)
"
);
});
}
]);