2015-04-11 17:30:01 +00:00
< ? php
register_module ([
" name " => " Page mover " ,
2015-05-24 20:00:30 +00:00
" version " => " 0.5 " ,
2015-04-11 17:30:01 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Adds an action to allow administrators to move pages. " ,
" id " => " page-move " ,
" code " => function () {
add_action ( " move " , function () {
global $pageindex , $settings , $page , $isadmin ;
if ( ! $settings -> editing )
{
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " Moving $page - error " , " <p>You tried to move $page , but editing is disabled on this wiki.</p>
2015-04-11 17:30:01 +00:00
< p > If you wish to move this page , please re - enable editing on this wiki first .</ p >
< p >< a href = 'index.php?page=$page' > Go back to $page </ a >.</ p >
< p > Nothing has been changed .</ p > " ));
}
if ( ! $isadmin )
{
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " Moving $page - Error " , " <p>You tried to move $page , but you do not have permission to do that.</p>
2015-04-11 17:30:01 +00:00
< 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 )
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " Moving $page " , " <h2>Moving $page </h2>
2015-04-11 17:30:01 +00:00
< 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 ))
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " 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>
2015-04-11 17:30:01 +00:00
< p > Nothing has been changed .</ p > " ));
if ( $page == $new_name )
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " Moving $page - Error " , " <p>You tried to move $page , but the new name you gave is the same as it's current name.</p>
2015-04-11 17:30:01 +00:00
< 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 " );
2015-05-24 20:00:30 +00:00
exit ( page_renderer :: render_main ( " 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> " ));
2015-04-11 17:30:01 +00:00
});
}
]);
?>