2 rcs_id('$Id: LikePages.php,v 1.4 2001-12-16 19:35:35 dairiki Exp $');
4 require_once('lib/TextSearchQuery.php');
8 class WikiPlugin_LikePages
12 return _("LikePages");
15 function getDescription() {
16 return _("List LikePages for [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', sprintf(_("Page names with prefix '%s'"),
44 $html .= QElement('p', sprintf(_("Page names with suffix '%s'"),
48 $words = preg_split('/[\s:-;.,]+/',
49 split_pagename($page));
50 $words = preg_grep('/\S/', $words);
52 $prefix = reset($words);
53 $suffix = end($words);
57 $fs = _("These pages share an initial or final title word with '%s'");
58 $html .= Element('p', sprintf(htmlspecialchars($fs), LinkWikiWord($page)));
62 // Search for pages containing either the suffix or the prefix.
63 $search = $match = array();
64 if (!empty($prefix)) {
65 $search[] = $this->_quote($prefix);
66 $match[] = '^' . preg_quote($prefix, '/');
68 if (!empty($suffix)) {
69 $search[] = $this->_quote($suffix);
70 $match[] = preg_quote($suffix, '/') . '$';
74 $query = new TextSearchQuery(join(' OR ', $search));
76 $query = new NullTextSearchQuery; // matches nothing
78 $match_re = '/' . join('|', $match) . '/';
80 $pages = $dbi->titleSearch($query);
82 while ($page = $pages->next()) {
83 $name = $page->getName();
84 if (!preg_match($match_re, $name))
86 if (!empty($exclude) && $name == $exclude)
88 $lines[] = Element('li', LinkWikiWord($name));
91 $html .= Element('ul', join("\n", $lines));
93 $html .= QElement('blockquote', gettext("<none>"));
98 function _quote($str) {
99 return "'" . str_replace("'", "''", $str) . "'";
107 // c-hanging-comment-ender-p: nil
108 // indent-tabs-mode: nil