mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Added page moving functionality for admins
This commit is contained in:
parent
2975b6c577
commit
fc2791d738
3 changed files with 88 additions and 4 deletions
42
core.php
42
core.php
|
@ -553,7 +553,47 @@ switch($_GET["action"])
|
|||
* %move%
|
||||
*/
|
||||
case "move":
|
||||
exit(renderpage("Moving $page", "<p>Coming soon...</p>"));
|
||||
if(!$isadmin)
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but you do not have permission to do that.</p>
|
||||
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
|
||||
|
||||
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
|
||||
exit(renderpage("Moving $page", "<h2>Moving $page</h2>
|
||||
<form method='get' action='index.php'>
|
||||
<input type='hidden' name='action' value='move' />
|
||||
<label for='old_name'>Old Name:</label>
|
||||
<input type='text' name='page' value='$page' readonly />
|
||||
<br />
|
||||
<label for='new_name'>New Name:</label>
|
||||
<input type='text' name='new_name' />
|
||||
<br />
|
||||
<input type='submit' value='Move Page' />
|
||||
</form>"));
|
||||
|
||||
$new_name = makepathsafe($_GET["new_name"]);
|
||||
|
||||
if(!isset($pageindex->$page))
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page to $new_name, but the page with the name $page does not exist in the first place.</p>
|
||||
<p>Nothing has been changed.</p>"));
|
||||
|
||||
if($page == $new_name)
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
|
||||
<p>It is possible that you tried to use some characters in the new name that are not allowed and were removed.</p>
|
||||
<p>Page names may only contain alphanumeric characters, dashes, and underscores.</p>"));
|
||||
|
||||
//move the page in the page index
|
||||
$pageindex->$new_name = new stdClass();
|
||||
foreach($pageindex->$page as $key => $value)
|
||||
{
|
||||
$pageindex->$new_name->$key = $value;
|
||||
}
|
||||
unset($pageindex->$page);
|
||||
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||
|
||||
//move the page on the disk
|
||||
rename("$page.md", "$new_name.md");
|
||||
|
||||
exit(renderpage("Moving $page", "<p><a href='index.php?page=$page'>$page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
|
||||
break;
|
||||
|
||||
/*
|
||||
|
|
46
index.php
46
index.php
|
@ -67,6 +67,7 @@ $navlinks = [
|
|||
[ "Printable", "index.php?action=view&printable=yes&page={page}" ],
|
||||
" | ",
|
||||
[ $admindisplaychar . "Delete", "index.php?action=delete&page={page}" ],
|
||||
[ $admindisplaychar . "Move", "index.php?action=move&page={page}" ],
|
||||
" | ",
|
||||
[ "All Pages", "index.php?action=list" ],
|
||||
" | ",
|
||||
|
@ -77,8 +78,9 @@ $navlinks = [
|
|||
//string of css to include
|
||||
//may be a url - urls will be referenced via a <link rel='stylesheet' /> tag
|
||||
$css = "body { font-family: sans-serif; color: #333333; background: #f3f3f3; }
|
||||
label { display: inline-block; min-width: 10rem; }
|
||||
textarea[name=content] { display: block; width: 100%; height: 35rem; }
|
||||
input[name=page] { width: 16rem; }
|
||||
/*input[name=page] { width: 16rem; }*/
|
||||
nav { position: absolute; top: 5px; right: 5px; }
|
||||
th { text-align: left; }
|
||||
.sitename { text-align: center; font-size: 2.5rem; color: #222222; }
|
||||
|
@ -666,7 +668,47 @@ switch($_GET["action"])
|
|||
* %move%
|
||||
*/
|
||||
case "move":
|
||||
exit(renderpage("Moving $page", "<p>Coming soon...</p>"));
|
||||
if(!$isadmin)
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but you do not have permission to do that.</p>
|
||||
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
|
||||
|
||||
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
|
||||
exit(renderpage("Moving $page", "<h2>Moving $page</h2>
|
||||
<form method='get' action='index.php'>
|
||||
<input type='hidden' name='action' value='move' />
|
||||
<label for='old_name'>Old Name:</label>
|
||||
<input type='text' name='page' value='$page' readonly />
|
||||
<br />
|
||||
<label for='new_name'>New Name:</label>
|
||||
<input type='text' name='new_name' />
|
||||
<br />
|
||||
<input type='submit' value='Move Page' />
|
||||
</form>"));
|
||||
|
||||
$new_name = makepathsafe($_GET["new_name"]);
|
||||
|
||||
if(!isset($pageindex->$page))
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page to $new_name, but the page with the name $page does not exist in the first place.</p>
|
||||
<p>Nothing has been changed.</p>"));
|
||||
|
||||
if($page == $new_name)
|
||||
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
|
||||
<p>It is possible that you tried to use some characters in the new name that are not allowed and were removed.</p>
|
||||
<p>Page names may only contain alphanumeric characters, dashes, and underscores.</p>"));
|
||||
|
||||
//move the page in the page index
|
||||
$pageindex->$new_name = new stdClass();
|
||||
foreach($pageindex->$page as $key => $value)
|
||||
{
|
||||
$pageindex->$new_name->$key = $value;
|
||||
}
|
||||
unset($pageindex->$page);
|
||||
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||
|
||||
//move the page on the disk
|
||||
rename("$page.md", "$new_name.md");
|
||||
|
||||
exit(renderpage("Moving $page", "<p><a href='index.php?page=$page'>$page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
|
||||
break;
|
||||
|
||||
/*
|
||||
|
|
|
@ -64,6 +64,7 @@ $navlinks = [
|
|||
[ "Printable", "index.php?action=view&printable=yes&page={page}" ],
|
||||
" | ",
|
||||
[ $admindisplaychar . "Delete", "index.php?action=delete&page={page}" ],
|
||||
[ $admindisplaychar . "Move", "index.php?action=move&page={page}" ],
|
||||
" | ",
|
||||
[ "All Pages", "index.php?action=list" ],
|
||||
" | ",
|
||||
|
@ -74,8 +75,9 @@ $navlinks = [
|
|||
//string of css to include
|
||||
//may be a url - urls will be referenced via a <link rel='stylesheet' /> tag
|
||||
$css = "body { font-family: sans-serif; color: #333333; background: #f3f3f3; }
|
||||
label { display: inline-block; min-width: 10rem; }
|
||||
textarea[name=content] { display: block; width: 100%; height: 35rem; }
|
||||
input[name=page] { width: 16rem; }
|
||||
/*input[name=page] { width: 16rem; }*/
|
||||
nav { position: absolute; top: 5px; right: 5px; }
|
||||
th { text-align: left; }
|
||||
.sitename { text-align: center; font-size: 2.5rem; color: #222222; }
|
||||
|
|
Loading…
Reference in a new issue