2 rcs_id('$Id: OrphanedPages.php,v 1.3 2002-02-26 10:44:30 lakka Exp $');
4 /*This file is part of PhpWiki.
6 PhpWiki is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 PhpWiki is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with PhpWiki; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * A plugin which returns a list of pages which are not linked to by any other page
24 * Initial version by Lawrence Akka
28 require_once('lib/PageList.php');
32 class WikiPlugin_OrphanedPages
36 return _("OrphanedPages");
39 function getDescription () {
40 return _("Orphaned Pages");
43 function getDefaultArguments() {
44 return array('noheader' => false,
45 'include_empty' => false,
50 // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor,markup or all
51 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
53 function run($dbi, $argstr, $request) {
54 extract($this->getArgs($argstr, $request));
56 $pagelist = new PageList($info, $exclude);
59 $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):"));
61 // deleted pages show up as version 0.
63 $pagelist->_addColumn('version');
65 // There's probably a more efficient way to do this (eg a tailored SQL query via the
66 // backend, but this does the job
68 $allpages_iter = $dbi->getAllPages($include_empty);
70 while ($page = $allpages_iter->next())
72 $links_iter = $page->getLinks();
73 // test for absence of backlinks. If a page is linked to only by itself, it is
75 $parent = $links_iter->next();
76 if (!$parent || //page has no parents
77 (($parent->getName() == $page->getName()) && !$links_iter->next())) // page has itself only as a parent
78 $pagelist->addPage($page);
90 // c-hanging-comment-ender-p: nil
91 // indent-tabs-mode: nil