2 rcs_id('$Id: LikePages.php,v 1.7 2002-01-21 06:55:47 dairiki 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))
38 $descrip = fmt("Page names with prefix '%s'", $prefix);
41 $descrip = fmt("Page names with suffix '%s'", $suffix);
44 $words = preg_split('/[\s:-;.,]+/',
45 split_pagename($page));
46 $words = preg_grep('/\S/', $words);
48 $prefix = reset($words);
49 $suffix = end($words);
52 $descrip = fmt("These pages share an initial or final title word with '%s'",
53 _LinkWikiWord($page));
56 // Search for pages containing either the suffix or the prefix.
57 $search = $match = array();
58 if (!empty($prefix)) {
59 $search[] = $this->_quote($prefix);
60 $match[] = '^' . preg_quote($prefix, '/');
62 if (!empty($suffix)) {
63 $search[] = $this->_quote($suffix);
64 $match[] = preg_quote($suffix, '/') . '$';
68 $query = new TextSearchQuery(join(' OR ', $search));
70 $query = new NullTextSearchQuery; // matches nothing
72 $match_re = '/' . join('|', $match) . '/';
74 $pages = $dbi->titleSearch($query);
76 while ($page = $pages->next()) {
77 $name = $page->getName();
78 if (!preg_match($match_re, $name))
80 if (!empty($exclude) && $name == $exclude)
82 $list->pushContent(HTML::li(_LinkWikiWord($name)));
84 if (!$list->getContent())
85 $list = HTML::blockquote(_("<none>"));
89 return array(HTML::p($descrip), $list);
92 function _quote($str) {
93 return "'" . str_replace("'", "''", $str) . "'";
101 // c-hanging-comment-ender-p: nil
102 // indent-tabs-mode: nil