]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
Added multiple page exclusion and include_self. Added new message when only 1 match...
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.15 2002-01-30 18:27:13 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                      'pagename'         => '[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 (!$pagename)
34             return '';
35
36         $p = $dbi->getPage($pagename);
37         $backlinks = $p->getLinks();
38
39         $pagelist = new PageList;
40
41         if ($info)
42             foreach (explode(",", $info) as $col)
43                 $pagelist->insertColumn($col);
44
45         if ($exclude)
46             foreach (explode(",", $exclude) as $excludepage)
47                 $pagelist->excludePageName($excludepage);
48         if (!$include_self)
49                 $pagelist->excludePageName($pagename);
50
51         while ($backlink = $backlinks->next()) {
52             $pagelist->addPage($backlink);
53         }
54
55         if (!$noheader) {
56             $pagelink = LinkWikiWord($pagename);
57
58             if ($pagelist->isEmpty())
59                 return HTML::p(fmt("No pages link to %s.", $pagelink));
60
61             if ($pagelist->getTotal() == 1)
62                 $pagelist->setCaption(fmt("1 page links to %s:",
63                                           $pagelink));
64             else
65                 $pagelist->setCaption(fmt("%s pages link to %s:",
66                                           $pagelist->getTotal(), $pagelink));
67
68             $pagelist->setMessageIfEmpty('');
69         }
70
71         return $pagelist;
72     }
73 };
74
75 // For emacs users
76 // Local Variables:
77 // mode: php
78 // tab-width: 8
79 // c-basic-offset: 4
80 // c-hanging-comment-ender-p: nil
81 // indent-tabs-mode: nil
82 // End:
83         
84 ?>