]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?php // -*-php-*-
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 getExpire($dbi, $argarray, $request) {
51         return '+900'; // 15 minutes
52     }
53
54     function getDefaultArguments() {
55         return array_merge
56             (
57              PageList::supportedArgs(),
58              array(
59                    'format'        => 'html', // 'html', 'text', 'xml'
60                    'noheader'      => false,
61                    'include_empty' => false,
62                    'exclude_from'  => false,
63                    'info'          => '',
64                    ));
65     }
66
67     function getHtml($dbi, $argarray, $request, $basepage) {
68         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
69     }
70
71     function run($dbi, $argstr, $request, $basepage) {
72         global $WikiTheme;
73         $args = $this->getArgs($argstr, $request);
74
75         $caption = _("All pages with all links in this wiki (%d total):");
76
77         if ( !empty($args['owner']) ) {
78             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],
79                                                $args['sortby'],$args['limit']);
80             if ($args['owner'])
81                 $caption = fmt("List of pages owned by [%s] (%d total):",
82                                WikiLink($args['owner'], 'if_known'),
83                                count($pages));
84         } elseif ( !empty($args['author']) ) {
85             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],
86                                                 $args['sortby'],$args['limit']);
87             if ($args['author'])
88                 $caption = fmt("List of pages last edited by [%s] (%d total):",
89                                WikiLink($args['author'], 'if_known'),
90                                count($pages));
91         } elseif ( !empty($args['creator']) ) {
92             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],
93                                                  $args['sortby'],$args['limit']);
94             if ($args['creator'])
95                 $caption = fmt("List of pages created by [%s] (%d total):",
96                                WikiLink($args['creator'], 'if_known'),
97                                count($pages));
98         } else {
99             if (! $request->getArg('count'))
100                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
101             else
102                 $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             //$pagelist->_addColumn("links");
111             if (!$args['noheader']) $pagelist->setCaption($caption);
112             $pagelist->addPages($pages);
113             return $pagelist;
114         } elseif ($args['format'] == 'text') {
115             $request->discardOutput();
116             $request->buffer_output(false);
117             if (!headers_sent())
118                 header("Content-Type: text/plain");
119             $request->checkValidators();
120             while ($page = $pages->next()) {
121                 echo preg_replace("/ /","%20",$page->getName());
122                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
123                                              $args['exclude']);
124                 while ($link = $links->next()) {
125                     echo " ", preg_replace("/ /","%20",$link->getName());
126                 }
127                 echo "\n";
128             }
129             flush();
130             if (empty($WikiTheme->DUMP_MODE))
131                 $request->finish();
132
133         } elseif ($args['format'] == 'xml') {
134             // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
135             global $WikiTheme, $charset;
136             $currpage = $request->getArg('pagename');
137             $request->discardOutput();
138             $request->buffer_output(false);
139             if (!headers_sent())
140                 header("Content-Type: text/xml");
141             $request->checkValidators();
142             echo "<?xml version=\"1.0\" encoding=\"$charset\"?>";
143             // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
144             $dtd = $WikiTheme->_findData("GraphXML.dtd");
145             echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
146             echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
147             echo "<graph id=\"",MangleXmlIdentifier(WIKI_NAME),"\">\n";
148             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";
149             while ($page = $pages->next()) {
150                     $pageid = MangleXmlIdentifier($page->getName());
151                     $pagename = $page->getName();
152                 echo "<node name=\"$pageid\"";
153                 if ($pagename == $currpage) echo " class=\"main\"";
154                 echo "><label>$pagename</label>";
155                 echo "<dataref><ref xlink:href=\"",WikiURL($pagename,'',true),"\"/></dataref></node>\n";
156                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
157                 while ($link = $links->next()) {
158                     $edge = MangleXmlIdentifier($link->getName());
159                     echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
160                 }
161                 echo "\n";
162             }
163             echo "</graph>\n";
164             echo "</GraphXML>\n";
165             if (empty($WikiTheme->DUMP_MODE)) {
166                 unset($GLOBALS['ErrorManager']->_postponed_errors);
167                 $request->finish();
168             }
169         } else {
170             return $this->error(fmt("Unsupported format argument %s", $args['format']));
171         }
172     }
173 };
174
175 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
176     function _getValue($page, &$revision_handle) {
177         $out = HTML();
178         $links = $page->getPageLinks();
179         while ($link = $links->next()) {
180             $out->pushContent(" ", WikiLink($link));
181         }
182         return $out;
183     }
184 }
185
186 // Local Variables:
187 // mode: php
188 // tab-width: 8
189 // c-basic-offset: 4
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil
192 // End: