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 $caption = _("All pages with all links in this wiki (%d total):");
81 if ( !empty($args['owner']) ) {
82 $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
83 $args['sortby'],$args['limit']);
85 $caption = fmt("List of pages owned by [%s] (%d total):",
86 WikiLink($args['owner'], 'if_known'),
88 } elseif ( !empty($args['author']) ) {
89 $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
90 $args['sortby'],$args['limit']);
92 $caption = fmt("List of pages last edited by [%s] (%d total):",
93 WikiLink($args['author'], 'if_known'),
95 } elseif ( !empty($args['creator']) ) {
96 $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
97 $args['sortby'],$args['limit']);
99 $caption = fmt("List of pages created by [%s] (%d total):",
100 WikiLink($args['creator'], 'if_known'),
103 if (! $request->getArg('count'))
104 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
106 $args['count'] = $request->getArg('count');
107 $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
108 $args['limit'], $args['exclude_from']);
110 if ($args['format'] == 'html') {
111 $args['types']['links'] =
112 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
113 $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
114 //$pagelist->_addColumn("links");
115 if (!$args['noheader']) $pagelist->setCaption($caption);
116 $pagelist->addPages($pages);
118 } elseif ($args['format'] == 'text') {
119 $request->discardOutput();
120 $request->buffer_output(false);
122 header("Content-Type: text/plain");
123 $request->checkValidators();
124 while ($page = $pages->next()) {
125 echo preg_replace("/ /","%20",$page->getName());
126 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
128 while ($link = $links->next()) {
129 echo " ", preg_replace("/ /","%20",$link->getName());
134 if (empty($WikiTheme->DUMP_MODE))
137 } elseif ($args['format'] == 'xml') {
138 // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
139 global $WikiTheme, $charset;
140 $currpage = $request->getArg('pagename');
141 $request->discardOutput();
142 $request->buffer_output(false);
144 header("Content-Type: text/xml");
145 $request->checkValidators();
146 echo "<?xml version=\"1.0\" encoding=\"$charset\"?>";
147 // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
148 $dtd = $WikiTheme->_findData("GraphXML.dtd");
149 echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
150 echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
151 echo "<graph id=\"",MangleXmlIdentifier(WIKI_NAME),"\">\n";
152 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";
153 while ($page = $pages->next()) {
154 $pageid = MangleXmlIdentifier($page->getName());
155 $pagename = $page->getName();
156 echo "<node name=\"$pageid\"";
157 if ($pagename == $currpage) echo " class=\"main\"";
158 echo "><label>$pagename</label>";
159 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
160 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
161 while ($link = $links->next()) {
162 $edge = MangleXmlIdentifier($link->getName());
163 echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
168 echo "</GraphXML>\n";
169 if (empty($WikiTheme->DUMP_MODE)) {
170 unset($GLOBALS['ErrorManager']->_postponed_errors);
174 return $this->error(fmt("Unsupported format argument %s", $args['format']));
179 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
180 function _getValue($page, &$revision_handle) {
182 $links = $page->getPageLinks();
183 while ($link = $links->next()) {
184 $out->pushContent(" ", WikiLink($link));
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil