4 * Copyright 2004,2007 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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.
36 * DONE: Convert " " to %20
38 class WikiPlugin_LinkDatabase
39 extends WikiPluginCached
43 return _("LinkDatabase");
46 function getPluginType()
48 return PLUGIN_CACHED_HTML;
51 function getDescription()
53 return _("List all pages with all links in various formats for some Java Visualization tools.");
56 function getExpire($dbi, $argarray, $request)
58 return '+900'; // 15 minutes
61 function getDefaultArguments()
65 PageList::supportedArgs(),
67 'format' => 'html', // 'html', 'text', 'xml'
69 'include_empty' => false,
70 'exclude_from' => false,
75 function getHtml($dbi, $argarray, $request, $basepage)
77 $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
80 function run($dbi, $argstr, $request, $basepage)
83 $args = $this->getArgs($argstr, $request);
85 $caption = _("All pages with all links in this wiki (%d total):");
87 if (!empty($args['owner'])) {
88 $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
89 $args['sortby'], $args['limit']);
91 $caption = fmt("List of pages owned by [%s] (%d total):",
92 WikiLink($args['owner'], 'if_known'),
94 } elseif (!empty($args['author'])) {
95 $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
96 $args['sortby'], $args['limit']);
98 $caption = fmt("List of pages last edited by [%s] (%d total):",
99 WikiLink($args['author'], 'if_known'),
101 } elseif (!empty($args['creator'])) {
102 $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
103 $args['sortby'], $args['limit']);
104 if ($args['creator'])
105 $caption = fmt("List of pages created by [%s] (%d total):",
106 WikiLink($args['creator'], 'if_known'),
109 if (!$request->getArg('count'))
110 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
112 $args['count'] = $request->getArg('count');
113 $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
114 $args['limit'], $args['exclude_from']);
116 if ($args['format'] == 'html') {
117 $args['types']['links'] =
118 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
119 $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
120 //$pagelist->_addColumn("links");
121 if (!$args['noheader']) $pagelist->setCaption($caption);
122 $pagelist->addPages($pages);
124 } elseif ($args['format'] == 'text') {
125 $request->discardOutput();
126 $request->buffer_output(false);
128 header("Content-Type: text/plain");
129 $request->checkValidators();
130 while ($page = $pages->next()) {
131 echo preg_replace("/ /", "%20", $page->getName());
132 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
134 while ($link = $links->next()) {
135 echo " ", preg_replace("/ /", "%20", $link->getName());
140 if (empty($WikiTheme->DUMP_MODE))
143 } elseif ($args['format'] == 'xml') {
144 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
146 $currpage = $request->getArg('pagename');
147 $request->discardOutput();
148 $request->buffer_output(false);
150 header("Content-Type: text/xml");
151 $request->checkValidators();
152 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
153 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
154 $dtd = $WikiTheme->_findData("GraphXML.dtd");
155 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
156 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
157 echo "<graph id=\"", MangleXmlIdentifier(WIKI_NAME), "\">\n";
159 echo '<line tag="node" class="main" colour="#ffffff"/>';
160 echo '<line tag="node" class="child" colour="blue"/>';
161 echo '<line tag="node" class="relation" colour="green"/>';
163 while ($page = $pages->next()) {
164 $pageid = MangleXmlIdentifier($page->getName());
165 $pagename = $page->getName();
166 echo "<node name=\"$pageid\"";
167 if ($pagename == $currpage) echo " class=\"main\"";
168 echo "><label>$pagename</label>";
169 echo "<dataref><ref xlink:href=\"", WikiURL($pagename, '', true), "\"/></dataref></node>\n";
170 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
171 while ($link = $links->next()) {
172 $edge = MangleXmlIdentifier($link->getName());
173 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
178 echo "</GraphXML>\n";
179 if (empty($WikiTheme->DUMP_MODE)) {
180 unset($GLOBALS['ErrorManager']->_postponed_errors);
184 return $this->error(fmt("Unsupported format argument %s", $args['format']));
189 class _PageList_Column_LinkDatabase_links extends _PageList_Column
191 function _getValue($page, &$revision_handle)
194 $links = $page->getPageLinks();
195 while ($link = $links->next()) {
196 $out->pushContent(" ", WikiLink($link));
206 // c-hanging-comment-ender-p: nil
207 // indent-tabs-mode: nil