]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
some comments
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?php // -*-php-*-
2 rcs_id('$Id: LinkDatabase.php,v 1.3 2004-11-30 23:44:00 rurban Exp $');
3 /**
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 require_once('lib/PageList.php');
24 require_once('lib/WikiPluginCached.php');
25
26 /**
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 
32  * the RPC2 interface.
33  *
34  * TODO: Currently the meta-head tags disturb the touchgraph java browser a bit. 
35  * Maybe add a theme without much header tags.
36  */
37 class WikiPlugin_LinkDatabase
38 extends WikiPluginCached
39 {
40     function getName () {
41         return _("LinkDatabase");
42     }
43     function getPluginType() {
44         return PLUGIN_CACHED_HTML;
45     }
46     function getDescription () {
47         return _("List all pages with all links in various formats for some Java Visualization tools");
48     }
49     function getVersion() {
50         return preg_replace("/[Revision: $]/", '',
51                             "\$Revision: 1.3 $");
52     }
53     function getExpire($dbi, $argarray, $request) {
54         return '+900'; // 15 minutes
55     }
56
57     function getDefaultArguments() {
58         return array_merge
59             (
60              PageList::supportedArgs(),
61              array(
62                    'format'        => 'text', // or 'html', 'xml'
63                    'noheader'      => false,
64                    'include_empty' => false,
65                    'exclude_from'  => false,
66                    'info'          => '',
67                    ));
68     }
69
70     function getHtml($dbi, $argarray, $request, $basepage) {
71         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
72     }
73     
74     function run($dbi, $argstr, $request, $basepage) {
75         $args = $this->getArgs($argstr, $request);
76         $caption = _("All pages with all links in this wiki (%d total):");
77         
78         if ( !empty($args['owner']) ) {
79             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
80                                                $args['sortby'],$args['limit']);
81             if ($args['owner'])
82                 $caption = fmt("List of pages owned by [%s] (%d total):", 
83                                WikiLink($args['owner'], 'if_known'),
84                                count($pages));
85         } elseif ( !empty($args['author']) ) {
86             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
87                                                 $args['sortby'],$args['limit']);
88             if ($args['author'])
89                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
90                                WikiLink($args['author'], 'if_known'), 
91                                count($pages));
92         } elseif ( !empty($args['creator']) ) {
93             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
94                                                  $args['sortby'],$args['limit']);
95             if ($args['creator'])
96                 $caption = fmt("List of pages created by [%s] (%d total):", 
97                                WikiLink($args['creator'], 'if_known'), 
98                                count($pages));
99         } else {
100             if (! $request->getArg('count'))  
101                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
102             else $args['count'] = $request->getArg('count');
103             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], 
104                                        $args['limit'], $args['exclude_from']);
105         }
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             if (!$args['noheader']) $pagelist->setCaption($caption);
111             return $pagelist;
112         } elseif ($args['format'] == 'text') {
113             $request->discardOutput();
114             $request->buffer_output(COMPRESS_OUTPUT);
115             if (!headers_sent())
116                 header("Content-Type: text/plain");
117             $request->checkValidators();
118             while ($page = $pages->next()) {
119                 echo $page->getName();
120                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], 
121                                              $args['exclude']);
122                 while ($link = $links->next()) {
123                     echo " ", $link->getName();
124                 }
125                 echo "\n";
126             }
127             flush();
128             $request->finish();
129         } elseif ($args['format'] == 'xml') {
130             // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
131             global $WikiTheme, $charset;
132             $currpage = $request->getArg('pagename');
133             $request->discardOutput();
134             $request->buffer_output(false);
135             if (!headers_sent())
136                 header("Content-Type: text/xml");
137             $request->checkValidators();
138             echo "<?xml version=\"1.0\" encoding=\"$charset\"?>\n";
139             // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
140             $dtd = SERVER_URL . $WikiTheme->_findData("GraphXML.dtd");
141             echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
142             echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
143             echo "<graph id=\"",WIKI_NAME,"\">\n";
144             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";
145             while ($page = $pages->next()) {
146                 $pageid = MangleXmlIdentifier($page->getName());
147                 $pagename = $page->getName();
148                 echo "<node name=\"$pageid\"";
149                 if ($pagename == $currpage) echo " class=\"main\"";
150                 echo "><label>$pagename</label>";
151                 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
152                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
153                 while ($link = $links->next()) {
154                     $edge = MangleXmlIdentifier($link->getName());
155                     echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
156                 }
157                 echo "\n";
158             }
159             echo "</graph>\n";
160             echo "</GraphXML>\n\n";
161             unset($GLOBALS['ErrorManager']->_postponed_errors);
162             $request->finish();
163         } else {
164             return $this->error(fmt("Unsupported format argument %s", $args['format']));
165         }
166     }
167 };
168
169 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
170     function _getValue($page, &$revision_handle) {
171         $out = HTML();
172         $links = $page->getPageLinks();
173         while ($link = $links->next()) {
174             $out->pushContent(" ", WikiLink($link));
175         }
176         return $out;
177     }
178 }
179
180 // $Log: not supported by cvs2svn $
181 // Revision 1.2  2004/11/30 23:02:45  rurban
182 // format=xml for hypergraph.sf.net applet
183 //
184 // Revision 1.1  2004/11/30 21:02:16  rurban
185 // A simple plugin for WikiBrowser at http://touchgraph.sourceforge.net/
186 // List all pages with all links as text file (with some caching tricks).
187 //   format=html currently unstable.
188 //
189
190 // Local Variables:
191 // mode: php
192 // tab-width: 8
193 // c-basic-offset: 4
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil
196 // End:
197 ?>