mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 17:23:00 +00:00
Integrate search into top bar
This commit is contained in:
parent
7957b3ca2e
commit
e79e522d78
4 changed files with 53 additions and 5 deletions
|
@ -963,7 +963,7 @@ class page_renderer
|
|||
break;
|
||||
|
||||
case "search": // Displays a search bar
|
||||
$result .= "<span class='inflexible'><form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /></form></span>";
|
||||
$result .= "<span class='inflexible'><form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /><input type='hidden' name='search-redirect' value='true' /></form></span>";
|
||||
break;
|
||||
|
||||
case "divider": // Displays a divider
|
||||
|
@ -1018,6 +1018,20 @@ class page_renderer
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
///// Extra consistency measures /////
|
||||
//////////////////////////////////////
|
||||
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>
|
||||
<p>Alternatively, you could <a href='?action=edit&page=" . rawurlencode($env->page) . "&create=true'>create this page</a>.</p>"));
|
||||
}
|
||||
//////////////////////////////////////
|
||||
//////////////////////////////////////
|
||||
|
||||
//////////////////////////
|
||||
/// Module functions ///
|
||||
//////////////////////////
|
||||
|
@ -1358,7 +1372,7 @@ register_module([
|
|||
});
|
||||
|
||||
add_action("search", function() {
|
||||
global $settings;
|
||||
global $settings, $env, $pageindex;
|
||||
|
||||
if(!isset($_GET["query"]))
|
||||
exit(page_renderer::render("No Search Terms - Error - $settings->sitename", "<p>You didn't specify any search terms. Try typing some into the box above.</p>"));
|
||||
|
@ -1381,6 +1395,16 @@ register_module([
|
|||
$content .= " <input type='hidden' name='action' value='search' />\n";
|
||||
$content .= "</form>";
|
||||
|
||||
$query = $_GET["query"];
|
||||
if(isset($pageindex->$query))
|
||||
{
|
||||
$content .= "<p>There's a page on $settings->sitename called <a href='?page=" . rawurlencode($query) . "'>$query</a>.</p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$content .= "<p>There isn't a page called $query on $settings->sitename, but you can <a href='?action=edit&page=" . rawurlencode($query) . "'>create it</a>.</p>";
|
||||
}
|
||||
|
||||
$i = 0; // todo use $_GET["offset"] and $_GET["result-count"] or something
|
||||
foreach($results as $result)
|
||||
{
|
||||
|
|
16
core.php
16
core.php
|
@ -638,7 +638,7 @@ class page_renderer
|
|||
break;
|
||||
|
||||
case "search": // Displays a search bar
|
||||
$result .= "<span class='inflexible'><form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /></form></span>";
|
||||
$result .= "<span class='inflexible'><form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /><input type='hidden' name='search-redirect' value='true' /></form></span>";
|
||||
break;
|
||||
|
||||
case "divider": // Displays a divider
|
||||
|
@ -693,6 +693,20 @@ class page_renderer
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
///// Extra consistency measures /////
|
||||
//////////////////////////////////////
|
||||
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>
|
||||
<p>Alternatively, you could <a href='?action=edit&page=" . rawurlencode($env->page) . "&create=true'>create this page</a>.</p>"));
|
||||
}
|
||||
//////////////////////////////////////
|
||||
//////////////////////////////////////
|
||||
|
||||
//////////////////////////
|
||||
/// Module functions ///
|
||||
//////////////////////////
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
|
||||
"id": "feature-search",
|
||||
"lastupdate": 1446300948,
|
||||
"lastupdate": 1446372585,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ register_module([
|
|||
});
|
||||
|
||||
add_action("search", function() {
|
||||
global $settings;
|
||||
global $settings, $env, $pageindex;
|
||||
|
||||
if(!isset($_GET["query"]))
|
||||
exit(page_renderer::render("No Search Terms - Error - $settings->sitename", "<p>You didn't specify any search terms. Try typing some into the box above.</p>"));
|
||||
|
@ -51,6 +51,16 @@ register_module([
|
|||
$content .= " <input type='hidden' name='action' value='search' />\n";
|
||||
$content .= "</form>";
|
||||
|
||||
$query = $_GET["query"];
|
||||
if(isset($pageindex->$query))
|
||||
{
|
||||
$content .= "<p>There's a page on $settings->sitename called <a href='?page=" . rawurlencode($query) . "'>$query</a>.</p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$content .= "<p>There isn't a page called $query on $settings->sitename, but you can <a href='?action=edit&page=" . rawurlencode($query) . "'>create it</a>.</p>";
|
||||
}
|
||||
|
||||
$i = 0; // todo use $_GET["offset"] and $_GET["result-count"] or something
|
||||
foreach($results as $result)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue