2 rcs_id('$Id: LikePages.php,v 1.11 2002-01-22 06:15:52 carstenklapp Exp $');
4 require_once('lib/TextSearchQuery.php');
5 require_once('lib/PageList.php');
9 class WikiPlugin_LikePages
13 return _("LikePages");
16 function getDescription() {
17 return sprintf(_("List LikePages for %s"), '[pagename]');
20 function getDefaultArguments() {
21 // FIXME: how to exclude multiple pages?
22 return array('page' => false,
30 // info arg now allows multiple columns info=mtime,hits,summary,author,locked,minor
32 function run($dbi, $argstr, $request) {
33 $args = $this->getArgs($argstr, $request);
35 if (empty($page) && empty($prefix) && empty($suffix))
41 $descrip = fmt("Page names with prefix '%s'", $prefix);
44 $descrip = fmt("Page names with suffix '%s'", $suffix);
47 $words = preg_split('/[\s:-;.,]+/',
48 split_pagename($page));
49 $words = preg_grep('/\S/', $words);
51 $prefix = reset($words);
52 $suffix = end($words);
55 $descrip = fmt("These pages share an initial or final title word with '%s'",
59 // Search for pages containing either the suffix or the prefix.
60 $search = $match = array();
61 if (!empty($prefix)) {
62 $search[] = $this->_quote($prefix);
63 $match[] = '^' . preg_quote($prefix, '/');
65 if (!empty($suffix)) {
66 $search[] = $this->_quote($suffix);
67 $match[] = preg_quote($suffix, '/') . '$';
71 $query = new TextSearchQuery(join(' OR ', $search));
73 $query = new NullTextSearchQuery; // matches nothing
75 $match_re = '/' . join('|', $match) . '/';
77 $pages = $dbi->titleSearch($query);
78 $pagelist = new PageList;
81 foreach (explode(",", $info) as $col)
82 $pagelist->insertColumn($col);
84 while ($page = $pages->next()) {
85 $name = $page->getName();
86 if (!preg_match($match_re, $name))
88 if (!empty($exclude) && $name == $exclude)
91 $pagelist->addPage($page);
95 $pagelist->setCaption($descrip);
100 function _quote($str) {
101 return "'" . str_replace("'", "''", $str) . "'";
109 // c-hanging-comment-ender-p: nil
110 // indent-tabs-mode: nil