I missed the opportunity to do specific title searches, so I implemented a macro to do this. Using this macro it's possible to present the search result in several styles, and this is documented in TaviPatches/TitleSearchExamples.
To install the macro do the following:
And then you're done. Now go ahead and create all the title searches you want. And I will come back, hopefully, with a patch to include a title-search form to use at the bottom of the pages. (If anyone want to do this, feel free... I'm thinking something along the lines of the search already in there)
function view_macro_titlesearch ($args)
{
// Description of TitleSearch macro:
// [[TitleSearch search-pattern liststyle]]
// This macro searches for page-titles matching the searchpattern,
// and presents it according to liststyle. The pattern may include
// ^ or $ to lock it against start or end, and otherwise it must
// only contain alpha-characters. The special pattern '*' matches
// every title.
//
// The liststyle can have one of the following values:
// OneLine: Search result is displayed separated by spaces on
// one long line/paragraph
// CommaDelim : On one line, delimited by ', '
// BarDelim : On one line, delimited by ' | '
// Bullet : In a bulleted list
// default : Each result on a single line, with <pre>-tags around
global $pagestore, $AlphaPtn;
// Parse multiple arguments, split by whitespace
$search = strtok($args, ' ');
$listStyle = strtok(' ');
$text = '';
// Check for illegal characters to make search pattern safer against exploits
if ($search == '*') { // Match every title
$pattern = ".";
} else if ( !preg_match("|^[\^]?$AlphaPtn+[$]?$|", $search)) {
// Search can be locked at start and/or end, and elsewise only
// contain Alpha-characters, digits not included and '/' not
// included
return "[[TitleSearch $args $AlphaPtn]]";
} else {
// $search validates, so use as is
$pattern=$search;
}
// Set up the correct pattern for inserting the item according
// to which liststyle is wanted
if ($listStyle == "OneLine") { $insertStr = "%s "; }
else if ($listStyle == "CommaDelim") { $insertStr = "%s, "; }
else if ($listStyle == "BarDelim") { $insertStr = "%s | "; }
else if ($listStyle == "Bullet") { $insertStr = " <li>%s</li>\n"; }
else { $insertStr = "%s\n"; }
// Loop through all pagetitles
$list = $pagestore->allpages();
foreach($list as $page)
{
if (preg_match("|$pattern|", $page[1])) {
$text .= sprintf($insertStr, html_ref($page[1], $page[1]));
}
}
// The different liststyles need some different cleanup afterwards
if (($listStyle == "CommaDelim") or ($listStyle == "BarDelim")) {
$text = preg_replace("/[|,]+ $/", "\n", $text);
} else if ($listStyle == "Bullet") {
$text = "<ul>\n$text\n</ul>";
} else if ($listStyle == "OneLine") {
; // No need for extra work, do a noop to prevent html_code'ing
} else {
$text = html_code ($text);
}
return $text;
}