]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BackLinks.php
info=count: number of links at this subpage
[SourceForge/phpwiki.git] / lib / plugin / BackLinks.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BackLinks.php,v 1.25 2004-09-13 15:00:50 rurban 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.25 $");
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
52     // info arg allows multiple columns
53     // info=mtime,hits,summary,version,author,locked,minor
54     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
55     // NEW: info=count : number of links
56     function run($dbi, $argstr, &$request, $basepage) {
57         $this->_args = $this->getArgs($argstr, $request);
58         extract($this->_args);
59         if (empty($page) and $page != '0')
60             return '';
61         
62         $exclude = $exclude ? explode(",", $exclude) : array();
63         if (!$include_self)
64             $exclude[] = $page;
65         if ($info) {
66             $info = explode(",", $info);
67             if (in_array('count',$info))
68                 $this->_args['types']['count'] = new _PageList_Column_BackLinks_count('count', _("#"), 'center');
69         }
70         $pagelist = new PageList($info, $exclude, $this->_args);
71         $p = $dbi->getPage($page);
72         $pagelist->addPages($p->getLinks());
73         
74         // Localization note: In English, the differences between the
75         // various phrases spit out here may seem subtle or negligible
76         // enough to tempt you to combine/normalize some of these
77         // strings together, but the grammar employed most by other
78         // languages does not always end up with so subtle a
79         // distinction as it does with English in this case. :)
80         if (!$noheader) {
81             if ($page == $request->getArg('pagename')
82                 && !$dbi->isWikiPage($page)) {
83                     // BackLinks plugin is more than likely being called
84                     // upon for an empty page on said page, while either
85                     // 'browse'ing, 'create'ing or 'edit'ing.
86                     //
87                     // Don't bother displaying a WikiLink 'unknown', just
88                     // the Un~WikiLink~ified (plain) name of the uncreated
89                     // page currently being viewed.
90                     $pagelink = $page;
91                     
92                     if ($pagelist->isEmpty())
93                         return HTML::p(fmt("No other page links to %s yet.", $pagelink));
94                     
95                     if ($pagelist->getTotal() == 1)
96                         $pagelist->setCaption(fmt("One page would link to %s:",
97                                                   $pagelink));
98                     // Some future localizations will actually require
99                     // this... (BelieveItOrNot, English-only-speakers!(:)
100                     //
101                     // else if ($pagelist->getTotal() == 2)
102                     //     $pagelist->setCaption(fmt("Two pages would link to %s:",
103                     //                               $pagelink));
104                     else
105                         $pagelist->setCaption(fmt("%s pages would link to %s:",
106                                                   $pagelist->getTotal(), $pagelink));
107             }
108             else {
109                 // BackLinks plugin is being displayed on a normal page.
110                 $pagelink = WikiLink($page, 'auto');
111                 
112                 if ($pagelist->isEmpty())
113                     return HTML::p(fmt("No page links to %s.", $pagelink));
114                 
115                 //trigger_error("DEBUG: " . $pagelist->getTotal());
116                 
117                 if ($pagelist->getTotal() == 1)
118                     $pagelist->setCaption(fmt("One page links to %s:",
119                                               $pagelink));
120                 // Some future localizations will actually require
121                 // this... (BelieveItOrNot, English-only-speakers!(:)
122                 //
123                 // else if ($pagelist->getTotal() == 2)
124                 //     $pagelist->setCaption(fmt("Two pages link to %s:",
125                 //                               $pagelink));
126                 else
127                     $pagelist->setCaption(fmt("%s pages link to %s:",
128                                               $pagelist->getTotal(), $pagelink));
129             }
130         }
131         return $pagelist;
132     }
133     
134 };
135
136 // how many links from this backLink to other pages
137 class _PageList_Column_BackLinks_count extends _PageList_Column {
138     function _getValue($page, &$revision_handle) {
139         $iter = $page->getPageLinks();
140         $count = $iter->count();
141         return $count;
142     }
143 }
144
145
146 // $Log: not supported by cvs2svn $
147 // Revision 1.24  2004/04/18 05:42:17  rurban
148 // more fixes for page="0"
149 // better WikiForum support
150 //
151 // Revision 1.23  2004/02/22 23:20:33  rurban
152 // fixed DumpHtmlToDir,
153 // enhanced sortby handling in PageList
154 //   new button_heading th style (enabled),
155 // added sortby and limit support to the db backends and plugins
156 //   for paging support (<<prev, next>> links on long lists)
157 //
158 // Revision 1.22  2004/02/17 12:11:36  rurban
159 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
160 //
161 // Revision 1.21  2003/12/22 07:31:57  carstenklapp
162 // Bugfix: commented out debugging code that snuck into the release.
163 //
164 // Revision 1.20  2003/12/14 05:36:31  carstenklapp
165 // Internal changes to prepare for an upcoming feature: Added some
166 // conditions and alternate phrases (alternate wording of text srings
167 // when referring to a non-existant page (i.e. WikiLink 'unknown')) when
168 // calling the BackLinks plugin *within* a non-existant page, such as
169 // from within an editpage or browse template while editing a new page.
170 //
171 // Revision 1.19  2003/01/18 21:19:25  carstenklapp
172 // Code cleanup:
173 // Reformatting; added copyleft, getVersion, getDescription
174 //
175
176 // For emacs users
177 // Local Variables:
178 // mode: php
179 // tab-width: 8
180 // c-basic-offset: 4
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil
183 // End:
184 ?>