]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SemanticSearch.php
not yet working good enough
[SourceForge/phpwiki.git] / lib / plugin / SemanticSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: SemanticSearch.php,v 1.1 2006-03-07 20:52:01 rurban Exp $');
3 /*
4  Copyright 2005 Reini Urban
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * @author: Reini Urban
25  */
26 class WikiPlugin_SemanticSearch
27 extends WikiPlugin
28 {
29     function getName() {
30         return _("SemanticSearch");
31     }
32     function getDescription() {
33         return _("Search relations and attributes");
34     }
35     function getVersion() {
36         return preg_replace("/[Revision: $]/", '',
37                             "\$Revision: 1.1 $");
38     }
39     function getDefaultArguments() { 
40         return array(
41                      's'          => "", // query string
42                      'page'       => "", // which pages (glob allowed), default: current
43                      'relation'   => '', // which relations. default all
44                      'attribute'  => '', // which attributes. default all
45                      'units'      => '', // ?
46                      'noheader'   => false,
47                      'nohelp'     => false
48                      );
49     }
50     function run ($dbi, $argstr, &$request, $basepage) { 
51         global $WikiTheme;
52         $args = $this->getArgs($argstr, $request);
53         extract($args);
54         if (empty($page))
55             $page = $request->getArg('pagename');
56         $relhtml = HTML();
57         foreach (explodePageList($page) as $pagename) {
58             $p = $dbi->getPage($pagename);
59             $links = $p->getRelations(); // iter of pagelinks
60             // TODO: merge same relations together located_in::here, located_in::there
61             while ($object = $links->next()) {
62                 if ($related = $object->get('linkrelation')) { // a page name
63                     $relhtml->pushContent
64                         ($pagename . " ",
65                          // Link to a special "Relation:" InterWiki link?
66                          WikiLink($related, false, $related), 
67                          " :: ", // use spaces?
68                          WikiLink($object->_pagename), 
69                          " ",
70                          // Link to SemanticSearch
71                          $WikiTheme->makeActionButton(array('relation' => $related,
72                                                             'object'   => $object->_pagename),
73                                                       '+',
74                                                       _("SemanticSearch")),
75                          HTML::br());
76                 }
77             }
78             if (!empty($relhtml->_content) and !$noheader)
79                 $relhtml = HTML(HTML::hr(),
80                                 HTML::h3(fmt("Semantic relations for %s", $p->getName())),
81                                 $relhtml);
82             $atthtml = HTML();
83             if ($attributes = $p->get('attributes')) { // a hash of unique pairs
84                 foreach ($attributes as $att => $val) {
85                     if ($noheader)
86                         $atthtml->pushContent("$pagename  $att := $val", HTML::br());
87                     else
88                         $atthtml->pushContent("$att := $val", HTML::br());
89                 }
90                 if (!$noheader)
91                     $relhtml = HTML($relhtml,
92                                     HTML::hr(),
93                                     HTML::h3(fmt("Attributes of %s", $p->getName())), 
94                                     $atthtml);
95                 else
96                     $relhtml = HTML($relhtml, $atthtml);
97             }
98         }
99         if ($nohelp) return $relhtml;
100         return HTML($relhtml, 
101                     HTML::hr(), 
102                     WikiLink(_("Help/SemanticRelations"), false,
103                              HTML::em(_("Help/SemanticRelations"))),
104                     " - ",
105                     HTML::em(_("Find out how to add relations and attributes to pages.")));
106     }
107
108 };
109
110 // $Log: not supported by cvs2svn $
111
112 // Local Variables:
113 // mode: php
114 // tab-width: 8
115 // c-basic-offset: 4
116 // c-hanging-comment-ender-p: nil
117 // indent-tabs-mode: nil
118 // End:
119 ?>