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
42 return _("LinkDatabase");
44 function getPluginType() {
45 return PLUGIN_CACHED_HTML;
47 function getDescription () {
48 return _("List all pages with all links in various formats for some Java Visualization tools");
50 function getExpire($dbi, $argarray, $request) {
51 return '+900'; // 15 minutes
54 function getDefaultArguments() {
57 PageList::supportedArgs(),
59 'format' => 'html', // 'html', 'text', 'xml'
61 'include_empty' => false,
62 'exclude_from' => false,
67 function getHtml($dbi, $argarray, $request, $basepage) {
68 $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
71 function run($dbi, $argstr, $request, $basepage) {
73 $args = $this->getArgs($argstr, $request);
75 $caption = _("All pages with all links in this wiki (%d total):");
77 if ( !empty($args['owner']) ) {
78 $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
79 $args['sortby'],$args['limit']);
81 $caption = fmt("List of pages owned by [%s] (%d total):",
82 WikiLink($args['owner'], 'if_known'),
84 } elseif ( !empty($args['author']) ) {
85 $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
86 $args['sortby'],$args['limit']);
88 $caption = fmt("List of pages last edited by [%s] (%d total):",
89 WikiLink($args['author'], 'if_known'),
91 } elseif ( !empty($args['creator']) ) {
92 $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
93 $args['sortby'],$args['limit']);
95 $caption = fmt("List of pages created by [%s] (%d total):",
96 WikiLink($args['creator'], 'if_known'),
99 if (! $request->getArg('count'))
100 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
102 $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 //$pagelist->_addColumn("links");
111 if (!$args['noheader']) $pagelist->setCaption($caption);
112 $pagelist->addPages($pages);
114 } elseif ($args['format'] == 'text') {
115 $request->discardOutput();
116 $request->buffer_output(false);
118 header("Content-Type: text/plain");
119 $request->checkValidators();
120 while ($page = $pages->next()) {
121 echo preg_replace("/ /","%20",$page->getName());
122 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
124 while ($link = $links->next()) {
125 echo " ", preg_replace("/ /","%20",$link->getName());
130 if (empty($WikiTheme->DUMP_MODE))
133 } elseif ($args['format'] == 'xml') {
134 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
135 global $WikiTheme, $charset;
136 $currpage = $request->getArg('pagename');
137 $request->discardOutput();
138 $request->buffer_output(false);
140 header("Content-Type: text/xml");
141 $request->checkValidators();
142 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>";
143 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
144 $dtd = $WikiTheme->_findData("GraphXML.dtd");
145 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
146 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
147 echo "<graph id=\"",MangleXmlIdentifier(WIKI_NAME),"\">\n";
148 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\n";
149 while ($page = $pages->next()) {
150 $pageid = MangleXmlIdentifier($page->getName());
151 $pagename = $page->getName();
152 echo "<node name=\"$pageid\"";
153 if ($pagename == $currpage) echo " class=\"main\"";
154 echo "><label>$pagename</label>";
155 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
156 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
157 while ($link = $links->next()) {
158 $edge = MangleXmlIdentifier($link->getName());
159 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
164 echo "</GraphXML>\n";
165 if (empty($WikiTheme->DUMP_MODE)) {
166 unset($GLOBALS['ErrorManager']->_postponed_errors);
170 return $this->error(fmt("Unsupported format argument %s", $args['format']));
175 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
176 function _getValue($page, &$revision_handle) {
178 $links = $page->getPageLinks();
179 while ($link = $links->next()) {
180 $out->pushContent(" ", WikiLink($link));
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil