]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
Revert r7194
[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
79         $caption = _("All pages with all links in this wiki (%d total):");
80         
81         if ( !empty($args['owner']) ) {
82             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
83                                                $args['sortby'],$args['limit']);
84             if ($args['owner'])
85                 $caption = fmt("List of pages owned by [%s] (%d total):", 
86                                WikiLink($args['owner'], 'if_known'),
87                                count($pages));
88         } elseif ( !empty($args['author']) ) {
89             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
90                                                 $args['sortby'],$args['limit']);
91             if ($args['author'])
92                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
93                                WikiLink($args['author'], 'if_known'), 
94                                count($pages));
95         } elseif ( !empty($args['creator']) ) {
96             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
97                                                  $args['sortby'],$args['limit']);
98             if ($args['creator'])
99                 $caption = fmt("List of pages created by [%s] (%d total):", 
100                                WikiLink($args['creator'], 'if_known'), 
101                                count($pages));
102         } else {
103             if (! $request->getArg('count'))  
104                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
105             else 
106                 $args['count'] = $request->getArg('count');
107             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], 
108                                        $args['limit'], $args['exclude_from']);
109         }
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);
117             return $pagelist;
118         } elseif ($args['format'] == 'text') {
119             $request->discardOutput();
120             $request->buffer_output(false);
121             if (!headers_sent())
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'], 
127                                              $args['exclude']);
128                 while ($link = $links->next()) {
129                     echo " ", preg_replace("/ /","%20",$link->getName());
130                 }
131                 echo "\n";
132             }
133             flush();
134             if (empty($WikiTheme->DUMP_MODE))
135                 $request->finish();
136
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);
143             if (!headers_sent())
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";
164                 }
165                 echo "\n";
166             }
167             echo "</graph>\n";
168             echo "</GraphXML>\n";
169             if (empty($WikiTheme->DUMP_MODE)) {
170                 unset($GLOBALS['ErrorManager']->_postponed_errors);
171                 $request->finish();
172             }
173         } else {
174             return $this->error(fmt("Unsupported format argument %s", $args['format']));
175         }
176     }
177 };
178
179 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
180     function _getValue($page, &$revision_handle) {
181         $out = HTML();
182         $links = $page->getPageLinks();
183         while ($link = $links->next()) {
184             $out->pushContent(" ", WikiLink($link));
185         }
186         return $out;
187     }
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 ?>