]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
format=xml for hypergraph.sf.net applet
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?php // -*-php-*-
2 rcs_id('$Id: LinkDatabase.php,v 1.2 2004-11-30 23:02:45 rurban Exp $');
3 /**
4  Copyright 2004 $ThePhpWikiProgrammingTeam
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 require_once('lib/PageList.php');
24 require_once('lib/WikiPluginCached.php');
25
26 /**
27  * To be used by WikiBrowser at http://touchgraph.sourceforge.net/
28  *   (only via a static text file by ?format=text) or the 
29  * Hypergraph applet should use format=xml
30  *   http://hypergraph.sourceforge.net/
31  *
32  * Currently the meta-head tags disturb the java browser a bit. 
33  * Maybe add theme without much header tags.
34  */
35 class WikiPlugin_LinkDatabase
36 extends WikiPluginCached
37 {
38     function getName () {
39         return _("LinkDatabase");
40     }
41     function getPluginType() {
42         return PLUGIN_CACHED_HTML;
43     }
44     function getDescription () {
45         return _("List all pages with all links in text-format for some Java Visualization tools");
46     }
47     function getVersion() {
48         return preg_replace("/[Revision: $]/", '',
49                             "\$Revision: 1.2 $");
50     }
51     function getExpire($dbi, $argarray, $request) {
52         return '+900'; // 15 minutes
53     }
54
55     function getDefaultArguments() {
56         return array_merge
57             (
58              PageList::supportedArgs(),
59              array(
60                    'format'        => 'text', // or 'html', 'xml'
61                    'noheader'      => false,
62                    'include_empty' => false,
63                    'exclude_from'  => false,
64                    'info'          => '',
65                    ));
66     }
67
68     function getHtml($dbi, $argarray, $request, $basepage) {
69         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
70     }
71     
72     function run($dbi, $argstr, $request, $basepage) {
73         $args = $this->getArgs($argstr, $request);
74         $caption = _("All pages with all links in this wiki (%d total):");
75         
76         if ( !empty($args['owner']) ) {
77             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],$args['sortby'],$args['limit']);
78             if ($args['owner'])
79                 $caption = fmt("List of pages owned by [%s] (%d total):", 
80                                WikiLink($args['owner'], 'if_known'),
81                                count($pages));
82         } elseif ( !empty($args['author']) ) {
83             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],$args['sortby'],$args['limit']);
84             if ($args['author'])
85                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
86                                WikiLink($args['author'], 'if_known'), 
87                                count($pages));
88         } elseif ( !empty($args['creator']) ) {
89             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],$args['sortby'],$args['limit']);
90             if ($args['creator'])
91                 $caption = fmt("List of pages created by [%s] (%d total):", 
92                                WikiLink($args['creator'], 'if_known'), 
93                                count($pages));
94         } else {
95             if (! $request->getArg('count'))  $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
96             else $args['count'] = $request->getArg('count');
97             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit'], $args['exclude_from']);
98         }
99         if ($args['format'] == 'html') {
100             $args['types']['links'] = 
101                 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
102             $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
103             if (!$args['noheader']) $pagelist->setCaption($caption);
104             return $pagelist;
105         } elseif ($args['format'] == 'text') {
106             $request->discardOutput();
107             $request->buffer_output(COMPRESS_OUTPUT);
108             if (!headers_sent())
109                 header("Content-Type: text/plain");
110             $request->checkValidators();
111             while ($page = $pages->next()) {
112                 echo $page->getName();
113                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
114                 while ($link = $links->next()) {
115                     echo " ", $link->getName();
116                 }
117                 echo "\n";
118             }
119             flush();
120             $request->finish();
121         } elseif ($args['format'] == 'xml') {
122             // for hypergraph.jar. best dump it to a sitemap.xml
123             global $WikiTheme, $charset;
124             $currpage = $request->getArg('pagename');
125             $request->discardOutput();
126             $request->buffer_output(false);
127             if (!headers_sent())
128                 header("Content-Type: text/xml");
129             $request->checkValidators();
130             echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n";
131             $dtd = SERVER_URL . $WikiTheme->_findData("GraphXML.dtd");
132             echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
133             echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
134             echo "<graph id=\"",WIKI_NAME,"\">\n";
135             echo '<style><line tag="node" class="main" colour="#ffffff"/><line tag="node" class="child" colour="blue"/><line tag="node" class="relation" colour="green"/></style>',"\n";
136             while ($page = $pages->next()) {
137                 $pageid = MangleXmlIdentifier($page->getName());
138                 $pagename = $page->getName();
139                 echo "<node name=\"$pageid\"";
140                 if ($pagename == $currpage) echo " class=\"main\"";
141                 echo "><label>$pagename</label>";
142                 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
143                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
144                 while ($link = $links->next()) {
145                     $edge = MangleXmlIdentifier($link->getName());
146                     echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
147                 }
148                 echo "\n";
149             }
150             echo "</graph>\n";
151             echo "</GraphXML>\n\n";
152             unset($GLOBALS['ErrorManager']->_postponed_errors);
153             $request->finish();
154         } else {
155             return $this->error(fmt("Unsupported format argument %s", $args['format']));
156         }
157     }
158 };
159
160 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
161     function _getValue($page, &$revision_handle) {
162         $out = HTML();
163         $links = $page->getPageLinks();
164         while ($link = $links->next()) {
165             $out->pushContent(" ", WikiLink($link));
166         }
167         return $out;
168     }
169 }
170
171 // $Log: not supported by cvs2svn $
172 // Revision 1.1  2004/11/30 21:02:16  rurban
173 // A simple plugin for WikiBrowser at http://touchgraph.sourceforge.net/
174 // List all pages with all links as text file (with some caching tricks).
175 //   format=html currently unstable.
176 //
177
178 // Local Variables:
179 // mode: php
180 // tab-width: 8
181 // c-basic-offset: 4
182 // c-hanging-comment-ender-p: nil
183 // indent-tabs-mode: nil
184 // End:
185 ?>