2 rcs_id('$Id: LikePages.php,v 1.17 2002-01-31 01:14:14 dairiki 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 return array('page' => '[pagename]',
29 // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor
30 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
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);
54 $descrip = fmt("These pages share an initial or final title word with '%s'",
55 WikiLink($page, 'auto'));
58 // Search for pages containing either the suffix or the prefix.
59 $search = $match = array();
60 if (!empty($prefix)) {
61 $search[] = $this->_quote($prefix);
62 $match[] = '^' . preg_quote($prefix, '/');
64 if (!empty($suffix)) {
65 $search[] = $this->_quote($suffix);
66 $match[] = preg_quote($suffix, '/') . '$';
70 $query = new TextSearchQuery(join(' OR ', $search));
72 $query = new NullTextSearchQuery; // matches nothing
74 $match_re = '/' . join('|', $match) . '/';
76 $pagelist = new PageList($info, $exclude);
78 $pagelist->setCaption($descrip);
80 $pages = $dbi->titleSearch($query);
82 while ($page = $pages->next()) {
83 $name = $page->getName();
84 if (!preg_match($match_re, $name))
86 $pagelist->addPage($page);
92 function _quote($str) {
93 return "'" . str_replace("'", "''", $str) . "'";
101 // c-hanging-comment-ender-p: nil
102 // indent-tabs-mode: nil