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