Start implementing watchlists :D

TODO: update the changelog
This commit is contained in:
Starbeamrainbowlabs 2019-12-22 14:37:20 +00:00
parent f02e486580
commit 167259623d
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 133 additions and 1 deletions

View File

@ -135,7 +135,7 @@
"version": "0.11",
"author": "Starbeamrainbowlabs",
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"lastupdate": 1576440066,
"lastupdate": 1576615079,
"optional": false,
"extra_data": []
},
@ -189,6 +189,16 @@
"optional": false,
"extra_data": []
},
{
"id": "feature-watchlist",
"name": "User watchlists",
"version": "0.1",
"author": "Starbeamrainbowlabs",
"description": "Adds per-user watchlists. When a page on a user's watchlist is edited, a notification email is sent.",
"lastupdate": 1577024516,
"optional": false,
"extra_data": []
},
{
"id": "page-credits",
"name": "Credits",

View File

@ -0,0 +1,121 @@
<?php
register_module([
"name" => "User watchlists",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds per-user watchlists. When a page on a user's watchlist is edited, a notification email is sent.",
"id" => "feature-watchlist",
"code" => function() {
/**
* @api {get} ?action=watchlist&foormat=format Get your watchlist
* @apiName Watchlist
* @apiGroup Settings
* @apiPermission User
*
* @apiParam {string} format The format to return the watchlist in.
*
* @apiError WatchlistsDisabled Watchlists are disabled because the watchlists_enable setting is set to false.
* @apiError NoEmailAddress The currently logged in user doesn't have an email address specified in their account.
*/
/*
* ██ ██ █████ ████████ ██████ ██ ██ ██ ██ ███████ ████████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██ ███████ ██ ██ ███████ ██ ██ ███████ ██
* ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███ ███ ██ ██ ██ ██████ ██ ██ ███████ ██ ███████ ██
*/
add_action("watchlist", function() {
global $settings, $env;
if(!$settings->watchlists_enable) {
http_response_code(403);
exit(page_renderer::render_main("Watchlists disabled - $settings->sitename", "<p>Sorry, but watchlists are currently disabled on $settings->sitename. Contact your moderators to learn - their details are at the bottom of every page.</p>"));
}
if(!$env->is_logged_in) {
http_response_code(401);
exit(page_renderer::render_main("Not logged in - $settings->sitename", "<p>Only logged in users can have watchlists. Try <a href='?action=login&amp;returnto=".rawurlencode("?action=watchlist")."'>logging in</a>."));
}
if(empty($env->user_data->emailAddress)) {
http_response_code(422);
exit(page_renderer::render_main("No email address specified -$settings->sitename", "<p>You are logged in, but have not specified an email address to send notifications to. Try specifying one in your <a href='?action=user-preferences'>user preferences</a> and then coming back here.</p>"));
}
$format = $_GET["format"] ?? "html";
$watchlist = [];
if(!empty($env->user_data->watchlist))
$watchlist = $env->user_data->watchlist;
$mime_type = "text/html";
$content = "";
switch ($format) {
case "html":
$content .= "<h1>Watchlist</h1>";
if(!empty($watchlist)) {
$content .= "<ul class='page-list watchlist'>\n";
foreach($watchlist as $pagename) {
$content .= "<li><a href='?action=watchlist-edit&page=".rawurlencode($pagename)."&do=remove'>&#x274c;</a> <a href='?page=".rawurlencode($pagename)."'>".htmlentities($pagename)."</a></li>";
}
$content .= "</ul>";
$content .= "<p>You can also <a href='?action=watchlist&do=clear'>clear your entire list</a> and start again.</p>";
}
else {
$content .= "<p><em>You don't have any pages on your watchlist. Try visiting some pages and adding them to your watchlist and then coming back here.</em></p>";
}
$content = page_renderer::render_main("Watchlist - $settings->sitename", $content);
break;
case "text":
$mime_type = "text/plain";
foreach($watchlist as $pagename)
$content .= "$pagename\n";
break;
case "json":
$mime_type = "application/json";
$content = json_encode($watchlist);
break;
default:
http_response_code(400);
header("content-type: text/plain");
exit("Sorry, the format '$format' wasn't recognised. This action currently supports these formats: html, json, text");
break;
}
header("content-type: $mime_type");
header("content-length: " . strlen($content));
exit($content);
});
/**
* @api {get} ?action=watchlist-edit&do={do_verb} Edit your watchlist
* @apiName WatchlistEdit
* @apiGroup Settings
* @apiPermission User
*
* TODO: Finish filling this out
* @apiParam {string} string The string to hash.
* @apiParam {boolean} raw Whether to return the hashed password as a raw string instead of as part of an HTML page.
*
* @apiError ParamNotFound The string parameter was not specified.
*/
/*
* ███████ ██████ ██ ████████
* ██ ██ ██ ██ ██
* █████ ██ ██ ██ ██
* ██ ██ ██ ██ ██
* ███████ ██████ ██ ██
*/
add_action("watchlist-edit", function () {
// TODO: Fill this in
});
}
]);
?>

View File

@ -96,6 +96,7 @@
"new_password_length": { "type": "number", "description": "The length of newly-generated passwords. This is currently used in the user table when creating new accounts.", "default": 32},
"require_login_view": { "type": "checkbox", "description": "Whether to require that users login before they do anything else. Best used with the data_storage_dir option.", "default": false},
"data_storage_dir": { "type": "text", "description": "The directory in which to store all files, except the main index.php.", "default": "." },
"watchlists_enable": { "type": "checkbox", "description": "Whether the watchlists feature should be enabled or not.", "default": true },
"delayed_indexing_time": { "type": "number", "description": "The amount of time, in seconds, that pages should be blocked from being indexed by search engines after their last edit. Aka delayed indexing.", "default": 0},
"nav_links": { "type": "nav", "description": "<p>An array of links and display text to display at the top of the site.<br />Format: <code>\"Display Text\": \"Link\"</code></p><p>You can also use strings here and they will be printed as-is, except the following special strings:</p><ul><li><code>user-status</code> - Expands to the user's login information. e.g. \"Logged in as {name}. | Logout\", or e.g. \"Browsing as Anonymous. | Login\".</li><li><code>search</code> - Expands to a search box.</li><li><code>divider</code> - Expands to a divider to separate stuff.</li><li><code>more</code> - Expands to the \"More...\" submenu.</li></ul>", "default": [
"user-status",