]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkDatabase.php
A simple plugin for WikiBrowser at http://touchgraph.sourceforge.net/
[SourceForge/phpwiki.git] / lib / plugin / LinkDatabase.php
1 <?php // -*-php-*-
2 rcs_id('$Id: LinkDatabase.php,v 1.1 2004-11-30 21:02:16 rurban Exp $');
3 /**
4  Copyright 2004 $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 by ?format=text) or the 
29  * Hypergraph applet without intermediate text file
30  * http://hypergraph.sourceforge.net/ (not yet tested)
31  */
32 class WikiPlugin_LinkDatabase
33 extends WikiPluginCached
34 {
35     function getName () {
36         return _("LinkDatabase");
37     }
38     function getPluginType() {
39         return PLUGIN_CACHED_HTML;
40     }
41     function getDescription () {
42         return _("List all pages with all links in text-format for some Java Visualization tools");
43     }
44     function getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision: 1.1 $");
47     }
48     function getExpire($dbi, $argarray, $request) {
49         return '+900'; // 15 minutes
50     }
51
52     function getDefaultArguments() {
53         return array_merge
54             (
55              PageList::supportedArgs(),
56              array(
57                    'format'        => 'text', // or 'html'
58                    'noheader'      => false,
59                    'include_empty' => false,
60                    'exclude_from'  => false,
61                    'info'          => '',
62                    ));
63     }
64
65     function getHtml($dbi, $argarray, $request, $basepage) {
66         $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
67     }
68     
69     function run($dbi, $argstr, $request, $basepage) {
70         $args = $this->getArgs($argstr, $request);
71         $caption = _("All pages with all links in this wiki (%d total):");
72         
73         if ( !empty($args['owner']) ) {
74             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],$args['sortby'],$args['limit']);
75             if ($args['owner'])
76                 $caption = fmt("List of pages owned by [%s] (%d total):", 
77                                WikiLink($args['owner'], 'if_known'),
78                                count($pages));
79         } elseif ( !empty($args['author']) ) {
80             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],$args['sortby'],$args['limit']);
81             if ($args['author'])
82                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
83                                WikiLink($args['author'], 'if_known'), 
84                                count($pages));
85         } elseif ( !empty($args['creator']) ) {
86             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],$args['sortby'],$args['limit']);
87             if ($args['creator'])
88                 $caption = fmt("List of pages created by [%s] (%d total):", 
89                                WikiLink($args['creator'], 'if_known'), 
90                                count($pages));
91         } else {
92             if (! $request->getArg('count'))  $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
93             else $args['count'] = $request->getArg('count');
94             $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit'], $args['exclude_from']);
95         }
96         if ($args['format'] == 'html') {
97             $args['types']['links'] = 
98                 new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
99             $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
100             if (!$args['noheader']) $pagelist->setCaption($caption);
101             return $pagelist;
102         } elseif ($args['format'] == 'text') {
103             $request->discardOutput();
104             $request->buffer_output(COMPRESS_OUTPUT);
105             if (!headers_sent())
106                 header("Content-Type: text/plain");
107             $request->checkValidators();
108             while ($page = $pages->next()) {
109                 echo $page->getName();
110                 $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
111                 while ($link = $links->next()) {
112                     echo " ", $link->getName();
113                 }
114                 echo "\n";
115             }
116             flush();
117             $request->finish();
118         } else {
119             return $this->error(fmt("Unsupported format argument %s", $args['format']));
120         }
121     }
122 };
123
124 class _PageList_Column_LinkDatabase_links extends _PageList_Column {
125     function _getValue($page, &$revision_handle) {
126         $out = HTML();
127         $links = $page->getPageLinks();
128         while ($link = $links->next()) {
129             $out->pushContent(" ", WikiLink($link));
130         }
131         return $out;
132     }
133 }
134
135 // $Log: not supported by cvs2svn $
136
137 // Local Variables:
138 // mode: php
139 // tab-width: 8
140 // c-basic-offset: 4
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil
143 // End:
144 ?>