]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/OrphanedPages.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / OrphanedPages.php
1 <?php // -*-php-*-
2
3 /**
4  * This file is part of PhpWiki.
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 /**
22  * A plugin which returns a list of pages which are not linked to by
23  * any other page
24  *
25  * Initial version by Lawrence Akka
26  *
27  **/
28 require_once 'lib/PageList.php';
29
30 class WikiPlugin_OrphanedPages
31 extends WikiPlugin
32 {
33     function getName () {
34         return _("OrphanedPages");
35     }
36
37     function getDescription () {
38         return _("List pages which are not linked to by any other page.");
39     }
40
41     function getDefaultArguments() {
42         return array('noheader'      => false,
43                      'include_empty' => false,
44                      'exclude'       => '',
45                      'info'          => '',
46                      'sortby'        => false,
47                      'limit'         => 0,
48                      'paging'        => 'auto',
49                      );
50     }
51     // info arg allows multiple columns
52     // info=mtime,hits,summary,version,author,locked,minor,markup or all
53     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
54
55     function run($dbi, $argstr, &$request, $basepage) {
56         $args = $this->getArgs($argstr, $request);
57         extract($args);
58
59         // There's probably a more efficient way to do this (eg a
60         // tailored SQL query via the backend, but this does the job
61
62         $allpages_iter = $dbi->getAllPages($include_empty);
63         $pages = array();
64         while ($page = $allpages_iter->next()) {
65             $links_iter = $page->getBackLinks();
66             // Test for absence of backlinks. If a page is linked to
67             // only by itself, it is still an orphan
68             $parent = $links_iter->next();
69             if (!$parent               // page has no parents
70                 or (($parent->getName() == $page->getName())
71                     and !$links_iter->next())) // or page has only itself as a parent
72             {
73                 $pages[] = $page;
74             }
75         }
76         $args['count'] = count($pages);
77         $pagelist = new PageList($info, $exclude, $args);
78         if (!$noheader)
79             $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):"));
80         // deleted pages show up as version 0.
81         if ($include_empty)
82             $pagelist->_addColumn('version');
83         list($offset,$pagesize) = $pagelist->limit($args['limit']);
84         if (!$pagesize) $pagelist->addPageList($pages);
85         else {
86             for ($i=$offset; $i < $offset + $pagesize - 1; $i++) {
87                     if ($i >= $args['count']) break;
88                 $pagelist->addPage($pages[$i]);
89             }
90         }
91         return $pagelist;
92     }
93 };
94
95 // Local Variables:
96 // mode: php
97 // tab-width: 8
98 // c-basic-offset: 4
99 // c-hanging-comment-ender-p: nil
100 // indent-tabs-mode: nil
101 // End: