]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
Add missing return
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?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     {
43         return _("LinkDatabase");
44     }
45
46     function getPluginType()
47     {
48         return PLUGIN_CACHED_HTML;
49     }
50
51     function getDescription()
52     {
53         return _("List all pages with all links in various formats for some Java Visualization tools.");
54     }
55
56     function getExpire($dbi, $argarray, $request)
57     {
58         return '+900'; // 15 minutes
59     }
60
61     function getDefaultArguments()
62     {
63         return array_merge
64         (
65             PageList::supportedArgs(),
66             array(
67                 'format' => 'html', // 'html', 'text', 'xml'
68                 'noheader' => false,
69                 'include_empty' => false,
70                 'exclude_from' => false,
71                 'info' => '',
72             ));
73     }
74
75     function getHtml($dbi, $argarray, $request, $basepage)
76     {
77         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
78     }
79
80     function run($dbi, $argstr, $request, $basepage)
81     {
82         global $WikiTheme;
83         $args = $this->getArgs($argstr, $request);
84
85         $caption = _("All pages with all links in this wiki (%d total):");
86
87         if (!empty($args['owner'])) {
88             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
89                 $args['sortby'], $args['limit']);
90             if ($args['owner'])
91                 $caption = fmt("List of pages owned by [%s] (%d total):",
92                     WikiLink($args['owner'], 'if_known'),
93                     count($pages));
94         } elseif (!empty($args['author'])) {
95             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
96                 $args['sortby'], $args['limit']);
97             if ($args['author'])
98                 $caption = fmt("List of pages last edited by [%s] (%d total):",
99                     WikiLink($args['author'], 'if_known'),
100                     count($pages));
101         } elseif (!empty($args['creator'])) {
102             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
103                 $args['sortby'], $args['limit']);
104             if ($args['creator'])
105                 $caption = fmt("List of pages created by [%s] (%d total):",
106                     WikiLink($args['creator'], 'if_known'),
107                     count($pages));
108         } else {
109             if (!$request->getArg('count'))
110                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
111             else
112                 $args['count'] = $request->getArg('count');
113             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'],
114                 $args['limit'], $args['exclude_from']);
115         }
116         if ($args['format'] == 'html') {
117             $args['types']['links'] =
118                 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
119             $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
120             //$pagelist->_addColumn("links");
121             if (!$args['noheader']) $pagelist->setCaption($caption);
122             $pagelist->addPages($pages);
123             return $pagelist;
124         } elseif ($args['format'] == 'text') {
125             $request->discardOutput();
126             $request->buffer_output(false);
127             if (!headers_sent())
128                 header("Content-Type: text/plain");
129             $request->checkValidators();
130             while ($page = $pages->next()) {
131                 echo preg_replace("/ /", "%20", $page->getName());
132                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'],
133                     $args['exclude']);
134                 while ($link = $links->next()) {
135                     echo " ", preg_replace("/ /", "%20", $link->getName());
136                 }
137                 echo "\n";
138             }
139             flush();
140             if (empty($WikiTheme->DUMP_MODE))
141                 $request->finish();
142
143         } elseif ($args['format'] == 'xml') {
144             // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
145             global $WikiTheme;
146             $currpage = $request->getArg('pagename');
147             $request->discardOutput();
148             $request->buffer_output(false);
149             if (!headers_sent())
150                 header("Content-Type: text/xml");
151             $request->checkValidators();
152             echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
153             // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
154             $dtd = $WikiTheme->_findData("GraphXML.dtd");
155             echo "<!DOCTYPE GraphXML SYSTEM \"$dtd\">\n";
156             echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
157             echo "<graph id=\"", MangleXmlIdentifier(WIKI_NAME), "\">\n";
158             echo '<style>';
159             echo '<line tag="node" class="main" colour="#ffffff"/>';
160             echo '<line tag="node" class="child" colour="blue"/>';
161             echo '<line tag="node" class="relation" colour="green"/>';
162             echo "</style>\n\n";
163             while ($page = $pages->next()) {
164                 $pageid = MangleXmlIdentifier($page->getName());
165                 $pagename = $page->getName();
166                 echo "<node name=\"$pageid\"";
167                 if ($pagename == $currpage) echo " class=\"main\"";
168                 echo "><label>$pagename</label>";
169                 echo "<dataref><ref xlink:href=\"", WikiURL($pagename, '', true), "\"/></dataref></node>\n";
170                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
171                 while ($link = $links->next()) {
172                     $edge = MangleXmlIdentifier($link->getName());
173                     echo "<edge source=\"$pageid\" target=\"$edge\" />\n";
174                 }
175                 echo "\n";
176             }
177             echo "</graph>\n";
178             echo "</GraphXML>\n";
179             if (empty($WikiTheme->DUMP_MODE)) {
180                 unset($GLOBALS['ErrorManager']->_postponed_errors);
181                 $request->finish();
182             }
183         } else {
184             return $this->error(fmt("Unsupported format argument %s", $args['format']));
185         }
186         return '';
187     }
188 }
189
190 class _PageList_Column_LinkDatabase_links extends _PageList_Column
191 {
192     function _getValue($page, &$revision_handle)
193     {
194         $out = HTML();
195         $links = $page->getPageLinks();
196         while ($link = $links->next()) {
197             $out->pushContent(" ", WikiLink($link));
198         }
199         return $out;
200     }
201 }
202
203 // Local Variables:
204 // mode: php
205 // tab-width: 8
206 // c-basic-offset: 4
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil
209 // End: