2 rcs_id('$Id: BackLinks.php,v 1.30 2004-11-25 17:20:52 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
25 require_once('lib/PageList.php');
27 class WikiPlugin_BackLinks
31 return _("BackLinks");
34 function getDescription() {
35 return sprintf(_("List all pages which link to %s."), '[pagename]');
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
40 "\$Revision: 1.30 $");
43 function getDefaultArguments() {
46 PageList::supportedArgs(),
47 array('include_self' => false,
49 'page' => '[pagename]',
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 $args = $this->getArgs($argstr, $request);
60 if (empty($page) and $page != '0')
62 // exclude is already expanded in WikiPlugin::getArgs()
63 if (empty($exclude)) $exclude = array();
67 $info = explode(",", $info);
68 if (in_array('count',$info))
69 $args['types']['count'] =
70 new _PageList_Column_BackLinks_count('count', _("#"), 'center');
72 $args['dosort'] = !empty($args['sortby']); // override DB sort
73 $pagelist = new PageList($info, $exclude, $args);
74 $p = $dbi->getPage($page);
75 $pagelist->addPages($p->getBackLinks(false, $sortby, $limit, $exclude));
77 // Localization note: In English, the differences between the
78 // various phrases spit out here may seem subtle or negligible
79 // enough to tempt you to combine/normalize some of these
80 // strings together, but the grammar employed most by other
81 // languages does not always end up with so subtle a
82 // distinction as it does with English in this case. :)
84 if ($page == $request->getArg('pagename')
85 && !$dbi->isWikiPage($page)) {
86 // BackLinks plugin is more than likely being called
87 // upon for an empty page on said page, while either
88 // 'browse'ing, 'create'ing or 'edit'ing.
90 // Don't bother displaying a WikiLink 'unknown', just
91 // the Un~WikiLink~ified (plain) name of the uncreated
92 // page currently being viewed.
95 if ($pagelist->isEmpty())
96 return HTML::p(fmt("No other page links to %s yet.", $pagelink));
98 if ($pagelist->getTotal() == 1)
99 $pagelist->setCaption(fmt("One page would link to %s:",
101 // Some future localizations will actually require
102 // this... (BelieveItOrNot, English-only-speakers!(:)
104 // else if ($pagelist->getTotal() == 2)
105 // $pagelist->setCaption(fmt("Two pages would link to %s:",
108 $pagelist->setCaption(fmt("%s pages would link to %s:",
109 $pagelist->getTotal(), $pagelink));
112 // BackLinks plugin is being displayed on a normal page.
113 $pagelink = WikiLink($page, 'auto');
115 if ($pagelist->isEmpty())
116 return HTML::p(fmt("No page links to %s.", $pagelink));
118 //trigger_error("DEBUG: " . $pagelist->getTotal());
120 if ($pagelist->getTotal() == 1)
121 $pagelist->setCaption(fmt("One page links to %s:",
123 // Some future localizations will actually require
124 // this... (BelieveItOrNot, English-only-speakers!(:)
126 // else if ($pagelist->getTotal() == 2)
127 // $pagelist->setCaption(fmt("Two pages link to %s:",
130 $pagelist->setCaption(fmt("%s pages link to %s:",
131 $pagelist->getTotal(), $pagelink));
139 // how many links from this backLink to other pages
140 class _PageList_Column_BackLinks_count extends _PageList_Column {
141 function _getValue($page, &$revision_handle) {
142 $iter = $page->getPageLinks();
143 $count = $iter->count();
149 // $Log: not supported by cvs2svn $
150 // Revision 1.29 2004/11/23 15:17:19 rurban
151 // better support for case_exact search (not caseexact for consistency),
152 // plugin args simplification:
153 // handle and explode exclude and pages argument in WikiPlugin::getArgs
154 // and exclude in advance (at the sql level if possible)
155 // handle sortby and limit from request override in WikiPlugin::getArgs
156 // ListSubpages: renamed pages to maxpages
158 // Revision 1.28 2004/10/14 17:16:22 rurban
159 // override DB sort: not applicable
161 // Revision 1.27 2004/09/25 16:33:52 rurban
162 // add support for all PageList options
164 // Revision 1.26 2004/09/14 10:32:32 rurban
165 // support exclude = plugin-list
167 // Revision 1.25 2004/09/13 15:00:50 rurban
168 // info=count: number of links at this subpage
170 // Revision 1.24 2004/04/18 05:42:17 rurban
171 // more fixes for page="0"
172 // better WikiForum support
174 // Revision 1.23 2004/02/22 23:20:33 rurban
175 // fixed DumpHtmlToDir,
176 // enhanced sortby handling in PageList
177 // new button_heading th style (enabled),
178 // added sortby and limit support to the db backends and plugins
179 // for paging support (<<prev, next>> links on long lists)
181 // Revision 1.22 2004/02/17 12:11:36 rurban
182 // 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, ...)
184 // Revision 1.21 2003/12/22 07:31:57 carstenklapp
185 // Bugfix: commented out debugging code that snuck into the release.
187 // Revision 1.20 2003/12/14 05:36:31 carstenklapp
188 // Internal changes to prepare for an upcoming feature: Added some
189 // conditions and alternate phrases (alternate wording of text srings
190 // when referring to a non-existant page (i.e. WikiLink 'unknown')) when
191 // calling the BackLinks plugin *within* a non-existant page, such as
192 // from within an editpage or browse template while editing a new page.
194 // Revision 1.19 2003/01/18 21:19:25 carstenklapp
196 // Reformatting; added copyleft, getVersion, getDescription
204 // c-hanging-comment-ender-p: nil
205 // indent-tabs-mode: nil