4 * Copyright 1999,2000,2001,2002,2006 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once 'lib/PageList.php';
25 class WikiPlugin_BackLinks
30 return _("BackLinks");
33 function getDescription()
35 return sprintf(_("List all pages which link to %s."), '[pagename]');
38 function getDefaultArguments()
42 PageList::supportedArgs(),
43 array('include_self' => false,
45 'page' => '[pagename]',
46 'linkmore' => '', // If count>0 and limit>0 display a link with
47 // the number of all results, linked to the given pagename.
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 // NEW: info=count : number of links
55 // page=foo,bar : backlinks to both pages
56 function run($dbi, $argstr, &$request, $basepage)
58 $args = $this->getArgs($argstr, $request);
61 if (empty($page) and $page != '0')
63 // exclude is now already expanded in WikiPlugin::getArgs()
64 if (empty($exclude)) $exclude = array();
68 $info = explode(",", $info);
69 if (in_array('count', $info))
70 $args['types']['count'] =
71 new _PageList_Column_BackLinks_count('count', _("#"), 'center');
74 $args['limit'] = $limit;
75 // $args['dosort'] = !empty($args['sortby']); // override DB sort (??)
76 $pagelist = new PageList($info, $exclude, $args);
78 // support logical AND: page1,page2
79 $pages = explodePageList($page);
80 $count = count($pages);
81 if (count($pages) > 1) {
82 // AND: the intersection of all these pages
84 foreach ($pages as $p) {
85 $dp = $dbi->getPage($p);
86 $bi = $dp->getBackLinks(false, $sortby, 0, $exclude);
87 while ($b = $bi->next()) {
88 $name = $b->getName();
89 if (isset($bl[$name]))
95 foreach ($bl as $b => $v)
97 $pagelist->addPage($b);
99 $p = $dbi->getPage($page);
100 $pagelist->addPages($p->getBackLinks(false, $sortby, 0, $exclude));
102 $total = $pagelist->getTotal();
104 // Localization note: In English, the differences between the
105 // various phrases spit out here may seem subtle or negligible
106 // enough to tempt you to combine/normalize some of these
107 // strings together, but the grammar employed most by other
108 // languages does not always end up with so subtle a
109 // distinction as it does with English in this case. :)
111 if ($page == $request->getArg('pagename')
112 and !$dbi->isWikiPage($page)
114 // BackLinks plugin is more than likely being called
115 // upon for an empty page on said page, while either
116 // 'browse'ing, 'create'ing or 'edit'ing.
118 // Don't bother displaying a WikiLink 'unknown', just
119 // the Un~WikiLink~ified (plain) name of the uncreated
120 // page currently being viewed.
123 if ($pagelist->isEmpty())
124 return HTML::p(fmt("No other page links to %s yet.", $pagelink));
127 $pagelist->setCaption(fmt("One page would link to %s:",
129 // Some future localizations will actually require
130 // this... (BelieveItOrNot, English-only-speakers!(:)
132 // else if ($pagelist->getTotal() == 2)
133 // $pagelist->setCaption(fmt("Two pages would link to %s:",
136 $pagelist->setCaption(fmt("%s pages would link to %s:",
141 $p = array_shift($tmp_pages);
142 $pagelink = HTML(WikiLink($p, 'auto'));
143 foreach ($tmp_pages as $p)
144 $pagelink->pushContent(" ", _("AND"), " ", WikiLink($p, 'auto'));
146 // BackLinks plugin is being displayed on a normal page.
147 $pagelink = WikiLink($page, 'auto');
149 if ($pagelist->isEmpty())
150 return HTML::p(fmt("No page links to %s.", $pagelink));
152 //trigger_error("DEBUG: " . $pagelist->getTotal());
155 $pagelist->setCaption(fmt("One page links to %s:",
157 // Some future localizations will actually require
158 // this... (BelieveItOrNot, English-only-speakers!(:)
160 // else if ($pagelist->getTotal() == 2)
161 // $pagelist->setCaption(fmt("Two pages link to %s:",
164 $pagelist->setCaption(fmt("%s pages link to %s:",
165 $limit > 0 ? $total : _("Those"),
169 if (!empty($args['linkmore'])
170 and $dbi->isWikiPage($args['linkmore'])
171 and $limit > 0 and $total > $limit
173 $pagelist->addCaption(WikiLink($args['linkmore'], "auto", _("More...")));
179 // how many links from this backLink to other pages
180 class _PageList_Column_BackLinks_count extends _PageList_Column
182 function _getValue($page, &$revision_handle)
184 $iter = $page->getPageLinks();
185 $count = $iter->count();
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil