]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
New argument 'info' to optionally specify data such as 'hits' to include in a second...
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.6 2002-01-15 02:42:32 carstenklapp Exp $');
3 /**
4  */
5 class WikiPlugin_BackLinks
6 extends WikiPlugin
7 {
8     function getName () {
9         return _("BackLinks");
10     }
11
12     function getDescription () {
13         return sprintf(_("Get BackLinks for %s"),'[pagename]');
14     }
15   
16     function getDefaultArguments() {
17         // FIXME: how to exclude multiple pages?
18         return array('exclude'          => '',
19                      'include_self'     => 0,
20                      'noheader'         => 0,
21                      'page'             => false,
22                      'info'             => false);
23     }
24
25     // Currently only info=false or info=hits works (I don't think
26     // anything else would be useful anyway).
27
28     function run($dbi, $argstr, $request) {
29         $args = $this->getArgs($argstr, $request);
30         extract($args);
31         if (!$page)
32             return '';
33               
34         $p = $dbi->getPage($page);
35         $backlinks = $p->getLinks();
36         $lines = array();
37         if ($info) {
38             $lines[] = $this->_tr(QElement('u', _(ucfirst($info))),
39                                   QElement('u', _("Page Name")));
40         }
41         while ($backlink = $backlinks->next()) {
42             $name = $backlink->getName();
43             if ($exclude && $name == $exclude)
44                 continue;
45             if (!$include_self && $name == $page)
46                 continue;
47             if ($info) {
48                 $lines[] = $this->_tr($backlink->get($info),
49                                       LinkWikiWord($name));
50             } else {
51                 $lines[] = Element('li', LinkWikiWord($name));
52             }
53         }
54
55         $html = '';
56         if (!$noheader) {
57             $fs = $lines ? _("These pages link to %s:") : _("No pages link to %s.");
58             $header = sprintf(htmlspecialchars($fs),
59                               LinkExistingWikiWord($page));
60             $html = Element('p', $header) . "\n";
61         }
62         
63         if ($info) {
64             $html .= Element('blockquote',
65                              Element('table', array('cellpadding' => 0,
66                                                     'cellspacing' => 1,
67                                                     'border' => 0),
68                                      join("\n", $lines)));
69             return $html;
70         } else {
71             return $html . Element('ul', join("\n", $lines));
72         }
73     }
74
75     function _tr ($col1, $col2) {
76         return "<tr><td align='right'>$col1&nbsp;&nbsp;</td>"
77             . "<td>&nbsp;&nbsp;$col2</td></tr>\n";
78     }
79
80 };
81
82 // For emacs users
83 // Local Variables:
84 // mode: php
85 // tab-width: 8
86 // c-basic-offset: 4
87 // c-hanging-comment-ender-p: nil
88 // indent-tabs-mode: nil
89 // End:
90         
91 ?>