]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/OrphanedPages.php
Activated Id substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / OrphanedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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.10 $");
46     }
47
48     function getDefaultArguments() {
49         return array('noheader'      => false,
50                      'include_empty' => false,
51                      'exclude'       => '',
52                      'info'          => '',
53                      'sortby'        => false,
54                      'limit'         => 0,
55                      'paging'        => 'auto',
56                      );
57     }
58     // info arg allows multiple columns
59     // info=mtime,hits,summary,version,author,locked,minor,markup or all
60     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
61
62     function run($dbi, $argstr, &$request, $basepage) {
63         $args = $this->getArgs($argstr, $request);
64         extract($args);
65
66         // There's probably a more efficient way to do this (eg a
67         // tailored SQL query via the backend, but this does the job
68
69         $allpages_iter = $dbi->getAllPages($include_empty);
70         $pages = array();
71         while ($page = $allpages_iter->next()) {
72             $links_iter = $page->getBackLinks();
73             // Test for absence of backlinks. If a page is linked to
74             // only by itself, it is still an orphan
75             $parent = $links_iter->next();
76             if (!$parent               // page has no parents
77                 or (($parent->getName() == $page->getName())
78                     and !$links_iter->next())) // or page has only itself as a parent
79             {
80                 $pages[] = $page;
81             }
82         }
83         $args['count'] = count($pages);
84         $pagelist = new PageList($info, $exclude, $args);
85         if (!$noheader)
86             $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):"));
87         // deleted pages show up as version 0.
88         if ($include_empty)
89             $pagelist->_addColumn('version');
90         list($offset,$pagesize) = $pagelist->limit($args['limit']);
91         if (!$pagesize) $pagelist->addPageList($pages);
92         else {
93             for ($i=$offset; $i < $offset + $pagesize - 1; $i++) {
94                 if ($i >= $args['count']) break;
95                 $pagelist->addPage($pages[$i]);
96             }
97         }
98         return $pagelist;
99     }
100 };
101
102 // $Log: not supported by cvs2svn $
103 // Revision 1.9  2004/07/09 12:49:46  rurban
104 // no limit, no sorting
105 //
106 // Revision 1.8  2004/04/20 00:56:00  rurban
107 // more paging support and paging fix for shorter lists
108 //
109 // Revision 1.7  2004/04/20 00:34:15  rurban
110 // more paging support
111 //
112 // Revision 1.6  2004/04/18 01:44:02  rurban
113 // more sortby+limit support
114 //
115 // Revision 1.5  2004/02/17 12:11:36  rurban
116 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
117 //
118 // Revision 1.4  2003/01/18 21:49:00  carstenklapp
119 // Code cleanup:
120 // Reformatting & tabs to spaces;
121 // Added copyleft, getVersion, getDescription, rcs_id.
122 //
123
124 // Local Variables:
125 // mode: php
126 // tab-width: 8
127 // c-basic-offset: 4
128 // c-hanging-comment-ender-p: nil
129 // indent-tabs-mode: nil
130 // End:
131 ?>