]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPages.php
added withlinks argument
[SourceForge/phpwiki.git] / lib / plugin / WantedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WantedPages.php,v 1.17 2007-05-24 18:41:04 rurban Exp $');
3 /*
4  Copyright (C) 2002, 2004 $ThePhpWikiProgrammingTeam
5  
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * Rewrite of WantedPages, which uses PageList and prints the references, not just the count.
25  * It disables r1.6 but is more explicit, and of comparable convenience.
26  *
27  * A plugin which returns a list of referenced pages which do not exist yet.
28  * All empty pages which are linked from any page - with an ending question mark,
29  * or for just a single page, when the page argument is present.
30  *
31  * TODO: sort pagename col: disable backend fallback
32  **/
33 include_once('lib/PageList.php');
34
35 class WikiPlugin_WantedPages
36 extends WikiPlugin
37 {
38     function getName () {
39         return _("WantedPages");
40     }
41     function getDescription () {
42         return _("Lists referenced page names which do not exist yet.");
43     }
44     function getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision: 1.17 $");
47     }
48     function getDefaultArguments() {
49         return array_merge
50             (
51              PageList::supportedArgs(),
52              array('page'     => '[pagename]', // just for a single page.
53                    'withlinks' => 0,
54                    'noheader' => false,
55                    'exclude_from'  => _("PgsrcTranslation").','._("InterWikiMap"),
56                    'limit'    => '100',
57                    'paging'   => 'auto'));
58     }
59
60     // info arg allows multiple columns
61     // info=mtime,hits,summary,version,author,locked,minor,markup or all
62     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
63     function run($dbi, $argstr, &$request, $basepage) {
64         $args = $this->getArgs($argstr, $request);
65         if (!empty($args['exclude_from']))
66             $args['exclude_from'] = is_string($args['exclude_from'])
67                 ? explodePageList($args['exclude_from']) 
68                 : $args['exclude_from']; // <! plugin-list !>
69         extract($args);
70         if ($page == _("WantedPages")) $page = "";
71
72         // There's probably a more memory-efficient way to do this (eg
73         // a tailored SQL query via the backend, but this gets the job
74         // done.
75         // TODO: Move this to backend/dumb/WantedPagesIter.php
76
77         if (!$page and $withlinks) {
78             $GLOBALS['WikiTheme']->addPageListColumn(
79                 array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left')));
80             $info = "pagename,wanted";
81         } elseif ($page) {
82             //only get WantedPages links for one page
83             $info = "";
84         } else {
85             // just link to links
86             $GLOBALS['WikiTheme']->addPageListColumn(
87                 array('links' => array('_PageList_Column_WantedPages_links', 'custom:links', _("Links"), 'left')));
88             $info = "pagename,links";
89         }
90         $pagelist = new PageList($info, $exclude, $args); // search button?
91         $pagelist->_wpagelist = array();
92
93         if (!$page) {
94             list($offset, $maxcount) = $pagelist->limit($limit);
95             $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit);
96             while ($row = $wanted_iter->next()) {
97                 $wanted = $row['pagename'];
98                 $wantedfrom = $row['wantedfrom'];
99                 // ignore duplicates:
100                 if (empty($pagelist->_wpagelist[$wanted]))
101                     $pagelist->addPage($wanted);
102                 if (!isset($pagelist->_wpagelist[$wanted]))
103                     $pagelist->_wpagelist[$wanted][] = $wantedfrom;
104                 elseif (!in_array($wantedfrom, $pagelist->_wpagelist[$wanted]))
105                     $pagelist->_wpagelist[$wanted][] = $wantedfrom;
106             }
107             $wanted_iter->free();
108             unset($wanted_iter);
109             // update limit, but it's still a hack.
110             $pagelist->_options['limit'] = "$offset," . min($pagelist->getTotal(), $maxcount);
111         } elseif ($dbi->isWikiPage($page)) {
112             //only get WantedPages links for one page
113             $page_handle = $dbi->getPage($page);
114             $links = $page_handle->getPageLinks(true); // include_empty
115             while ($link_handle = $links->next()) {
116                 if (! $dbi->isWikiPage($linkname = $link_handle->getName())) {
117                     $pagelist->addPage($linkname);
118                     //if (!array_key_exists($linkname, $this->_wpagelist))
119                     $pagelist->_wpagelist[$linkname][] = 1;
120                 }
121             }
122         }
123         /*
124         if ($sortby) {
125             ksort($this->_wpagelist);
126             arsort($this->_wpagelist);
127         }*/
128         if (!$noheader) {
129             if ($page)
130                 $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
131             else
132                 $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
133         }
134         // reference obviously doesn't work, so force an update to add _wpagelist to parentobj
135         if (isset($pagelist->_columns[1]) 
136             and in_array($pagelist->_columns[1]->_field, array('wanted','links')))
137             $pagelist->_columns[1]->parentobj =& $pagelist;
138         return $pagelist;
139     }
140 };
141
142 // which links to the missing page
143 class _PageList_Column_WantedPages_wanted extends _PageList_Column {
144     function _PageList_Column_WantedPages_wanted (&$params) {
145         $this->parentobj =& $params[3];
146         $this->_PageList_Column($params[0],$params[1],$params[2]);
147     }
148     function _getValue(&$page, $revision_handle) {
149         $html = false;
150         $pagename = $page->getName();
151         foreach ($this->parentobj->_wpagelist[$pagename] as $page) {
152             if ($html)
153                 $html->pushContent(', ', WikiLink($page));
154             else 
155                 $html = HTML(WikiLink($page));
156         }
157         return $html;
158     }
159 }
160
161 /*
162  * List of Links and link to ListLinks
163  */
164 class _PageList_Column_WantedPages_links extends _PageList_Column {
165     function _PageList_Column_WantedPages_links (&$params) {
166         $this->parentobj =& $params[3];
167         $this->_PageList_Column($params[0],$params[1],$params[2]);
168     }
169     function _getValue(&$page, $revision_handle) {
170         $html = false;
171         $pagename = $page->getName();
172         $count = count($this->parentobj->_wpagelist[$pagename]);
173         return LinkURL(WikiURL($page, array('action' => 'BackLinks'), false), 
174                         fmt("(%d Links)", $count));
175     }
176 }
177
178 // $Log: not supported by cvs2svn $
179 // Revision 1.16  2004/11/23 15:17:19  rurban
180 // better support for case_exact search (not caseexact for consistency),
181 // plugin args simplification:
182 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
183 //     and exclude in advance (at the sql level if possible)
184 //   handle sortby and limit from request override in WikiPlugin::getArgs
185 // ListSubpages: renamed pages to maxpages
186 //
187 // Revision 1.15  2004/11/23 13:35:49  rurban
188 // add case_exact search
189 //
190 // Revision 1.14  2004/11/20 17:35:58  rurban
191 // improved WantedPages SQL backends
192 // PageList::sortby new 3rd arg valid_fields (override db fields)
193 // WantedPages sql pager inexact for performance reasons:
194 //   assume 3 wantedfrom per page, to be correct, no getTotal()
195 // support exclude argument for get_all_pages, new _sql_set()
196 //
197 // Revision 1.13  2004/11/20 11:28:49  rurban
198 // fix a yet unused PageList customPageListColumns bug (merge class not decl to _types)
199 // change WantedPages to use PageList
200 // change WantedPages to print the list of referenced pages, not just the count.
201 //   the old version was renamed to WantedPagesOld
202 //   fix and add handling of most standard PageList arguments (limit, exclude, ...)
203 // TODO: pagename sorting, dumb/WantedPagesIter and SQL optimization
204 //
205 // Revision 1.12  2004/10/04 23:39:34  rurban
206 // just aesthetics
207 //
208 // Revision 1.11  2004/04/20 00:56:00  rurban
209 // more paging support and paging fix for shorter lists
210 //
211 // Revision 1.10  2004/04/18 01:44:02  rurban
212 // more sortby+limit support
213 //
214 // Revision 1.9  2004/04/10 04:15:06  rurban
215 // sf.net 927122 Suggestion
216 //
217 // Revision 1.8  2004/02/17 12:11:36  rurban
218 // 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, ...)
219 //
220 // Revision 1.7  2003/12/19 06:57:49  carstenklapp
221 // Bugfix: Enclose FullTextSearch query with quotes when the [Wiki Word]
222 // contains spaces.
223 //
224 // Revision 1.6  2003/11/19 17:08:23  carstenklapp
225 // New feature: Clicking on the number of citations in the links column
226 // now does a FullTextSearch for the WantedPage link!
227 //
228 // Revision 1.5  2003/03/25 21:05:27  dairiki
229 // Ensure pagenames are strings.
230 //
231 // Revision 1.4  2003/01/18 22:14:24  carstenklapp
232 // Code cleanup:
233 // Reformatting & tabs to spaces;
234 // Added copyleft, getVersion, getDescription, rcs_id.
235 //
236
237 // Local Variables:
238 // mode: php
239 // tab-width: 8
240 // c-basic-offset: 4
241 // c-hanging-comment-ender-p: nil
242 // indent-tabs-mode: nil
243 // End:
244 ?>