]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/OrphanedPages.php
Enabled Admin "Email Verification"
[SourceForge/phpwiki.git] / lib / plugin / OrphanedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: OrphanedPages.php,v 1.5 2004-02-17 12:11:36 rurban Exp $');
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
17  along with PhpWiki; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 /**
31  */
32 class WikiPlugin_OrphanedPages
33 extends WikiPlugin
34 {
35     function getName () {
36         return _("OrphanedPages");
37     }
38
39     function getDescription () {
40         return _("List pages which are not linked to by any other page.");
41     }
42
43     function getVersion() {
44         return preg_replace("/[Revision: $]/", '',
45                             "\$Revision: 1.5 $");
46     }
47
48     function getDefaultArguments() {
49         return array('noheader'      => false,
50                      'include_empty' => false,
51                      'exclude'       => '',
52                      'info'          => ''
53                      );
54     }
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
58
59     function run($dbi, $argstr, &$request, $basepage) {
60         extract($this->getArgs($argstr, $request));
61
62         $pagelist = new PageList($info, $exclude);
63
64         if (!$noheader)
65             $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):"));
66
67         // deleted pages show up as version 0.
68         if ($include_empty)
69             $pagelist->_addColumn('version');
70
71         // There's probably a more efficient way to do this (eg a
72         // tailored SQL query via the backend, but this does the job
73
74         $allpages_iter = $dbi->getAllPages($include_empty);
75
76         while ($page = $allpages_iter->next()) {
77             $links_iter = $page->getLinks();
78             // test for absence of backlinks. If a page is linked to
79             // only by itself, it is still an orphan
80             $parent = $links_iter->next();
81             if (!$parent ||               // page has no parents
82                 (($parent->getName() == $page->getName())
83                  && !$links_iter->next()) // page has only itself as a parent
84                 )
85                 $pagelist->addPage($page);
86         }
87         return $pagelist;
88     }
89 };
90
91 // $Log: not supported by cvs2svn $
92 // Revision 1.4  2003/01/18 21:49:00  carstenklapp
93 // Code cleanup:
94 // Reformatting & tabs to spaces;
95 // Added copyleft, getVersion, getDescription, rcs_id.
96 //
97
98 // Local Variables:
99 // mode: php
100 // tab-width: 8
101 // c-basic-offset: 4
102 // c-hanging-comment-ender-p: nil
103 // indent-tabs-mode: nil
104 // End:
105 ?>