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