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
41 function getPluginType()
43 return PLUGIN_CACHED_HTML;
46 function getDescription()
48 return _("List all pages with all links in various formats for some Java Visualization tools.");
51 function getExpire($dbi, $argarray, $request)
53 return '+900'; // 15 minutes
56 function getDefaultArguments()
60 PageList::supportedArgs(),
62 'format' => 'html', // 'html', 'text', 'xml'
64 'include_empty' => false,
65 'exclude_from' => false,
70 function getHtml($dbi, $argarray, $request, $basepage)
72 $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
75 function run($dbi, $argstr, $request, $basepage)
78 $args = $this->getArgs($argstr, $request);
80 $caption = _("All pages with all links in this wiki (%d total):");
82 if (!empty($args['owner'])) {
83 $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
84 $args['sortby'], $args['limit']);
86 $caption = fmt("List of pages owned by [%s] (%d total):",
87 WikiLink($args['owner'], 'if_known'),
89 } elseif (!empty($args['author'])) {
90 $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
91 $args['sortby'], $args['limit']);
93 $caption = fmt("List of pages last edited by [%s] (%d total):",
94 WikiLink($args['author'], 'if_known'),
96 } elseif (!empty($args['creator'])) {
97 $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
98 $args['sortby'], $args['limit']);
100 $caption = fmt("List of pages created by [%s] (%d total):",
101 WikiLink($args['creator'], 'if_known'),
104 if (!$request->getArg('count'))
105 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
107 $args['count'] = $request->getArg('count');
108 $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
109 $args['limit'], $args['exclude_from']);
111 if ($args['format'] == 'html') {
112 $args['types']['links'] =
113 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
114 $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
115 //$pagelist->_addColumn("links");
116 if (!$args['noheader']) $pagelist->setCaption($caption);
117 $pagelist->addPages($pages);
119 } elseif ($args['format'] == 'text') {
120 $request->discardOutput();
121 $request->buffer_output(false);
123 header("Content-Type: text/plain");
124 $request->checkValidators();
125 while ($page = $pages->next()) {
126 echo preg_replace("/ /", "%20", $page->getName());
127 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
129 while ($link = $links->next()) {
130 echo " ", preg_replace("/ /", "%20", $link->getName());
135 if (empty($WikiTheme->DUMP_MODE))
138 } elseif ($args['format'] == 'xml') {
139 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
141 $currpage = $request->getArg('pagename');
142 $request->discardOutput();
143 $request->buffer_output(false);
145 header("Content-Type: text/xml");
146 $request->checkValidators();
147 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
148 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
149 $dtd = $WikiTheme->_findData("GraphXML.dtd");
150 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
151 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
152 echo "<graph id=\"", MangleXmlIdentifier(WIKI_NAME), "\">\n";
154 echo '<line tag="node" class="main" colour="#ffffff"/>';
155 echo '<line tag="node" class="child" colour="blue"/>';
156 echo '<line tag="node" class="relation" colour="green"/>';
158 while ($page = $pages->next()) {
159 $pageid = MangleXmlIdentifier($page->getName());
160 $pagename = $page->getName();
161 echo "<node name=\"$pageid\"";
162 if ($pagename == $currpage) echo " class=\"main\"";
163 echo "><label>$pagename</label>";
164 echo "<dataref><ref xlink:href=\"", WikiURL($pagename, '', true), "\"/></dataref></node>\n";
165 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
166 while ($link = $links->next()) {
167 $edge = MangleXmlIdentifier($link->getName());
168 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
173 echo "</GraphXML>\n";
174 if (empty($WikiTheme->DUMP_MODE)) {
175 unset($GLOBALS['ErrorManager']->_postponed_errors);
179 return $this->error(fmt("Unsupported format argument %s", $args['format']));
185 class _PageList_Column_LinkDatabase_links extends _PageList_Column
187 function _getValue($page, &$revision_handle)
190 $links = $page->getPageLinks();
191 while ($link = $links->next()) {
192 $out->pushContent(" ", WikiLink($link));
202 // c-hanging-comment-ender-p: nil
203 // indent-tabs-mode: nil