2 rcs_id('$Id: LikePages.php,v 1.6 2002-01-09 18:06:49 carstenklapp Exp $');
4 require_once('lib/TextSearchQuery.php');
8 class WikiPlugin_LikePages
12 return _("LikePages");
15 function getDescription() {
16 return sprintf(_("List LikePages for %s"), '[pagename]');
19 function getDefaultArguments() {
20 // FIXME: how to exclude multiple pages?
21 return array('page' => false,
29 function run($dbi, $argstr, $request) {
30 $args = $this->getArgs($argstr, $request);
32 if (empty($page) && empty($prefix) && empty($suffix))
39 $html .= QElement('p',
40 sprintf(_("Page names with prefix '%s'"),
45 $html .= QElement('p',
46 sprintf(_("Page names with suffix '%s'"),
50 $words = preg_split('/[\s:-;.,]+/',
51 split_pagename($page));
52 $words = preg_grep('/\S/', $words);
54 $prefix = reset($words);
55 $suffix = end($words);
59 $fs = _("These pages share an initial or final title word with '%s'");
60 $html .= Element('p', sprintf(htmlspecialchars($fs),
61 LinkWikiWord($page)));
65 // Search for pages containing either the suffix or the prefix.
66 $search = $match = array();
67 if (!empty($prefix)) {
68 $search[] = $this->_quote($prefix);
69 $match[] = '^' . preg_quote($prefix, '/');
71 if (!empty($suffix)) {
72 $search[] = $this->_quote($suffix);
73 $match[] = preg_quote($suffix, '/') . '$';
77 $query = new TextSearchQuery(join(' OR ', $search));
79 $query = new NullTextSearchQuery; // matches nothing
81 $match_re = '/' . join('|', $match) . '/';
83 $pages = $dbi->titleSearch($query);
85 while ($page = $pages->next()) {
86 $name = $page->getName();
87 if (!preg_match($match_re, $name))
89 if (!empty($exclude) && $name == $exclude)
91 $lines[] = Element('li', LinkWikiWord($name));
94 $html .= Element('ul', join("\n", $lines));
96 $html .= QElement('blockquote', gettext("<none>"));
101 function _quote($str) {
102 return "'" . str_replace("'", "''", $str) . "'";
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil