2 rcs_id('$Id: LikePages.php,v 1.1 2001-09-18 19:19:05 dairiki Exp $');
4 require_once('lib/TextSearchQuery.php');
8 class WikiPlugin_LikePages
11 var $name = 'LikePages';
13 function getDefaultArguments() {
14 // FIXME: how to exclude multiple pages?
15 return array('page' => false,
23 function run($dbi, $argstr, $request) {
24 $args = $this->getArgs($argstr, $request);
26 if (empty($page) && empty($prefix) && empty($suffix))
33 $html .= QElement('p', sprintf(gettext("Page names with prefix '%s'"),
38 $html .= QElement('p', sprintf(gettext("Page names with suffix '%s'"),
42 $words = explode(" ", split_pagename($page));
45 list($suffix) = array_reverse($words);
48 $fs = gettext("These pages share an initial or final title word with '%s'");
50 $html .= Element('p', sprintf(htmlspecialchars($fs), LinkWikiWord($page)));
53 // Search for pages containing either the suffix or the prefix.
55 if (!empty($prefix)) {
56 $search[] = $this->_quote($prefix);
57 $match[] = '^' . preg_quote($prefix, '/');
59 if (!empty($suffix)) {
60 $search[] = $this->_quote($suffix);
61 $match[] = preg_quote($suffix, '/') . '$';
63 $query = new TextSearchQuery(join(' OR ', $search));
64 $match_re = '/' . join('|', $match) . '/';
66 $pages = $dbi->titleSearch($query);
68 while ($page = $pages->next()) {
69 $name = $page->getName();
70 if (!preg_match($match_re, $name))
72 if (!empty($exclude) && $name == $exclude)
74 $lines[] = Element('li', LinkWikiWord($name));
77 $html .= Element('ul', join("\n", $lines));
79 $html .= QElement('blockquote', gettext("<none>"));
84 function _quote($str) {
85 return "'" . str_replace("'", "''", $str) . "'";
93 // c-hanging-comment-ender-p: nil
94 // indent-tabs-mode: nil