1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Update the idindex when moving a page. Fixes #33.

This commit is contained in:
Starbeamrainbowlabs 2015-11-11 18:49:08 +00:00
parent 05026b9045
commit 43d15f9212
4 changed files with 37 additions and 9 deletions

View file

@ -771,6 +771,16 @@ class ids
return $idindex->$id;
}
public static function movepagename($oldpagename, $newpagename)
{
global $idindex, $paths;
$pageid = self::getid($oldpagename);
$idindex->$pageid = $newpagename;
file_put_contents($paths->idindex, json_encode($idindex));
}
/*
* @summary Assigns an id to a pagename. Doesn't check to make sure that
* pagename doesn't exist in the pageindex.
@ -1086,7 +1096,7 @@ if(!isset($pageindex->{$env->page}) and isset($_GET["search-redirect"]))
http_response_code(307);
$url = "?action=search&query=" . rawurlencode($env->page);
header("location: $url");
exit(pagerenderer::render("Non existent page - $settings->sitename", "<p>There isn't a page on $settings->sitename with that name. However, you could <a href='$url'>search for this page name</a> in other pages.</p>
exit(page_renderer::render("Non existent page - $settings->sitename", "<p>There isn't a page on $settings->sitename with that name. However, you could <a href='$url'>search for this page name</a> in other pages.</p>
<p>Alternatively, you could <a href='?action=edit&page=" . rawurlencode($env->page) . "&create=true'>create this page</a>.</p>"));
}
//////////////////////////////////////
@ -2897,7 +2907,7 @@ register_module([
"id" => "page-move",
"code" => function() {
add_action("move", function() {
global $pageindex, $settings, $env;
global $pageindex, $settings, $env, $paths;
if(!$settings->editing)
{
exit(page_renderer::render_main("Moving $env->page - error", "<p>You tried to move $env->page, but editing is disabled on this wiki.</p>
@ -2954,11 +2964,15 @@ register_module([
// Move the file on disk
rename($env->storage_prefix . $env->page, $env->storage_prefix . $new_name);
}
file_put_contents($env->storage_prefix . "pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
//move the page on the disk
// Move the page on the disk
rename("$env->storage_prefix$env->page.md", "$env->storage_prefix$new_name.md");
// Move the page in the id index
ids::movepagename($page, $new_name);
// Exit with a nice message
exit(page_renderer::render_main("Moving $env->page", "<p><a href='index.php?page=$env->page'>$env->page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
});
}

View file

@ -433,6 +433,16 @@ class ids
return $idindex->$id;
}
public static function movepagename($oldpagename, $newpagename)
{
global $idindex, $paths;
$pageid = self::getid($oldpagename);
$idindex->$pageid = $newpagename;
file_put_contents($paths->idindex, json_encode($idindex));
}
/*
* @summary Assigns an id to a pagename. Doesn't check to make sure that
* pagename doesn't exist in the pageindex.
@ -748,7 +758,7 @@ if(!isset($pageindex->{$env->page}) and isset($_GET["search-redirect"]))
http_response_code(307);
$url = "?action=search&query=" . rawurlencode($env->page);
header("location: $url");
exit(pagerenderer::render("Non existent page - $settings->sitename", "<p>There isn't a page on $settings->sitename with that name. However, you could <a href='$url'>search for this page name</a> in other pages.</p>
exit(page_renderer::render("Non existent page - $settings->sitename", "<p>There isn't a page on $settings->sitename with that name. However, you could <a href='$url'>search for this page name</a> in other pages.</p>
<p>Alternatively, you could <a href='?action=edit&page=" . rawurlencode($env->page) . "&create=true'>create this page</a>.</p>"));
}
//////////////////////////////////////

View file

@ -140,7 +140,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to move pages.",
"id": "page-move",
"lastupdate": 1447266462,
"lastupdate": 1447267600,
"optional": false
},
{

View file

@ -7,7 +7,7 @@ register_module([
"id" => "page-move",
"code" => function() {
add_action("move", function() {
global $pageindex, $settings, $env;
global $pageindex, $settings, $env, $paths;
if(!$settings->editing)
{
exit(page_renderer::render_main("Moving $env->page - error", "<p>You tried to move $env->page, but editing is disabled on this wiki.</p>
@ -64,11 +64,15 @@ register_module([
// Move the file on disk
rename($env->storage_prefix . $env->page, $env->storage_prefix . $new_name);
}
file_put_contents($env->storage_prefix . "pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
//move the page on the disk
// Move the page on the disk
rename("$env->storage_prefix$env->page.md", "$env->storage_prefix$new_name.md");
// Move the page in the id index
ids::movepagename($page, $new_name);
// Exit with a nice message
exit(page_renderer::render_main("Moving $env->page", "<p><a href='index.php?page=$env->page'>$env->page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
});
}