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
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.
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 getVersion() {
51 return preg_replace("/[Revision: $]/", '',
54 function getExpire($dbi, $argarray, $request) {
55 return '+900'; // 15 minutes
58 function getDefaultArguments() {
61 PageList::supportedArgs(),
63 'format' => 'html', // 'html', 'text', 'xml'
65 'include_empty' => false,
66 'exclude_from' => false,
71 function getHtml($dbi, $argarray, $request, $basepage) {
72 $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
75 function run($dbi, $argstr, $request, $basepage) {
77 $args = $this->getArgs($argstr, $request);
79 if (!empty($args['limit']) && !is_numeric($args['limit'])) {
80 return $this->error(_("Illegal 'limit' argument: must be numeric"));
83 $caption = _("All pages with all links in this wiki (%d total):");
85 if ( !empty($args['owner']) ) {
86 $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
87 $args['sortby'],$args['limit']);
89 $caption = fmt("List of pages owned by [%s] (%d total):",
90 WikiLink($args['owner'], 'if_known'),
92 } elseif ( !empty($args['author']) ) {
93 $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
94 $args['sortby'],$args['limit']);
96 $caption = fmt("List of pages last edited by [%s] (%d total):",
97 WikiLink($args['author'], 'if_known'),
99 } elseif ( !empty($args['creator']) ) {
100 $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
101 $args['sortby'],$args['limit']);
102 if ($args['creator'])
103 $caption = fmt("List of pages created by [%s] (%d total):",
104 WikiLink($args['creator'], 'if_known'),
107 if (! $request->getArg('count'))
108 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
110 $args['count'] = $request->getArg('count');
111 $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
112 $args['limit'], $args['exclude_from']);
114 if ($args['format'] == 'html') {
115 $args['types']['links'] =
116 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
117 $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
118 //$pagelist->_addColumn("links");
119 if (!$args['noheader']) $pagelist->setCaption($caption);
120 $pagelist->addPages($pages);
122 } elseif ($args['format'] == 'text') {
123 $request->discardOutput();
124 $request->buffer_output(false);
126 header("Content-Type: text/plain");
127 $request->checkValidators();
128 while ($page = $pages->next()) {
129 echo preg_replace("/ /","%20",$page->getName());
130 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
132 while ($link = $links->next()) {
133 echo " ", preg_replace("/ /","%20",$link->getName());
138 if (empty($WikiTheme->DUMP_MODE))
141 } elseif ($args['format'] == 'xml') {
142 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
143 global $WikiTheme, $charset;
144 $currpage = $request->getArg('pagename');
145 $request->discardOutput();
146 $request->buffer_output(false);
148 header("Content-Type: text/xml");
149 $request->checkValidators();
150 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>";
151 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
152 $dtd = $WikiTheme->_findData("GraphXML.dtd");
153 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
154 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
155 echo "<graph id=\"",MangleXmlIdentifier(WIKI_NAME),"\">\n";
156 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";
157 while ($page = $pages->next()) {
158 $pageid = MangleXmlIdentifier($page->getName());
159 $pagename = $page->getName();
160 echo "<node name=\"$pageid\"";
161 if ($pagename == $currpage) echo " class=\"main\"";
162 echo "><label>$pagename</label>";
163 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
164 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
165 while ($link = $links->next()) {
166 $edge = MangleXmlIdentifier($link->getName());
167 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
172 echo "</GraphXML>\n";
173 if (empty($WikiTheme->DUMP_MODE)) {
174 unset($GLOBALS['ErrorManager']->_postponed_errors);
178 return $this->error(fmt("Unsupported format argument %s", $args['format']));
183 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
184 function _getValue($page, &$revision_handle) {
186 $links = $page->getPageLinks();
187 while ($link = $links->next()) {
188 $out->pushContent(" ", WikiLink($link));
198 // c-hanging-comment-ender-p: nil
199 // indent-tabs-mode: nil