]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
More infiltration of new object-based HTML generation.
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.7 2002-01-21 06:55:47 dairiki 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         $this->_args = $this->getArgs($argstr, $request);
30         extract($this->_args);
31         if (!$page)
32             return '';
33
34         $p = $dbi->getPage($page);
35         $backlinks = $p->getLinks();
36
37         if ($info)
38             $list = $this->_info_listing($backlinks);
39         else
40             $list = $this->_plain_listing($backlinks);
41         
42         if ($noheader)
43             return $list;
44         
45         global $Theme;
46         $pagelink = $Theme->linkExistingWikiWord($page);
47         
48         if ($list)
49             $head = fmt("These pages link to %s:", $pagelink);
50         else
51             $head = fmt("No pages link to %s.", $pagelink);
52
53         $head = HTML::p($head);
54
55         return array($head, $list);
56     }
57
58     function _plain_listing ($backlinks) {
59         extract($this->_args);
60
61         $ul = HTML::ul();
62         $n = 0;
63         while ($backlink = $backlinks->next()) {
64             $name = $backlink->getName();
65             if ($exclude && $name == $exclude)
66                 continue;
67             if (!$include_self && $name == $page)
68                 continue;
69             $ul->pushContent(HTML::li(_LinkWikiWord($name)));
70             $n++;
71         }
72         return $n ? $ul : '';
73     }
74
75     function _info_listing ($backlinks) {
76         extract($this->_args);
77
78         $tab = HTML::table(array('cellpadding' => 0,
79                                  'cellspacing' => 1,
80                                  'border' => 0));
81         $tab->pushContent($this->_tr(HTML::u(_(ucfirst($info))),
82                                      HTML::u(_("Page Name"))));
83         $n = 0;
84         while ($backlink = $backlinks->next()) {
85             $name = $backlink->getName();
86             if ($exclude && $name == $exclude)
87                 continue;
88             if (!$include_self && $name == $page)
89                 continue;
90             $tab->pushContent($this->_tr($backlink->get($info),
91                                          _LinkWikiWord($name)));
92             $n++;
93         }
94         return $n ? HTML::blockquote($tab) : '';
95     }
96     
97
98     function _tr ($col1, $col2) {
99         return HTML::tr(HTML::td(array('align' => 'right'),
100                                  $col1, new RawXml('&nbsp;&nbsp;')),
101                         HTML::td(new RawXml('&nbsp;&nbsp;'), $col2));
102     }
103     
104         
105
106
107 };
108
109 // For emacs users
110 // Local Variables:
111 // mode: php
112 // tab-width: 8
113 // c-basic-offset: 4
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil
116 // End:
117         
118 ?>