]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/TitleSearch.php
Begin refactoring.
[SourceForge/phpwiki.git] / lib / plugin / TitleSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: TitleSearch.php,v 1.12 2002-01-30 22:47:31 carstenklapp Exp $');
3
4 require_once('lib/TextSearchQuery.php');
5 require_once('lib/PageList.php');
6
7 /**
8  */
9 class WikiPlugin_TitleSearch
10 extends WikiPlugin
11 {
12     function getName () {
13         return _("TitleSearch");
14     }
15
16     function getDescription () {
17         return _("Title Search");
18     }
19     
20     function getDefaultArguments() {
21         return array('s'                => false,
22                      'auto_redirect'    => false,
23                      'noheader'         => false,
24                      'exclude'          => '',
25                      'include_self'     => 1,
26                      'pagename'         => '[pagename]', // hackish
27                      'info'             => false
28                      );
29     }
30     // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor
31     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
32
33     function run($dbi, $argstr, $request) {
34         $args = $this->getArgs($argstr, $request);
35         if (empty($args['s']))
36             return '';
37
38         extract($args);
39         
40         $query = new TextSearchQuery($s);
41         $pages = $dbi->titleSearch($query);
42
43         $pagelist = new PageList();
44         $this->_init($pagename, &$pagelist, $info, $exclude, $include_self);
45
46         while ($page = $pages->next()) {
47             $pagelist->addPage($page);
48             // if (!$pagelist->page_excluded($page->getName())); // not necessary
49             $last_name = $page->getName();
50         }
51
52         if ($auto_redirect && ($pagelist->getTotal() == 1))
53             $request->redirect(WikiURL($last_name));
54
55         if (!$noheader)
56             $pagelist->setCaption(fmt("Title search results for '%s'", $s));
57
58         return $pagelist;
59     }
60
61     function _init(&$page, &$pagelist, $info = '', $exclude = '', $include_self = '') {
62         if ($info)
63             foreach (explode(",", $info) as $col)
64                 $pagelist->insertColumn($col);
65
66         if ($exclude)
67             foreach (explode(",", $exclude) as $excludepage)
68                 $pagelist->excludePageName($excludepage);
69         if (!$include_self)
70             $pagelist->excludePageName($page);
71    }
72
73 };
74         
75 // Local Variables:
76 // mode: php
77 // tab-width: 8
78 // c-basic-offset: 4
79 // c-hanging-comment-ender-p: nil
80 // indent-tabs-mode: nil
81 // End:   
82 ?>