4 * Copyright 2005 Reini Urban
6 * This file is part of PhpWiki.
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.
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.
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
24 * SemanticRelations - Display the list of relations and attributes of given page(s).
25 * Relations are stored in the link table.
26 * Attributes as simple page meta-data.
28 * @author: Reini Urban
29 * @see WikiPlugin_SemanticSearch
31 class WikiPlugin_SemanticRelations
35 return _("SemanticRelations");
37 function getDescription() {
38 return _("Display the list of relations and attributes on this page.");
40 function getVersion() {
41 return preg_replace("/[Revision: $]/", '',
44 function getDefaultArguments() {
46 'page' => "[pagename]", // which pages (glob allowed), default: current
47 'relations' => '', // which relations. default all
48 'attributes' => '', // which attributes. default all
54 function run ($dbi, $argstr, &$request, $basepage) {
56 $args = $this->getArgs($argstr, $request);
59 $page = $request->getArg('pagename');
61 if ($args['relations'] != '') {
62 $relfilter = explode(",", $args['relations']);
65 if ($args['attributes'] != '') {
66 $attfilter = explode(",", $args['attributes']);
69 foreach (explodePageList($page) as $pagename) {
70 $p = $dbi->getPage($pagename);
71 if ($args['relations'] != '0') {
72 $links = $p->getRelations(); // iter of pagelinks
73 // TODO: merge same relations together located_in::here, located_in::there
74 while ($object = $links->next()) {
75 if ($related = $object->get('linkrelation')) { // a page name
76 if ($relfilter and !in_array($related, $relfilter)) {
79 $rellink = WikiLink($related, false, $related);
80 $rellink->setAttr('class', $rellink->getAttr('class').' relation');
83 // Link to a special "Relation:" InterWiki link?
85 HTML::span(array('class'=>'relation-symbol'), "::"), // use spaces?
86 WikiLink($object->_pagename),
88 // Link to SemanticSearch
89 $WikiTheme->makeActionButton(array('relation' => $related,
90 's' => $object->_pagename),
93 (count($relfilter) > 3 ? HTML::br() : " "));
96 if (!empty($relhtml->_content) and !$noheader)
97 $relhtml = HTML(HTML::hr(),
98 HTML::h3(fmt("Semantic relations for %s", $pagename)),
102 if ($args['attributes'] != '0') {
103 if ($attributes = $p->get('attributes')) { // a hash of unique pairs
104 foreach ($attributes as $att => $val) {
105 if ($attfilter and !in_array($att, $attfilter)) continue;
106 $rellink = WikiLink($att, false, $att);
107 $rellink->setAttr('class', $rellink->getAttr('class').' relation');
108 $searchlink = $WikiTheme->makeActionButton
109 (array('attribute' => $att,
112 _("SemanticSearch"));
113 $searchlink->setAttr('class', $searchlink->getAttr('class').' attribute');
115 $atthtml->pushContent("$pagename ");
116 $atthtml->pushContent(HTML::span(array('class' => 'attribute '.$att),
118 HTML::span(array('class'=>'relation-symbol'),
121 (count($attfilter) > 3 ? HTML::br() : " "));
124 $relhtml = HTML($relhtml,
126 HTML::h3(fmt("Attributes of %s", $pagename)),
129 $relhtml = HTML($relhtml, $atthtml);
133 if ($nohelp) return $relhtml;
134 return HTML($relhtml,
136 WikiLink(_("Help/SemanticRelations"), false,
137 HTML::em(_("Help/SemanticRelations"))),
139 HTML::em(_("Find out how to add relations and attributes to pages.")));
147 // c-hanging-comment-ender-p: nil
148 // indent-tabs-mode: nil