* @api {get} ?action=edit&page={pageName}[&newpage=yes] Get an editing page
* @apiDescription Gets an editing page for a given page. If you don't have permission to edit the page in question, a view source pagee is returned instead.
* @apiParam {string} newpage Set to 'yes' if a new page is being created. Only affects a few bits of text here and there, and the HTTP response code recieved on success from the `save` action.
$isOtherUsersPage // this page actually belongs to another user
)
{
if(!$creatingpage)
{
// The page already exists - let the user view the page source
$sourceViewContent = "<p>$settings->sitename does not allow anonymous users to make edits. You can view the source of $env->page below, but you can't edit it. You could, however, try <a href='index.php?action=login&returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "'>logging in</a>.</p>\n";
if($env->is_logged_in)
$sourceViewContent = "<p>$env->page is protected, and you aren't an administrator or moderator. You can view the source of $env->page below, but you can't edit it.</p>\n";
$sourceViewContent = "<p>$settings->sitename currently has editing disabled, so you can't make changes to this page at this time. Please contact $settings->admindetails_name, $settings->sitename's administrator for more information - their contact details can be found at the bottom of this page. Even so, you can still view the source of this page. It's disabled below:</p>";
$sourceViewContent = "<p>$env->page is a special user page which acutally belongs to " . extract_user_from_userpage($env->page) . ", another user on $settings->sitename. Because of this, you are not allowed to edit it (though you can always edit your own page and any pages under it if you're logged in). You can, however, vieww it's source below.</p>";
exit(page_renderer::render_main("Viewing source for $env->page", $sourceViewContent));
}
else
{
$errorMessage = "<p>The page <code>$env->page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login&returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "'>logging in</a>.</p>\n";
if($isOtherUsersPage) {
$errorMessage = "<p>The page <code>" . htmlentities($env->page) . "</code> doesn't exist, but you can't create it because it's a page belonging to another user.</p>\n";
// Need this for the prev-content-hash to prevent the conflict page from appearing
$old_pagetext = $pagetext;
// set the page content to the newly edited content
$pagetext = $_POST['content'];
// Set the tags to the new tags, if needed
if(isset($_POST['tags']))
$page_tags = $_POST['tags'];
// Insert the "view" part of the page we're editing
$content .= "<p class='preview-message'><strong>This is only a preview, so your edits haven't been saved! Scroll down to continue editing.</strong></p>" . parse_page_source($pagetext);
$content .= "<button class='smartsave-restore' title=\"Only works if you haven't changed the editor's content already!\">Restore Locally Saved Content</button>
<input type='text' name='tags' value='" . htmlentities($page_tags, ENT_HTML5 | ENT_QUOTES) . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
* @api {post} ?action=acquire-edit-key&page={pageName} Acquire an edit key for a page
* @apiDescription Returns an edit key that can be used to programmatically save an edit to a page. It does _not_ necessarily mean that such an edit will be saved. For example, editing might be disabled, or you might not have permission to save an edit on a particular page.
* @apiName AcquireEditKey
* @apiGroup Editing
* @apiPermission Anonymous
*
* @apiUse PageParameter
* @apiPara {string} format The format ot return the edit key in. Possible values: text, json. Default: text.
*/
/*
* █████ ██████ ██████ ██ ██ ██ ██████ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███████ ██ ██ ██ ██ ██ ██ ██████ █████ █████
* ██ ██ ██ ██ ▄▄ ██ ██ ██ ██ ██ ██ ██
* ██ ██ ██████ ██████ ██████ ██ ██ ██ ███████
* ▀▀
*
* ███████ ██████ ██ ████████
* ██ ██ ██ ██ ██
* █████ ██ ██ ██ ██ █████
* ██ ██ ██ ██ ██
* ███████ ██████ ██ ██
*
* ██ ██ ███████ ██ ██
* ██ ██ ██ ██ ██
* █████ █████ ████
* ██ ██ ██ ██
* ██ ██ ███████ ██
*/
add_action("acquire-edit-key", function() {
global $env;
if(!file_exists($env->page_filename)) {
http_response_code(404);
header("content-type: text/plain");
exit("Error: The page '$env->page' couldn't be found.");
exit("Error: The format $format is not currently known. Supported formats: text, json. Default: text.\nThink this is a bug? Open an issue at https://github.com/sbrl/Pepperminty-Wiki/issues/new");
* @apiParam {string} newpage GET only. Set to 'yes' to indicate that this is a new page that is being saved. Only affects the HTTP response code you recieve upon success.
* @apiParam {string} content POST only. The new content to save to the given filename.
* @apiParam {string} tags POST only. A comma-separated list of tags to assign to the current page. Will replace the existing list of tags, if any are present.
* @apiParam {string} prev-content-hash POST only. The hash of the original content before editing. If this hash is found to be different to a hash computed of the currentl saved content, a conflict resolution page will be returned instead of saving the provided content.
*
* @apiError UnsufficientPermissionError You don't currently have sufficient permissions to save an edit.
*/
/*
*
* ___ __ ___ _____
* / __|/ _` \ \ / / _ \
* \__ \ (_| |\ V / __/
* |___/\__,_| \_/ \___|
* %save%
*/
add_action("save", function() {
global $pageindex, $settings, $env, $save_preprocessors, $paths;
exit(htmlentities($env->page) . " is protected, and you aren't logged in as an administrator or moderator. Your edit was not saved. Redirecting in 5 seconds...");
$content .= "<p>An edit conflict has arisen because someone else has saved an edit to " . htmlentities($env->page) . " since you started editing it. Both texts are shown below, along the differences between the 2 conflicting revisions. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be kept when you press the \"Resolve Conflict\" button at the bottom of the page.</p>
<input type='text' name='tags' value='" . htmlentities($_POST["tags"]) . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
exit(page_renderer::render_main("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the server's disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
<p>Please tell the administrator of this wiki (" . $settings->admindetails_name . ") about this problem.</p>"));
}
});
add_help_section("15-editing", "Editing", "<p>To edit a page on $settings->sitename, click the edit button on the top bar. Note that you will probably need to be logged in. If you do not already have an account you will need to ask $settings->sitename's administrator for an account since there is no registration form. Note that the $settings->sitename's administrator may have changed these settings to allow anonymous edits.</p>
<p>Editing is simple. The edit page has a sizeable box that contains a page's current contents. Once you are done altering it, add or change the comma separated list of tags in the field below the editor and then click save page.</p>
<p>A reference to the syntax that $settings->sitename supports can be found below.</p>");
add_help_section("17-user-pages", "User Pages", "<p>If you are logged in, $settings->sitename allocates you your own user page that only you can edit. On $settings->sitename, user pages are sub-pages of the <a href='?page=" . rawurlencode($settings->user_page_prefix) . "'>" . htmlentities($settings->user_page_prefix) . "</a> page, and each user page can have a nested structure of pages underneath it, just like a normal page. Your user page is located at <a href='?page=" . rawurlencode(get_user_pagename($env->user)) . "'>" . htmlentities(get_user_pagename($env->user)) . "</a>. " .
(module_exists("page-user-list") ? "You can see a list of all the users on $settings->sitename and visit their user pages on the <a href='?action=user-list'>user list</a>." : "")