diff --git a/Changelog.md b/Changelog.md old mode 100755 new mode 100644 diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/build/index.php b/build/index.php index 932581d..319d31b 100644 --- a/build/index.php +++ b/build/index.php @@ -288,6 +288,8 @@ textarea { min-height: 10em; line-height: 1.3em; font-size: 1.25rem; } textarea, textarea[name=content] + pre, textarea ~ input[type=submit], #search-box { width: calc(100% - 0.3rem); box-sizing: border-box; } textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight: bolder; } .editform input[type=text] { width: calc(100% - 0.3rem); box-sizing: border-box; } +input.edit-page-button[type='submit'] { width: 49.5%; box-sizing: border-box; } +.preview-message { text-align: center; } .jump-to-comments { position: relative; top: -2.5em; display: block; text-align: right; pointer-events: none; } .jump-to-comments > a { pointer-events: all; } @@ -5112,6 +5114,47 @@ register_module([ "code" => function() { global $settings, $env; + /** + * @api {post} ?action=preview-edit&page={pageName}[&newpage=yes] Get a preview of the page + * @apiDescription Gets a preview of the current edit state of a given page + * @apiName PreviewPage + * @apiPermission Anonymous + * + * @apiUse PageParameter + * @apiParam {string} newpage Set to 'yes' if a new page is being created. + * @apiParam {string} preview-edit Set to a value to preview an edit of a page. + */ + + /* + * + * ██████ ██████ ███████ ██ ██ ██ ███████ ██ ██ + * ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + * ██████ ██████ █████ ██ ██ ██ █████ ██ █ ██ + * ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ + * ██ ██ ██ ███████ ████ ██ ███████ ███ ███ + * + * ███████ ██████ ██ ████████ + * ██ ██ ██ ██ ██ + * █████ ██ ██ ██ ██ + * ██ ██ ██ ██ ██ + * ███████ ██████ ██ ██ + * + */ + add_action("preview-edit", function() { + global $pageindex, $settings, $env, $actions; + + if(isset($_POST['preview-edit']) && isset($_POST['content'])) { + // preview changes + get_object_vars($actions)['edit'](); + } + else { + // save page + get_object_vars($actions)['save'](); + } + + + }); + /** * @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. @@ -5141,6 +5184,10 @@ register_module([ { $title = "Creating $env->page"; } + else if(isset($_POST['preview-edit']) && isset($_POST['content'])) + { + $title = "Preview Edits for $env->page"; + } else { $title = "Editing $env->page"; @@ -5191,7 +5238,7 @@ register_module([ exit(page_renderer::render_main("Viewing source for $env->page", $sourceViewContent)); } else - { + { $errorMessage = "
The page $env->page
does not exist, but you do not have permission to create it.
If you haven't already, perhaps you should try logging in.
\n"; if($isOtherUsersPage) { @@ -5211,14 +5258,33 @@ register_module([ { $content .= "Warning: You are not logged in! Your IP address may be recorded.
"; } - $content .= ""; + + // Include preview, if set + if(isset($_POST['preview-edit']) && isset($_POST['content'])) { + // 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 .= " " . parse_page_source($pagetext); + + } + + $content .= ""; // Allow tab characters in the page editor page_renderer::AddJSSnippet("window.addEventListener('load', function(event) { // Adapted from https://jsfiddle.net/2wAzx/13/ diff --git a/module_index.json b/module_index.json index 5cdfa55..855f2a1 100755 --- a/module_index.json +++ b/module_index.json @@ -104,7 +104,7 @@ "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.", "id": "feature-search", - "lastupdate": 1498646440, + "lastupdate": 1499101922, "optional": false }, { @@ -131,7 +131,7 @@ "author": "Starbeamrainbowlabs", "description": "Adds the credits page. You *must* have this module :D", "id": "page-credits", - "lastupdate": 1496781899, + "lastupdate": 1499101922, "optional": false }, { @@ -158,7 +158,7 @@ "author": "Starbeamrainbowlabs", "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "id": "page-edit", - "lastupdate": 1488730217, + "lastupdate": 1499101922, "optional": false }, { @@ -185,7 +185,7 @@ "author": "Starbeamrainbowlabs", "description": "Adds a page that lists all the pages in the index along with their metadata.", "id": "page-list", - "lastupdate": 1489074718, + "lastupdate": 1499101922, "optional": false }, { diff --git a/modules/feature-search.php b/modules/feature-search.php old mode 100755 new mode 100644 diff --git a/modules/page-credits.php b/modules/page-credits.php old mode 100755 new mode 100644 diff --git a/modules/page-edit.php b/modules/page-edit.php old mode 100755 new mode 100644 index a5af3c1..2416cd9 --- a/modules/page-edit.php +++ b/modules/page-edit.php @@ -9,6 +9,47 @@ register_module([ "code" => function() { global $settings, $env; + /** + * @api {post} ?action=preview-edit&page={pageName}[&newpage=yes] Get a preview of the page + * @apiDescription Gets a preview of the current edit state of a given page + * @apiName PreviewPage + * @apiPermission Anonymous + * + * @apiUse PageParameter + * @apiParam {string} newpage Set to 'yes' if a new page is being created. + * @apiParam {string} preview-edit Set to a value to preview an edit of a page. + */ + + /* + * + * ██████ ██████ ███████ ██ ██ ██ ███████ ██ ██ + * ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + * ██████ ██████ █████ ██ ██ ██ █████ ██ █ ██ + * ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ + * ██ ██ ██ ███████ ████ ██ ███████ ███ ███ + * + * ███████ ██████ ██ ████████ + * ██ ██ ██ ██ ██ + * █████ ██ ██ ██ ██ + * ██ ██ ██ ██ ██ + * ███████ ██████ ██ ██ + * + */ + add_action("preview-edit", function() { + global $pageindex, $settings, $env, $actions; + + if(isset($_POST['preview-edit']) && isset($_POST['content'])) { + // preview changes + get_object_vars($actions)['edit'](); + } + else { + // save page + get_object_vars($actions)['save'](); + } + + + }); + /** * @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. @@ -38,6 +79,10 @@ register_module([ { $title = "Creating $env->page"; } + else if(isset($_POST['preview-edit']) && isset($_POST['content'])) + { + $title = "Preview Edits for $env->page"; + } else { $title = "Editing $env->page"; @@ -88,7 +133,7 @@ register_module([ exit(page_renderer::render_main("Viewing source for $env->page", $sourceViewContent)); } else - { + { $errorMessage = "The page $env->page
does not exist, but you do not have permission to create it.
If you haven't already, perhaps you should try logging in.
\n"; if($isOtherUsersPage) { @@ -108,14 +153,33 @@ register_module([ { $content .= "Warning: You are not logged in! Your IP address may be recorded.
"; } - $content .= ""; + + // Include preview, if set + if(isset($_POST['preview-edit']) && isset($_POST['content'])) { + // 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 .= " " . parse_page_source($pagetext); + + } + + $content .= ""; // Allow tab characters in the page editor page_renderer::AddJSSnippet("window.addEventListener('load', function(event) { // Adapted from https://jsfiddle.net/2wAzx/13/ diff --git a/modules/page-list.php b/modules/page-list.php old mode 100755 new mode 100644 diff --git a/start-server.sh b/start-server.sh old mode 100644 new mode 100755 diff --git a/theme_default.css b/theme_default.css index 48a7f6a..68d21aa 100644 --- a/theme_default.css +++ b/theme_default.css @@ -73,6 +73,8 @@ textarea { min-height: 10em; line-height: 1.3em; font-size: 1.25rem; } textarea, textarea[name=content] + pre, textarea ~ input[type=submit], #search-box { width: calc(100% - 0.3rem); box-sizing: border-box; } textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight: bolder; } .editform input[type=text] { width: calc(100% - 0.3rem); box-sizing: border-box; } +input.edit-page-button[type='submit'] { width: 49.5%; box-sizing: border-box; } +.preview-message { text-align: center; } .jump-to-comments { position: relative; top: -2.5em; display: block; text-align: right; pointer-events: none; } .jump-to-comments > a { pointer-events: all; }