]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 2004,2007 $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 that much header tags.
36  * DONE: Convert " " to %20
37  */
38 class WikiPlugin_LinkDatabase
39 extends WikiPluginCached
40 {
41     function getName () {
42         return _("LinkDatabase");
43     }
44     function getPluginType() {
45         return PLUGIN_CACHED_HTML;
46     }
47     function getDescription () {
48         return _("List all pages with all links in various formats for some Java Visualization tools");
49     }
50     function getVersion() {
51         return preg_replace("/[Revision: $]/", '',
52                             "\$Revision$");
53     }
54     function getExpire($dbi, $argarray, $request) {
55         return '+900'; // 15 minutes
56     }
57
58     function getDefaultArguments() {
59         return array_merge
60             (
61              PageList::supportedArgs(),
62              array(
63                    'format'        => 'html', // 'html', 'text', 'xml'
64                    'noheader'      => false,
65                    'include_empty' => false,
66                    'exclude_from'  => false,
67                    'info'          => '',
68                    ));
69     }
70
71     function getHtml($dbi, $argarray, $request, $basepage) {
72         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
73     }
74     
75     function run($dbi, $argstr, $request, $basepage) {
76         global $WikiTheme;
77         $args = $this->getArgs($argstr, $request);
78         $caption = _("All pages with all links in this wiki (%d total):");
79         
80         if ( !empty($args['owner']) ) {
81             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
82                                                $args['sortby'],$args['limit']);
83             if ($args['owner'])
84                 $caption = fmt("List of pages owned by [%s] (%d total):", 
85                                WikiLink($args['owner'], 'if_known'),
86                                count($pages));
87         } elseif ( !empty($args['author']) ) {
88             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
89                                                 $args['sortby'],$args['limit']);
90             if ($args['author'])
91                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
92                                WikiLink($args['author'], 'if_known'), 
93                                count($pages));
94         } elseif ( !empty($args['creator']) ) {
95             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
96                                                  $args['sortby'],$args['limit']);
97             if ($args['creator'])
98                 $caption = fmt("List of pages created by [%s] (%d total):", 
99                                WikiLink($args['creator'], 'if_known'), 
100                                count($pages));
101         } else {
102             if (! $request->getArg('count'))  
103                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
104             else 
105                 $args['count'] = $request->getArg('count');
106             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], 
107                                        $args['limit'], $args['exclude_from']);
108         }
109         if ($args['format'] == 'html') {
110             $args['types']['links'] = 
111                 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
112             $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
113             //$pagelist->_addColumn("links");
114             if (!$args['noheader']) $pagelist->setCaption($caption);
115             $pagelist->addPages($pages);
116             return $pagelist;
117         } elseif ($args['format'] == 'text') {
118             $request->discardOutput();
119             $request->buffer_output(false);
120             if (!headers_sent())
121                 header("Content-Type: text/plain");
122             $request->checkValidators();
123             while ($page = $pages->next()) {
124                 echo preg_replace("/ /","%20",$page->getName());
125                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], 
126                                              $args['exclude']);
127                 while ($link = $links->next()) {
128                     echo " ", preg_replace("/ /","%20",$link->getName());
129                 }
130                 echo "\n";
131             }
132             flush();
133             if (empty($WikiTheme->DUMP_MODE))
134                 $request->finish();
135
136         } elseif ($args['format'] == 'xml') {
137             // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
138             global $WikiTheme, $charset;
139             $currpage = $request->getArg('pagename');
140             $request->discardOutput();
141             $request->buffer_output(false);
142             if (!headers_sent())
143                 header("Content-Type: text/xml");
144             $request->checkValidators();
145             echo "<?xml version=\"1.0\" encoding=\"$charset\"?>";
146             // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
147             $dtd = $WikiTheme->_findData("GraphXML.dtd");
148             echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
149             echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
150             echo "<graph id=\"",MangleXmlIdentifier(WIKI_NAME),"\">\n";
151             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";
152             while ($page = $pages->next()) {
153                 $pageid = MangleXmlIdentifier($page->getName());
154                 $pagename = $page->getName();
155                 echo "<node name=\"$pageid\"";
156                 if ($pagename == $currpage) echo " class=\"main\"";
157                 echo "><label>$pagename</label>";
158                 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
159                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
160                 while ($link = $links->next()) {
161                     $edge = MangleXmlIdentifier($link->getName());
162                     echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
163                 }
164                 echo "\n";
165             }
166             echo "</graph>\n";
167             echo "</GraphXML>\n";
168             if (empty($WikiTheme->DUMP_MODE)) {
169                 unset($GLOBALS['ErrorManager']->_postponed_errors);
170                 $request->finish();
171             }
172         } else {
173             return $this->error(fmt("Unsupported format argument %s", $args['format']));
174         }
175     }
176 };
177
178 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
179     function _getValue($page, &$revision_handle) {
180         $out = HTML();
181         $links = $page->getPageLinks();
182         while ($link = $links->next()) {
183             $out->pushContent(" ", WikiLink($link));
184         }
185         return $out;
186     }
187 }
188
189 // $Log: not supported by cvs2svn $
190 // Revision 1.7  2004/12/26 17:17:25  rurban
191 // announce dumps - mult.requests to avoid request::finish, e.g. LinkDatabase, PdfOut, ...
192 //
193 // Revision 1.6  2004/12/22 18:48:10  rurban
194 // default format=html for unit-tests and DumpHtml/Zip breakage
195 //
196 // Revision 1.5  2004/12/17 16:39:03  rurban
197 // minor reformatting
198 //
199 // Revision 1.4  2004/12/06 19:50:05  rurban
200 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
201 // renamed delete_page to purge_page.
202 // enable action=edit&version=-1 to force creation of a new version.
203 // added BABYCART_PATH config
204 // fixed magiqc in adodb.inc.php
205 // and some more docs
206 //
207 // Revision 1.3  2004/11/30 23:44:00  rurban
208 // some comments
209 //
210 // Revision 1.2  2004/11/30 23:02:45  rurban
211 // format=xml for hypergraph.sf.net applet
212 //
213 // Revision 1.1  2004/11/30 21:02:16  rurban
214 // A simple plugin for WikiBrowser at http://touchgraph.sourceforge.net/
215 // List all pages with all links as text file (with some caching tricks).
216 //   format=html currently unstable.
217 //
218
219 // Local Variables:
220 // mode: php
221 // tab-width: 8
222 // c-basic-offset: 4
223 // c-hanging-comment-ender-p: nil
224 // indent-tabs-mode: nil
225 // End:
226 ?>