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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
34 function getDescription()
36 return _("Display the list of relations and attributes on this page.");
39 function getDefaultArguments()
42 'page' => "[pagename]", // which pages (glob allowed), default: current
43 'relations' => '', // which relations. default all
44 'attributes' => '', // which attributes. default all
51 function run($dbi, $argstr, &$request, $basepage)
54 $args = $this->getArgs($argstr, $request);
57 $page = $request->getArg('pagename');
59 if ($args['relations'] != '') {
60 $relfilter = explode(",", $args['relations']);
63 if ($args['attributes'] != '') {
64 $attfilter = explode(",", $args['attributes']);
67 foreach (explodePageList($page) as $pagename) {
68 $p = $dbi->getPage($pagename);
69 if ($args['relations'] != '0') {
70 $links = $p->getRelations(); // iter of pagelinks
71 // TODO: merge same relations together located_in::here, located_in::there
72 while ($object = $links->next()) {
73 if ($related = $object->get('linkrelation')) { // a page name
74 if ($relfilter and !in_array($related, $relfilter)) {
77 $rellink = WikiLink($related, false, $related);
78 $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
81 // Link to a special "Relation:" InterWiki link?
83 HTML::span(array('class' => 'relation-symbol'), "::"), // use spaces?
84 WikiLink($object->_pagename),
86 // Link to SemanticSearch
87 $WikiTheme->makeActionButton(array('relation' => $related,
88 's' => $object->_pagename),
91 (count($relfilter) > 3 ? HTML::br() : " "));
94 if (!empty($relhtml->_content) and !$noheader)
95 $relhtml = HTML(HTML::hr(),
96 HTML::h3(fmt("Semantic relations for %s", $pagename)),
100 if ($args['attributes'] != '0') {
101 if ($attributes = $p->get('attributes')) { // a hash of unique pairs
102 foreach ($attributes as $att => $val) {
103 if ($attfilter and !in_array($att, $attfilter)) continue;
104 $rellink = WikiLink($att, false, $att);
105 $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
106 $searchlink = $WikiTheme->makeActionButton
107 (array('attribute' => $att,
110 _("SemanticSearch"));
111 $searchlink->setAttr('class', $searchlink->getAttr('class') . ' attribute');
113 $atthtml->pushContent("$pagename ");
114 $atthtml->pushContent(HTML::span(array('class' => 'attribute ' . $att),
116 HTML::span(array('class' => 'relation-symbol'),
119 (count($attfilter) > 3 ? HTML::br() : " "));
122 $relhtml = HTML($relhtml,
124 HTML::h3(fmt("Attributes of %s", $pagename)),
127 $relhtml = HTML($relhtml, $atthtml);
131 if ($nohelp) return $relhtml;
132 return HTML($relhtml,
134 WikiLink(__("Help").":".__("SemanticRelations"), false,
135 HTML::em(_("Help")."/"._("SemanticRelations"))),
137 HTML::em(_("Find out how to add relations and attributes to pages.")));
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil