2 rcs_id('$Id: LinkDatabase.php,v 1.4 2004-12-06 19:50:05 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
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
23 require_once('lib/PageList.php');
24 require_once('lib/WikiPluginCached.php');
27 * - To be used by WikiBrowser at http://touchgraph.sourceforge.net/
28 * Only via a static text file yet. (format=text)
29 * - Or the Hypergraph applet (format=xml)
30 * http://hypergraph.sourceforge.net/
31 * So far also only for a static xml file, but I'll fix the applet and test
34 * TODO: Currently the meta-head tags disturb the touchgraph java browser a bit.
35 * Maybe add a theme without that much header tags.
37 class WikiPlugin_LinkDatabase
38 extends WikiPluginCached
41 return _("LinkDatabase");
43 function getPluginType() {
44 return PLUGIN_CACHED_HTML;
46 function getDescription () {
47 return _("List all pages with all links in various formats for some Java Visualization tools");
49 function getVersion() {
50 return preg_replace("/[Revision: $]/", '',
53 function getExpire($dbi, $argarray, $request) {
54 return '+900'; // 15 minutes
57 function getDefaultArguments() {
60 PageList::supportedArgs(),
62 'format' => 'text', // or 'html', 'xml'
64 'include_empty' => false,
65 'exclude_from' => false,
70 function getHtml($dbi, $argarray, $request, $basepage) {
71 $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
74 function run($dbi, $argstr, $request, $basepage) {
75 $args = $this->getArgs($argstr, $request);
76 $caption = _("All pages with all links in this wiki (%d total):");
78 if ( !empty($args['owner']) ) {
79 $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
80 $args['sortby'],$args['limit']);
82 $caption = fmt("List of pages owned by [%s] (%d total):",
83 WikiLink($args['owner'], 'if_known'),
85 } elseif ( !empty($args['author']) ) {
86 $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
87 $args['sortby'],$args['limit']);
89 $caption = fmt("List of pages last edited by [%s] (%d total):",
90 WikiLink($args['author'], 'if_known'),
92 } elseif ( !empty($args['creator']) ) {
93 $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
94 $args['sortby'],$args['limit']);
96 $caption = fmt("List of pages created by [%s] (%d total):",
97 WikiLink($args['creator'], 'if_known'),
100 if (! $request->getArg('count'))
101 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
102 else $args['count'] = $request->getArg('count');
103 $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
104 $args['limit'], $args['exclude_from']);
106 if ($args['format'] == 'html') {
107 $args['types']['links'] =
108 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
109 $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
110 if (!$args['noheader']) $pagelist->setCaption($caption);
112 } elseif ($args['format'] == 'text') {
113 $request->discardOutput();
114 $request->buffer_output(COMPRESS_OUTPUT);
116 header("Content-Type: text/plain");
117 $request->checkValidators();
118 while ($page = $pages->next()) {
119 echo $page->getName();
120 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
122 while ($link = $links->next()) {
123 echo " ", $link->getName();
129 } elseif ($args['format'] == 'xml') {
130 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
131 global $WikiTheme, $charset;
132 $currpage = $request->getArg('pagename');
133 $request->discardOutput();
134 $request->buffer_output(false);
136 header("Content-Type: text/xml");
137 $request->checkValidators();
138 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n";
139 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
140 $dtd = SERVER_URL . $WikiTheme->_findData("GraphXML.dtd");
141 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
142 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
143 echo "<graph id=\"",WIKI_NAME,"\">\n";
144 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";
145 while ($page = $pages->next()) {
146 $pageid = MangleXmlIdentifier($page->getName());
147 $pagename = $page->getName();
148 echo "<node name=\"$pageid\"";
149 if ($pagename == $currpage) echo " class=\"main\"";
150 echo "><label>$pagename</label>";
151 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
152 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
153 while ($link = $links->next()) {
154 $edge = MangleXmlIdentifier($link->getName());
155 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
160 echo "</GraphXML>\n\n";
161 unset($GLOBALS['ErrorManager']->_postponed_errors);
164 return $this->error(fmt("Unsupported format argument %s", $args['format']));
169 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
170 function _getValue($page, &$revision_handle) {
172 $links = $page->getPageLinks();
173 while ($link = $links->next()) {
174 $out->pushContent(" ", WikiLink($link));
180 // $Log: not supported by cvs2svn $
181 // Revision 1.3 2004/11/30 23:44:00 rurban
184 // Revision 1.2 2004/11/30 23:02:45 rurban
185 // format=xml for hypergraph.sf.net applet
187 // Revision 1.1 2004/11/30 21:02:16 rurban
188 // A simple plugin for WikiBrowser at http://touchgraph.sourceforge.net/
189 // List all pages with all links as text file (with some caching tricks).
190 // format=html currently unstable.
197 // c-hanging-comment-ender-p: nil
198 // indent-tabs-mode: nil