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 along
17 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * A plugin which returns a list of pages which are not linked to by
25 * Initial version by Lawrence Akka
28 require_once 'lib/PageList.php';
30 class WikiPlugin_OrphanedPages
35 return _("OrphanedPages");
38 function getDescription()
40 return _("List pages which are not linked to by any other page.");
43 function getDefaultArguments()
45 return array('noheader' => false,
46 'include_empty' => false,
55 // info arg allows multiple columns
56 // info=mtime,hits,summary,version,author,locked,minor,markup or all
57 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
59 function run($dbi, $argstr, &$request, $basepage)
61 $args = $this->getArgs($argstr, $request);
64 // There's probably a more efficient way to do this (eg a
65 // tailored SQL query via the backend, but this does the job
67 $allpages_iter = $dbi->getAllPages($include_empty);
69 while ($page = $allpages_iter->next()) {
70 $links_iter = $page->getBackLinks();
71 // Test for absence of backlinks. If a page is linked to
72 // only by itself, it is still an orphan
73 $parent = $links_iter->next();
74 if (!$parent // page has no parents
75 or (($parent->getName() == $page->getName())
76 and !$links_iter->next())
77 ) // or page has only itself as a parent
82 $args['count'] = count($pages);
83 $pagelist = new PageList($info, $exclude, $args);
85 $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):"));
86 // deleted pages show up as version 0.
88 $pagelist->_addColumn('version');
89 list($offset, $pagesize) = $pagelist->limit($args['limit']);
90 if (!$pagesize) $pagelist->addPageList($pages);
92 for ($i = $offset; $i < $offset + $pagesize - 1; $i++) {
93 if ($i >= $args['count']) break;
94 $pagelist->addPage($pages[$i]);
105 // c-hanging-comment-ender-p: nil
106 // indent-tabs-mode: nil