]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
Internal changes to prepare for an upcoming feature: Added some
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.20 2003-12-14 05:36:31 carstenklapp Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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 /**
24  */
25 require_once('lib/PageList.php');
26
27 class WikiPlugin_BackLinks
28 extends WikiPlugin
29 {
30     function getName() {
31         return _("BackLinks");
32     }
33     
34     function getDescription() {
35         return sprintf(_("List all pages which link to %s."), '[pagename]');
36     }
37     
38     function getVersion() {
39         return preg_replace("/[Revision: $]/", '',
40                             "\$Revision: 1.20 $");
41     }
42     
43     function getDefaultArguments() {
44         return array('exclude'      => '',
45                      'include_self' => false,
46                      'noheader'     => false,
47                      'page'         => '[pagename]',
48                      'info'         => false
49                      );
50     }
51     // info arg allows multiple columns
52     // info=mtime,hits,summary,version,author,locked,minor
53     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
54     
55     function run($dbi, $argstr, $request) {
56         $this->_args = $this->getArgs($argstr, $request);
57         extract($this->_args);
58         if (!$page)
59             return '';
60         
61         $exclude = $exclude ? explode(",", $exclude) : array();
62         if (!$include_self)
63             $exclude[] = $page;
64         
65         $pagelist = new PageList($info, $exclude);
66         
67         $p = $dbi->getPage($page);
68         $pagelist->addPages($p->getLinks());
69         
70         // Localization note: In English, the differences between the
71         // various phrases spit out here may seem subtle or negligible
72         // enough to tempt you to combine/normalize some of these
73         // strings together, but the grammar employed most by other
74         // languages does not always end up with so subtle a
75         // distinction as it does with English in this case. :)
76         if (!$noheader) {
77             if ($page == $request->args['pagename']
78                 && !$dbi->isWikiPage($page))
79                 {
80                     // BackLinks plugin is more than likely being called
81                     // upon for an empty page on said page, while either
82                     // 'browse'ing, 'create'ing or 'edit'ing.
83                     //
84                     // Don't bother displaying a WikiLink 'unknown', just
85                     // the Un~WikiLink~ified (plain) name of the uncreated
86                     // page currently being viewed.
87                     $pagelink = $page;
88                     
89                     if ($pagelist->isEmpty())
90                         return HTML::p(fmt("No other page links to %s yet.", $pagelink));
91                     
92                     if ($pagelist->getTotal() == 1)
93                         $pagelist->setCaption(fmt("One page would link to %s:",
94                                                   $pagelink));
95                     // Some future localizations will actually require
96                     // this... (BelieveItOrNot, English-only-speakers!(:)
97                     //
98                     // else if ($pagelist->getTotal() == 2)
99                     //     $pagelist->setCaption(fmt("Two pages would link to %s:",
100                     //                               $pagelink));
101                     else
102                         $pagelist->setCaption(fmt("%s pages would link to %s:",
103                                                   $pagelist->getTotal(), $pagelink));
104                 }
105             else {
106                 // BackLinks plugin is being displayed on a normal page.
107                 $pagelink = WikiLink($page, 'auto');
108                 
109                 if ($pagelist->isEmpty())
110                     return HTML::p(fmt("No page links to %s.", $pagelink));
111                 
112                 trigger_error($pagelist->getTotal());
113                 
114                 if ($pagelist->getTotal() == 1)
115                     $pagelist->setCaption(fmt("One page links to %s:",
116                                               $pagelink));
117                 // Some future localizations will actually require
118                 // this... (BelieveItOrNot, English-only-speakers!(:)
119                 //
120                 // else if ($pagelist->getTotal() == 2)
121                 //     $pagelist->setCaption(fmt("Two pages link to %s:",
122                 //                               $pagelink));
123                 else
124                     $pagelist->setCaption(fmt("%s pages link to %s:",
125                                               $pagelist->getTotal(), $pagelink));
126             }
127         }
128         return $pagelist;
129     }
130     
131 };
132
133 // $Log: not supported by cvs2svn $
134 // Revision 1.19  2003/01/18 21:19:25  carstenklapp
135 // Code cleanup:
136 // Reformatting; added copyleft, getVersion, getDescription
137 //
138
139 // For emacs users
140 // Local Variables:
141 // mode: php
142 // tab-width: 8
143 // c-basic-offset: 4
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil
146 // End:
147 ?>