]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
Reverted pagename= arg back to page=. Begin refactor.
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.16 2002-01-30 22:46:35 carstenklapp Exp $');
3 /**
4  */
5
6 require_once('lib/PageList.php');
7
8 class WikiPlugin_BackLinks
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("BackLinks");
13     }
14
15     function getDescription () {
16         return sprintf(_("Get BackLinks for %s"),'[pagename]');
17     }
18   
19     function getDefaultArguments() {
20         return array('exclude'          => '',
21                      'include_self'     => 0,
22                      'noheader'         => 0,
23                      'page'             => '[pagename]',
24                      'info'             => false
25                      );
26     }
27     // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor
28     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
29  
30     function run($dbi, $argstr, $request) {
31         $this->_args = $this->getArgs($argstr, $request);
32         extract($this->_args);
33         if (!$page)
34             return '';
35
36         $pagelist = new PageList();
37         $this->_init($page, &$pagelist, $info, $exclude, $include_self);
38
39         $p = $dbi->getPage($page);
40         $backlinks = $p->getLinks();
41
42         while ($backlink = $backlinks->next()) {
43             $pagelist->addPage($backlink);
44         }
45
46         if (!$noheader) {
47             $pagelink = LinkWikiWord($page);
48
49             if ($pagelist->isEmpty())
50                 return HTML::p(fmt("No pages link to %s.", $pagelink));
51
52             if ($pagelist->getTotal() == 1)
53                 $pagelist->setCaption(fmt("1 page links to %s:",
54                                           $pagelink));
55             else
56                 $pagelist->setCaption(fmt("%s pages link to %s:",
57                                           $pagelist->getTotal(), $pagelink));
58
59             $pagelist->setMessageIfEmpty('');
60         }
61
62         return $pagelist;
63     }
64
65     function _init(&$page, &$pagelist, $info = '', $exclude = '', $include_self = '') {
66         if ($info)
67             foreach (explode(",", $info) as $col)
68                 $pagelist->insertColumn($col);
69
70         if ($exclude)
71             foreach (explode(",", $exclude) as $excludepage)
72                 $pagelist->excludePageName($excludepage);
73         if (!$include_self)
74             $pagelist->excludePageName($page);
75    }
76
77 };
78
79 // For emacs users
80 // Local Variables:
81 // mode: php
82 // tab-width: 8
83 // c-basic-offset: 4
84 // c-hanging-comment-ender-p: nil
85 // indent-tabs-mode: nil
86 // End:
87         
88 ?>