]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/PageList.php
exclude pages already in addPages to simplify plugins
[SourceForge/phpwiki.git] / lib / PageList.php
1 <?php rcs_id('$Id: PageList.php,v 1.107 2004-09-14 10:29:08 rurban Exp $');
2
3 /**
4  * List a number of pagenames, optionally as table with various columns.
5  * This library relieves some work for these plugins:
6  *
7  * AllPages, BackLinks, LikePages, MostPopular, TitleSearch, WikiAdmin* and more
8  *
9  * It also allows dynamic expansion of those plugins to include more
10  * columns in their output.
11  *
12  * Column 'info=' arguments:
13  *
14  * 'pagename' _("Page Name")
15  * 'mtime'    _("Last Modified")
16  * 'hits'     _("Hits")
17  * 'summary'  _("Last Summary")
18  * 'version'  _("Version")),
19  * 'author'   _("Last Author")),
20  * 'locked'   _("Locked"), _("locked")
21  * 'minor'    _("Minor Edit"), _("minor")
22  * 'markup'   _("Markup")
23  * 'size'     _("Size")
24  * 'creator'  _("Creator")
25  * 'owner'    _("Owner")
26  * 'checkbox'  selectable checkbox at the left.
27  * 'content'  
28  *
29  * Special, custom columns: Either theme or plugin (WikiAdmin*) specific.
30  * 'remove'   _("Remove")     
31  * 'perm'     _("Permission Mask")
32  * 'acl'      _("ACL")
33  * 'renamed_pagename'   _("Rename to")
34  * 'ratingwidget', ... wikilens theme specific.
35  * 'custom'   See plugin/_WikiTranslation
36  *
37  * Symbolic 'info=' arguments:
38  * 'all'       All columns except the special columns
39  * 'most'      pagename, mtime, author, size, hits, ...
40  * 'some'      pagename, mtime, author
41  *
42  * FIXME: In this refactoring I (Jeff) have un-implemented _ctime, _cauthor, and
43  * number-of-revision.  Note the _ctime and _cauthor as they were implemented
44  * were somewhat flawed: revision 1 of a page doesn't have to exist in the
45  * database.  If lots of revisions have been made to a page, it's more than likely
46  * that some older revisions (include revision 1) have been cleaned (deleted).
47  *
48  * DONE: 
49  *   paging support: limit, offset args
50  *   check PagePerm "list" access-type,
51  *   all columns are sortable (Thanks to the wikilens team).
52  *
53  * TODO: 
54  *   rows arguments for multiple pages/multiple rows.
55  *
56  *   ->supportedArgs() which arguments are supported, so that the plugin 
57  *                     doesn't explictly need to declare it 
58  *   Status: already merged in some plugins calls
59  *
60  *   new method:
61  *     list not as <ul> or table, but as simple comma-seperated list
62  *
63  *   fix memory exhaustion on large pagelists. 
64  *   Status: fixed 2004-06-25 16:19:36 rurban but needs further testing.
65  */
66 class _PageList_Column_base {
67     var $_tdattr = array();
68
69     function _PageList_Column_base ($default_heading, $align = false) {
70         $this->_heading = $default_heading;
71
72         if ($align) {
73             // align="char" isn't supported by any browsers yet :(
74             //if (is_array($align))
75             //    $this->_tdattr = $align;
76             //else
77             $this->_tdattr['align'] = $align;
78         }
79     }
80
81     function format ($pagelist, $page_handle, &$revision_handle) {
82         return HTML::td($this->_tdattr,
83                         HTML::raw('&nbsp;'),
84                         $this->_getValue($page_handle, $revision_handle),
85                         HTML::raw('&nbsp;'));
86     }
87
88     function getHeading () {
89         return $this->_heading;
90     }
91
92     function setHeading ($heading) {
93         $this->_heading = $heading;
94     }
95
96     // old-style heading
97     function heading () {
98         // allow sorting?
99         if (1 /* or in_array($this->_field, PageList::sortable_columns())*/) {
100             // multiple comma-delimited sortby args: "+hits,+pagename"
101             // asc or desc: +pagename, -pagename
102             $sortby = PageList::sortby($this->_field, 'flip_order');
103             //Fixme: pass all also other GET args along. (limit, p[])
104             //TODO: support GET and POST
105             $s = HTML::a(array('href' => 
106                                $GLOBALS['request']->GetURLtoSelf(array('sortby' => $sortby,
107                                                                        'nocache' => '1')),
108                                'class' => 'pagetitle',
109                                'title' => sprintf(_("Sort by %s"), $this->_field)), 
110                          HTML::raw('&nbsp;'), HTML::u($this->_heading), HTML::raw('&nbsp;'));
111         } else {
112             $s = HTML(HTML::raw('&nbsp;'), HTML::u($this->_heading), HTML::raw('&nbsp;'));
113         }
114         return HTML::th(array('align' => 'center'),$s);
115     }
116
117     // new grid-style
118     // see activeui.js 
119     function button_heading ($pagelist, $colNum) {
120         global $WikiTheme, $request;
121         // allow sorting?
122         if (1 /* or in_array($this->_field, PageList::sortable_columns()) */) {
123             // multiple comma-delimited sortby args: "+hits,+pagename"
124             $src = false; 
125             $noimg_src = $WikiTheme->getButtonURL('no_order');
126             if ($noimg_src)
127                 $noimg = HTML::img(array('src' => $noimg_src,
128                                          'width' => '7', 
129                                          'height' => '7',
130                                          'border' => 0,
131                                          'alt'    => '.'));
132             else 
133                 $noimg = HTML::raw('&nbsp;');
134             if ($request->getArg('sortby')) {
135                 if ($pagelist->sortby($colNum, 'check')) { // show icon?
136                     $sortby = $pagelist->sortby($request->getArg('sortby'), 'flip_order');
137                     $request->setArg('sortby', $sortby);
138                     $desc = (substr($sortby,0,1) == '-'); // asc or desc? (+pagename, -pagename)
139                     $src = $WikiTheme->getButtonURL($desc ? 'asc_order' : 'desc_order');
140                 } else {
141                     $sortby = $pagelist->sortby($colNum, 'init');
142                 }
143             } else {
144                 $sortby = $pagelist->sortby($colNum, 'init');
145             }
146             if (!$src) {
147                 $img = $noimg;
148                 //$img->setAttr('alt', _("Click to sort"));
149             } else {
150                 $img = HTML::img(array('src' => $src, 
151                                        'width' => '7', 
152                                        'height' => '7', 
153                                        'border' => 0,
154                                        'alt' => _("Click to reverse sort order")));
155             }
156             $s = HTML::a(array('href' => 
157                                //Fixme: pass all also other GET args along. (limit, p[])
158                                //Fixme: convert to POST submit[sortby]
159                                $request->GetURLtoSelf(array('sortby' => $sortby,
160                                                             'nocache' => '1')),
161                                'class' => 'gridbutton', 
162                                'title' => sprintf(_("Click to sort by %s"), $this->_field)),
163                          HTML::raw('&nbsp;'),
164                          $noimg,
165                          HTML::raw('&nbsp;'),
166                          $this->_heading,
167                          HTML::raw('&nbsp;'),
168                          $img,
169                          HTML::raw('&nbsp;'));
170         } else {
171             $s = HTML(HTML::raw('&nbsp;'), $this->_heading, HTML::raw('&nbsp;'));
172         }
173         return HTML::th(array('align' => 'center', 'valign' => 'middle', 
174                               'class' => 'gridbutton'), $s);
175     }
176
177     /**
178      * Take two columns of this type and compare them.
179      * An undefined value is defined to be < than the smallest defined value.
180      * This base class _compare only works if the value is simple (e.g., a number).
181      *
182      * @param  $colvala  $this->_getValue() of column a
183      * @param  $colvalb  $this->_getValue() of column b
184      *
185      * @return -1 if $a < $b, 1 if $a > $b, 0 otherwise.
186      */
187     function _compare($colvala, $colvalb) {
188         if (is_string($colvala))
189             return strcmp($colvala,$colvalb);
190         $ret = 0;
191         if (($colvala === $colvalb) || (!isset($colvala) && !isset($colvalb))) {
192             ;
193         } else {
194             $ret = (!isset($colvala) || ($colvala < $colvalb)) ? -1 : 1;
195         }
196         return $ret; 
197     }
198 };
199
200 class _PageList_Column extends _PageList_Column_base {
201     function _PageList_Column ($field, $default_heading, $align = false) {
202         $this->_PageList_Column_base($default_heading, $align);
203
204         $this->_need_rev = substr($field, 0, 4) == 'rev:';
205         $this->_iscustom = substr($field, 0, 7) == 'custom:';
206         if ($this->_iscustom) {
207             $this->_field = substr($field, 7);
208         }
209         elseif ($this->_need_rev)
210             $this->_field = substr($field, 4);
211         else
212             $this->_field = $field;
213     }
214
215     function _getValue ($page_handle, &$revision_handle) {
216         if ($this->_need_rev) {
217             if (!$revision_handle)
218                 // columns which need the %content should override this. (size, hi_content)
219                 $revision_handle = $page_handle->getCurrentRevision(false);
220             return $revision_handle->get($this->_field);
221         }
222         else {
223             return $page_handle->get($this->_field);
224         }
225     }
226     
227     function _getSortableValue ($page_handle, &$revision_handle) {
228         return _PageList_Column::_getValue($page_handle, $revision_handle);
229     }
230 };
231
232 /* overcome a call_user_func limitation by not being able to do:
233  * call_user_func_array(array(&$class, $class_name), $params);
234  * So we need $class = new $classname($params);
235  * And we add a 4th param for the parent $pagelist object
236  */
237 class _PageList_Column_custom extends _PageList_Column {
238     function _PageList_Column_custom($params) {
239         $this->_pagelist =& $params[3];
240         $this->_PageList_Column($params[0], $params[1], $params[2]);
241     }
242 }
243
244 class _PageList_Column_size extends _PageList_Column {
245     function format (&$pagelist, $page_handle, &$revision_handle) {
246         return HTML::td($this->_tdattr,
247                         HTML::raw('&nbsp;'),
248                         $this->_getValue($pagelist, $page_handle, $revision_handle),
249                         HTML::raw('&nbsp;'));
250     }
251     
252     function _getValue (&$pagelist, $page_handle, &$revision_handle) {
253         if (!$revision_handle or (!$revision_handle->_data['%content'] 
254                                   or $revision_handle->_data['%content'] === true)) {
255             $revision_handle = $page_handle->getCurrentRevision(true);
256             unset($revision_handle->_data['%pagedata']['_cached_html']);
257         }
258         $size = $this->_getSize($revision_handle);
259         // we can safely purge the content when it is not sortable
260         if (empty($pagelist->_sortby[$this->_field]))
261             unset($revision_handle->_data['%content']);
262         return $size;
263     }
264     
265     function _getSortableValue ($page_handle, &$revision_handle) {
266         if (!$revision_handle)
267             $revision_handle = $page_handle->getCurrentRevision(true);
268         return (empty($revision_handle->_data['%content'])) 
269                ? 0 : strlen($revision_handle->_data['%content']);
270     }
271
272     function _getSize($revision_handle) {
273         $bytes = @strlen($revision_handle->_data['%content']);
274         return ByteFormatter($bytes);
275     }
276 }
277
278
279 class _PageList_Column_bool extends _PageList_Column {
280     function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
281         $this->_PageList_Column($field, $default_heading, 'center');
282         $this->_textIfTrue = $text;
283         $this->_textIfFalse = new RawXml('&#8212;'); //mdash
284     }
285
286     function _getValue ($page_handle, &$revision_handle) {
287         //FIXME: check if $this is available in the parent (->need_rev)
288         $val = _PageList_Column::_getValue($page_handle, $revision_handle);
289         return $val ? $this->_textIfTrue : $this->_textIfFalse;
290     }
291 };
292
293 class _PageList_Column_checkbox extends _PageList_Column {
294     function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
295         $this->_name = $name;
296         $heading = HTML::input(array('type'  => 'button',
297                                      'title' => _("Click to de-/select all pages"),
298                                      //'width' => '100%',
299                                      'name'  => $default_heading,
300                                      'value' => $default_heading,
301                                      'onclick' => "flipAll(this.form)"
302                                      ));
303         $this->_PageList_Column($field, $heading, 'center');
304     }
305     function _getValue ($pagelist, $page_handle, &$revision_handle) {
306         $pagename = $page_handle->getName();
307         $selected = !empty($pagelist->_selected[$pagename]);
308         if (strstr($pagename,'[') or strstr($pagename,']')) {
309             $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
310         }
311         if ($selected) {
312             return HTML::input(array('type' => 'checkbox',
313                                      'name' => $this->_name . "[$pagename]",
314                                      'value' => 1,
315                                      'checked' => 'CHECKED'));
316         } else {
317             return HTML::input(array('type' => 'checkbox',
318                                      'name' => $this->_name . "[$pagename]",
319                                      'value' => 1));
320         }
321     }
322     function format ($pagelist, $page_handle, &$revision_handle) {
323         return HTML::td($this->_tdattr,
324                         HTML::raw('&nbsp;'),
325                         $this->_getValue($pagelist, $page_handle, $revision_handle),
326                         HTML::raw('&nbsp;'));
327     }
328     // don't sort this javascript button
329     function button_heading ($pagelist, $colNum) {
330         $s = HTML(HTML::raw('&nbsp;'), $this->_heading, HTML::raw('&nbsp;'));
331         return HTML::th(array('align' => 'center', 'valign' => 'middle', 
332                               'class' => 'gridbutton'), $s);
333     }
334 };
335
336 class _PageList_Column_time extends _PageList_Column {
337     function _PageList_Column_time ($field, $default_heading) {
338         $this->_PageList_Column($field, $default_heading, 'right');
339         global $WikiTheme;
340         $this->Theme = &$WikiTheme;
341     }
342
343     function _getValue ($page_handle, &$revision_handle) {
344         $time = _PageList_Column::_getValue($page_handle, $revision_handle);
345         return $this->Theme->formatDateTime($time);
346     }
347 };
348
349 class _PageList_Column_version extends _PageList_Column {
350     function _getValue ($page_handle, &$revision_handle) {
351         if (!$revision_handle)
352             $revision_handle = $page_handle->getCurrentRevision();
353         return $revision_handle->getVersion();
354     }
355 };
356
357 // Output is hardcoded to limit of first 50 bytes. Otherwise
358 // on very large Wikis this will fail if used with AllPages
359 // (PHP memory limit exceeded)
360 // FIXME: old PHP without superglobals
361 class _PageList_Column_content extends _PageList_Column {
362     function _PageList_Column_content ($field, $default_heading, $align = false) {
363         $this->_PageList_Column($field, $default_heading, $align);
364         $this->bytes = 50;
365         if ($field == 'content') {
366             $this->_heading .= sprintf(_(" ... first %d bytes"),
367                                        $this->bytes);
368         } elseif ($field == 'hi_content') {
369             if (!empty($_POST['admin_replace'])) {
370                 $search = $_POST['admin_replace']['from'];
371                 $this->_heading .= sprintf(_(" ... around %s"),
372                                            '»'.$search.'«');
373             }
374         }
375     }
376     
377     function _getValue ($page_handle, &$revision_handle) {
378         if (!$revision_handle or (!$revision_handle->_data['%content'] 
379                                   or $revision_handle->_data['%content'] === true)) {
380             $revision_handle = $page_handle->getCurrentRevision(true);
381         }
382         // Not sure why implode is needed here, I thought
383         // getContent() already did this, but it seems necessary.
384         $c = implode("\n", $revision_handle->getContent());
385         if (empty($pagelist->_sortby[$this->_field]))
386             unset($revision_handle->_data['%content']);
387         if ($this->_field == 'hi_content') {
388             unset($revision_handle->_data['%pagedata']['_cached_html']);
389             $search = $_POST['admin_replace']['from'];
390             if ($search and ($i = strpos($c,$search))) {
391                 $l = strlen($search);
392                 $j = max(0,$i - ($this->bytes / 2));
393                 return HTML::div(array('style' => 'font-size:x-small'),
394                                  HTML::div(array('class' => 'transclusion'),
395                                            HTML::span(substr($c, $j, ($this->bytes / 2))),
396                                            HTML::span(array("style"=>"background:yellow"),$search),
397                                            HTML::span(substr($c, $i+$l, ($this->bytes / 2))))
398                                  );
399             } else {
400                 $c = sprintf(_("%s not found"),
401                              '»'.$search.'«');
402                 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
403                                  $c);
404             }
405         } elseif (($len = strlen($c)) > $this->bytes) {
406             $c = substr($c, 0, $this->bytes);
407         }
408         include_once('lib/BlockParser.php');
409         // false --> don't bother processing hrefs for embedded WikiLinks
410         $ct = TransformText($c, $revision_handle->get('markup'), false);
411         if (empty($pagelist->_sortby[$this->_field]))
412             unset($revision_handle->_data['%pagedata']['_cached_html']);
413         return HTML::div(array('style' => 'font-size:x-small'),
414                          HTML::div(array('class' => 'transclusion'), $ct),
415                          // Don't show bytes here if size column present too
416                          ($this->parent->_columns_seen['size'] or !$len) ? "" :
417                            ByteFormatter($len, /*$longformat = */true));
418     }
419     
420     function _getSortableValue ($page_handle, &$revision_handle) {
421         return substr(_PageList_Column::_getValue($page_handle, $revision_handle),0,50);
422     }
423 };
424
425 class _PageList_Column_author extends _PageList_Column {
426     function _PageList_Column_author ($field, $default_heading, $align = false) {
427         _PageList_Column::_PageList_Column($field, $default_heading, $align);
428         $this->dbi =& $GLOBALS['request']->getDbh();
429     }
430
431     function _getValue ($page_handle, &$revision_handle) {
432         $author = _PageList_Column::_getValue($page_handle, $revision_handle);
433         if (isWikiWord($author) && $this->dbi->isWikiPage($author))
434             return WikiLink($author);
435         else
436             return $author;
437     }
438 };
439
440 class _PageList_Column_owner extends _PageList_Column_author {
441     function _getValue ($page_handle, &$revision_handle) {
442         $author = $page_handle->getOwner();
443         if (isWikiWord($author) && $this->dbi->isWikiPage($author))
444             return WikiLink($author);
445         else
446             return $author;
447     }
448 };
449
450 class _PageList_Column_creator extends _PageList_Column_author {
451     function _getValue ($page_handle, &$revision_handle) {
452         $author = $page_handle->getCreator();
453         if (isWikiWord($author) && $this->dbi->isWikiPage($author))
454             return WikiLink($author);
455         else
456             return $author;
457     }
458 };
459
460 class _PageList_Column_pagename extends _PageList_Column_base {
461     var $_field = 'pagename';
462
463     function _PageList_Column_pagename () {
464         $this->_PageList_Column_base(_("Page Name"));
465         global $request;
466         $this->dbi = &$request->getDbh();
467     }
468
469     function _getValue ($page_handle, &$revision_handle) {
470         if ($this->dbi->isWikiPage($page_handle->getName()))
471             return WikiLink($page_handle);
472         else
473             return WikiLink($page_handle, 'unknown');
474     }
475     
476     function _getSortableValue ($page_handle, &$revision_handle) {
477         return $page_handle->getName();
478     }
479
480     /**
481      * Compare two pagenames for sorting.  See _PageList_Column::_compare.
482      **/
483     function _compare($colvala, $colvalb) {
484         return strcmp($colvala, $colvalb);
485     }
486 };
487
488 /**
489  * A class to bundle up a page with a reference to PageList, so that
490  * the compare function for usort() has access to it all.
491  * This is a hack necessitated by the interface to usort()-- comparators
492  * can't get information upon construction; you get a comparator by class
493  * name, not by instance.
494  * @author: Dan Frankowski
495  */
496 class _PageList_Page {
497     var $_pagelist;
498     var $_page;
499
500     function _PageList_Page(&$pagelist, &$page_handle) {
501         $this->_pagelist = $pagelist;
502         $this->_page = $page_handle;
503     }
504
505     function & getPageList() {
506         return $this->_pagelist;
507     }
508
509     function & getPage() {
510         return $this->_page;
511     }
512 }
513
514 class PageList {
515     var $_group_rows = 3;
516     var $_columns = array();
517     var $_columnsMap = array();      // Maps column name to column number.
518     var $_excluded_pages = array();
519     var $_pages = array();
520     var $_caption = "";
521     var $_pagename_seen = false;
522     var $_types = array();
523     var $_options = array();
524     var $_selected = array();
525     var $_sortby = array();
526     var $_maxlen = 0;
527
528     function PageList ($columns = false, $exclude = false, $options = false) {
529         if ($options)
530             $this->_options = $options;
531
532         // let plugins predefine only certain objects, such its own custom pagelist columns
533         if (!empty($this->_options['types'])) {
534             $this->_types = $this->_options['types'];
535             unset($this->_options['types']);
536         }
537         $this->_initAvailableColumns();
538         $symbolic_columns = 
539             array(
540                   'all' =>  array_diff(array_keys($this->_types), // all but...
541                                        array('checkbox','remove','renamed_pagename',
542                                              'content','hi_content','perm','acl')),
543                   'most' => array('pagename','mtime','author','hits'),
544                   'some' => array('pagename','mtime','author')
545                   );
546         if ($columns) {
547             if (!is_array($columns))
548                 $columns = explode(',', $columns);
549             // expand symbolic columns:
550             foreach ($symbolic_columns as $symbol => $cols) {
551                 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
552                     $columns = array_diff(array_merge($columns,$cols),array($symbol));
553                 }
554             }
555             if (!in_array('pagename',$columns))
556                 $this->_addColumn('pagename');
557             foreach ($columns as $col) {
558                 $this->_addColumn($col);
559             }
560         }
561         // If 'pagename' is already present, _addColumn() will not add it again
562         $this->_addColumn('pagename');
563
564         foreach (array('sortby','limit','paging','count') as $key) {
565           if (!empty($options) and !empty($options[$key])) {
566             $this->_options[$key] = $options[$key];
567           } else {
568             $this->_options[$key] = $GLOBALS['request']->getArg($key);
569           }
570         }
571         $this->_options['sortby'] = $this->sortby($this->_options['sortby'], 'init');
572         if ($exclude) {
573             if (is_string($exclude) and !is_array($exclude))
574                 $exclude = $this->explodePageList($exclude, false,
575                                                   $this->_options['sortby'],
576                                                   $this->_options['limit']);
577             $this->_excluded_pages = $exclude;
578         }
579         $this->_messageIfEmpty = _("<no matches>");
580     }
581
582     // Currently PageList takes these arguments:
583     // 1: info, 2: exclude, 3: hash of options
584     // Here we declare which options are supported, so that 
585     // the calling plugin may simply merge this with its own default arguments 
586     function supportedArgs () {
587         return array(//Currently supported options:
588                      'info'     => 'pagename',
589                      'exclude'  => '',          // also wildcards and comma-seperated lists
590
591                      /* select pages by meta-data: */
592                      'author'   => false, // current user by []
593                      'owner'    => false, // current user by []
594                      'creator'  => false, // current user by []
595
596                      // for the sort buttons in <th>
597                      'sortby'   => '', // same as for WikiDB::getAllPages (unsorted is faster)
598
599                      //PageList pager options:
600                      // These options may also be given to _generate(List|Table) later
601                      // But limit and offset might help the query WikiDB::getAllPages()
602                      'cols'     => 1,       // side-by-side display of list (1-3)
603                      'limit'    => 0,       // number of rows (pagesize)
604                      'paging'   => 'auto',  // 'auto'  normal paging mode
605                      //                     // 'smart' drop 'info' columns and enhance rows 
606                      //                     //         when the list becomes large
607                      //                     // 'none'  don't page at all
608                      //'azhead' => 0        // provide shortcut links to pages starting with different letters
609                      );
610     }
611
612     function setCaption ($caption_string) {
613         $this->_caption = $caption_string;
614     }
615
616     function getCaption () {
617         // put the total into the caption if needed
618         if (is_string($this->_caption) && strstr($this->_caption, '%d'))
619             return sprintf($this->_caption, $this->getTotal());
620         return $this->_caption;
621     }
622
623     function setMessageIfEmpty ($msg) {
624         $this->_messageIfEmpty = $msg;
625     }
626
627
628     function getTotal () {
629         return !empty($this->_options['count'])
630                ? (integer) $this->_options['count'] : count($this->_pages);
631     }
632
633     function isEmpty () {
634         return empty($this->_pages);
635     }
636
637     function addPage($page_handle) {
638         if (!empty($this->_excluded_pages)) {
639             if (!in_array((is_string($page_handle) ? $page_handle : $page_handle->getName()),
640                           $this->_excluded_pages))
641                 $this->_pages[] = new _PageList_Page($this, $page_handle);
642         } else {
643             $this->_pages[] = new _PageList_Page($this, $page_handle);        
644         }
645     }
646
647     function _getPageFromHandle($ph) {
648         $page_handle = $ph;
649         if (is_string($page_handle)) {
650             if (empty($page_handle)) return $page_handle;
651             $dbi = $GLOBALS['request']->getDbh();
652             $page_handle = $dbi->getPage($page_handle);
653         }
654         return $page_handle;
655     }
656
657     /**
658      * Take a PageList_Page object, and return an HTML object to display
659      * it in a table or list row.
660      */
661     function _renderPageRow ($pagelist_page, $i = 0) {
662         $page_handle = $pagelist_page->getPage();
663
664         $page_handle = $this->_getPageFromHandle($page_handle);
665         if (!isset($page_handle) || empty($page_handle)
666             || in_array($page_handle->getName(), $this->_excluded_pages))
667             return; // exclude page.
668             
669         //FIXME. only on sf.net
670         if (!is_object($page_handle)) {
671             trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
672             return;
673         }
674         // enforce view permission
675         if (!mayAccessPage('view', $page_handle->getName()))
676             return;
677
678         $group = (int)($i / $this->_group_rows);
679         $class = ($group % 2) ? 'oddrow' : 'evenrow';
680         $revision_handle = false;
681         $this->_maxlen = max($this->_maxlen, strlen($page_handle->getName()));
682
683         if (count($this->_columns) > 1) {
684             $row = HTML::tr(array('class' => $class));
685             foreach ($this->_columns as $col)
686                 $row->pushContent($col->format($this, $page_handle, $revision_handle));
687         }
688         else {
689             $col = $this->_columns[0];
690             $row = $col->_getValue($page_handle, $revision_handle);
691         }
692
693         return $row;
694     }
695
696     function addPages ($page_iter) {
697         //Todo: if limit check max(strlen(pagename))
698         while ($page = $page_iter->next()) {
699             $this->addPage($page);
700         }
701     }
702
703     function addPageList (&$list) {
704         if (empty($list)) return;  // Protect reset from a null arg
705         foreach ($list as $page) {
706             $this->addPage((string)$page);
707         }
708     }
709
710     function maxLen() {
711         global $request;
712         $dbi =& $request->getDbh();
713         if (isa($dbi,'WikiDB_SQL')) {
714             extract($dbi->_backend->_table_names);
715             $res = $dbi->_backend->_dbh->getOne("SELECT max(length(pagename)) FROM $page_tbl");
716             if (DB::isError($res) || empty($res)) return false;
717             else return $res;
718         } elseif (isa($dbi,'WikiDB_ADODB')) {
719             extract($dbi->_backend->_table_names);
720             $row = $dbi->_backend->_dbh->getRow("SELECT max(length(pagename)) FROM $page_tbl");
721             return $row ? $row[0] : false;
722         } else 
723             return false;
724     }
725
726     function getContent() {
727         // Note that the <caption> element wants inline content.
728         $caption = $this->getCaption();
729
730         if ($this->isEmpty())
731             return $this->_emptyList($caption);
732         elseif (count($this->_columns) == 1)
733             return $this->_generateList($caption);
734         else
735             return $this->_generateTable($caption);
736     }
737
738     function printXML() {
739         PrintXML($this->getContent());
740     }
741
742     function asXML() {
743         return AsXML($this->getContent());
744     }
745     
746     /** Now all columns are sortable. 
747      *  These are the colums which have native WikiDB backend methods.
748      *  FIXME: use this method at the db backends
749      */
750     //function sortable_columns() {
751     //    return array('pagename','mtime','hits');
752     //}
753
754     /** 
755      * Handle sortby requests for the DB iterator and table header links.
756      * Prefix the column with + or - like "+pagename","-mtime", ...
757      * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
758      *                    'db'         "-pagename" => "pagename DESC"
759      * Now all columns are sortable. (patch by DanFr)
760      */
761     function sortby ($column, $action) {
762         if (empty($column)) return '';
763         //support multiple comma-delimited sortby args: "+hits,+pagename"
764         if (strstr($column,',')) {
765             $result = array();
766             foreach (explode(',',$column) as $col) {
767                 $result[] = $this->sortby($col,$action);
768             }
769             return join(",",$result);
770         }
771         if (substr($column,0,1) == '+') {
772             $order = '+'; $column = substr($column,1);
773         } elseif (substr($column,0,1) == '-') {
774             $order = '-'; $column = substr($column,1);
775         }
776         // default order: +pagename, -mtime, -hits
777         if (empty($order))
778             if (in_array($column,array('mtime','hits')))
779                 $order = '-';
780             else
781                 $order = '+';
782         if ($action == 'flip_order') {
783             return ($order == '+' ? '-' : '+') . $column;
784         } elseif ($action == 'init') {
785             $this->_sortby[$column] = $order;
786             return $order . $column;
787         } elseif ($action == 'check') {
788             return (!empty($this->_sortby[$column]) or 
789                     ($GLOBALS['request']->getArg('sortby') and 
790                      strstr($GLOBALS['request']->getArg('sortby'),$column)));
791         } elseif ($action == 'db') {
792             // native sort possible?
793             $sortable_columns = $GLOBALS['request']->_dbi->_backend->sortable_columns();
794             /*
795             if (method_exists($this,'sortable_columns'))
796                 $sortable_columns = $this->sortable_columns();
797             else
798                 $sortable_columns = PageList::sortable_columns();
799             */
800             if (in_array($column, $sortable_columns))
801                 // asc or desc: +pagename, -pagename
802                 return $column . ($order == '+' ? ' ASC' : ' DESC');
803             else 
804                 return '';
805         }
806         return '';
807     }
808
809     // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
810     function explodePageList($input, $include_empty = false, $sortby=false, $limit=false) {
811         // expand wildcards from list of all pages
812         if (preg_match('/[\?\*]/',$input)) {
813             $dbi = $GLOBALS['request']->getDbh();
814             $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit);
815             while ($pagehandle = $allPagehandles->next()) {
816                 $allPages[] = $pagehandle->getName();
817             }
818             return explodeList($input, $allPages);
819         } else {
820             //TODO: do the sorting, normally not needed if used for exclude only
821             return explode(',',$input);
822         }
823     }
824
825     function allPagesByAuthor(&$wildcard, $include_empty=false, $sortby=false, $limit=false) {
826         $dbi = $GLOBALS['request']->getDbh();
827         $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit);
828         $allPages = array();
829         if ($wildcard === '[]') {
830             $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
831             if (!$wildcard) return $allPages;
832         }
833         $do_glob = preg_match('/[\?\*]/', $wildcard);
834         while ($pagehandle = $allPagehandles->next()) {
835             $name = $pagehandle->getName();
836             $author = $pagehandle->getAuthor();
837             if ($author) {
838                 if ($do_glob) {
839                     if (glob_match($wildcard, $author))
840                         $allPages[] = $name;
841                 } elseif ($wildcard == $author) {
842                       $allPages[] = $name;
843                 }
844             }
845             // TODO: purge versiondata_cache
846         }
847         return $allPages;
848     }
849
850     function allPagesByOwner(&$wildcard, $include_empty=false, $sortby=false, $limit=false) {
851         $dbi = $GLOBALS['request']->getDbh();
852         $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit);
853         $allPages = array();
854         if ($wildcard === '[]') {
855             $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
856             if (!$wildcard) return $allPages;
857         }
858         $do_glob = preg_match('/[\?\*]/', $wildcard);
859         while ($pagehandle = $allPagehandles->next()) {
860             $name = $pagehandle->getName();
861             $owner = $pagehandle->getOwner();
862             if ($owner) {
863                 if ($do_glob) {
864                     if (glob_match($wildcard, $owner))
865                         $allPages[] = $name;
866                 } elseif ($wildcard == $owner) {
867                       $allPages[] = $name;
868                 }
869             }
870         }
871         return $allPages;
872     }
873
874     function allPagesByCreator(&$wildcard, $include_empty=false, $sortby=false, $limit=false) {
875         $dbi = $GLOBALS['request']->getDbh();
876         $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit);
877         $allPages = array();
878         if ($wildcard === '[]') {
879             $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
880             if (!$wildcard) return $allPages;
881         }
882         $do_glob = preg_match('/[\?\*]/', $wildcard);
883         while ($pagehandle = $allPagehandles->next()) {
884             $name = $pagehandle->getName();
885             $creator = $pagehandle->getCreator();
886             if ($creator) {
887                 if ($do_glob) {
888                     if (glob_match($wildcard, $creator))
889                         $allPages[] = $name;
890                 } elseif ($wildcard == $creator) {
891                       $allPages[] = $name;
892                 }
893             }
894         }
895         return $allPages;
896     }
897
898     ////////////////////
899     // private
900     ////////////////////
901     /** Plugin and theme hooks: 
902      *  If the pageList is initialized with $options['types'] these types are also initialized, 
903      *  overriding the standard types.
904      */
905     function _initAvailableColumns() {
906         global $customPageListColumns;
907         $standard_types =
908             array(
909                   'content'
910                   => new _PageList_Column_content('rev:content', _("Content")),
911                   // new: plugin specific column types initialised by the relevant plugins
912                   /*
913                   'hi_content' // with highlighted search for SearchReplace
914                   => new _PageList_Column_content('rev:hi_content', _("Content")),
915                   'remove'
916                   => new _PageList_Column_remove('remove', _("Remove")),
917                   // initialised by the plugin
918                   'renamed_pagename'
919                   => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
920                   'perm'
921                   => new _PageList_Column_perm('perm', _("Permission")),
922                   'acl'
923                   => new _PageList_Column_acl('acl', _("ACL")),
924                   */
925                   'checkbox'
926                   => new _PageList_Column_checkbox('p', _("Select")),
927                   'pagename'
928                   => new _PageList_Column_pagename,
929                   'mtime'
930                   => new _PageList_Column_time('rev:mtime', _("Last Modified")),
931                   'hits'
932                   => new _PageList_Column('hits', _("Hits"), 'right'),
933                   'size'
934                   => new _PageList_Column_size('rev:size', _("Size"), 'right'),
935                                               /*array('align' => 'char', 'char' => ' ')*/
936                   'summary'
937                   => new _PageList_Column('rev:summary', _("Last Summary")),
938                   'version'
939                   => new _PageList_Column_version('rev:version', _("Version"),
940                                                  'right'),
941                   'author'
942                   => new _PageList_Column_author('rev:author', _("Last Author")),
943                   'owner'
944                   => new _PageList_Column_owner('author_id', _("Owner")),
945                   'creator'
946                   => new _PageList_Column_creator('author_id', _("Creator")),
947                   /*
948                   'group'
949                   => new _PageList_Column_author('group', _("Group")),
950                   */
951                   'locked'
952                   => new _PageList_Column_bool('locked', _("Locked"),
953                                                _("locked")),
954                   'minor'
955                   => new _PageList_Column_bool('rev:is_minor_edit',
956                                                _("Minor Edit"), _("minor")),
957                   'markup'
958                   => new _PageList_Column('rev:markup', _("Markup")),
959                   // 'rating' initialised by the wikilens theme hook: addPageListColumn
960                   /*
961                   'rating'
962                   => new _PageList_Column_rating('rating', _("Rate")),
963                   */
964                   );
965         if (empty($this->_types))
966             $this->_types = array();
967         // add plugin specific pageList columns, initialized by $options['types']
968         $this->_types = array_merge($standard_types, $this->_types);
969         // add theme custom specific pageList columns: 
970         //   set the 4th param as the current pagelist object.
971         if (!empty($customPageListColumns)) {
972             foreach ($customPageListColumns as $column => $params) {
973                 $class_name = array_shift($params);
974                 $params[3] =& $this;
975                 $class = new $class_name($params);
976             }
977             $this->_types = array_merge($this->_types, $customPageListColumns);
978         }
979     }
980
981     function getOption($option) {
982         if (array_key_exists($option, $this->_options)) {
983             return $this->_options[$option];
984         }
985         else {
986             return null;
987         }
988     }
989
990     /**
991      * Add a column to this PageList, given a column name.
992      * The name is a type, and optionally has a : and a label. Examples:
993      *
994      *   pagename
995      *   pagename:This page
996      *   mtime
997      *   mtime:Last modified
998      *
999      * If this function is called multiple times for the same type, the
1000      * column will only be added the first time, and ignored the succeeding times.
1001      * If you wish to add multiple columns of the same type, use addColumnObject().
1002      *
1003      * @param column name
1004      * @return  true if column is added, false otherwise
1005      */
1006     function _addColumn ($column) {
1007         
1008         if (isset($this->_columns_seen[$column]))
1009             return false;       // Already have this one.
1010         if (!isset($this->_types[$column]))
1011             $this->_initAvailableColumns();
1012         $this->_columns_seen[$column] = true;
1013
1014         if (strstr($column, ':'))
1015             list ($column, $heading) = explode(':', $column, 2);
1016
1017         if (!isset($this->_types[$column])) {
1018             $silently_ignore = array('numbacklinks','rating','coagreement','minmisery',
1019                                      'averagerating','top3recs');
1020             if (!in_array($column,$silently_ignore))
1021                 trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
1022             return false;
1023         }
1024         if ($column == 'ratingwidget' and !$GLOBALS['request']->_user->isSignedIn())
1025             return false;
1026
1027         $this->addColumnObject($this->_types[$column]);
1028
1029         return true;
1030     }
1031
1032     /**
1033      * Add a column to this PageList, given a column object.
1034      *
1035      * @param $col object   An object derived from _PageList_Column.
1036      **/
1037     function addColumnObject($col) {
1038         if (is_array($col)) {// custom column object
1039             $params =& $col;
1040             $class_name = array_shift($params);
1041             $params[3] =& $this;
1042             $col = new $class_name($params);
1043         }
1044         $heading = $col->getHeading();
1045         if (!empty($heading))
1046             $col->setHeading($heading);
1047
1048         $this->_columns[] = $col;
1049         $this->_columnsMap[$col->_field] = count($this->_columns)-1;
1050     }
1051
1052     /**
1053      * Compare _PageList_Page objects.
1054      **/
1055     function _pageCompare($a, $b) {
1056         $pagelist =& $a->_pagelist;
1057         $pagea = $a->getPage();
1058         $pageb = $b->getPage();
1059         if (count($pagelist->_sortby) == 0) {
1060             // No columns to sort by
1061             return 0;
1062         }
1063         else {
1064             foreach ($pagelist->_sortby as $colNum => $direction) {
1065                 $colkey = $colNum;
1066                 if (!is_int($colkey)) { // or column fieldname
1067                     $colkey = $pagelist->_columnsMap[$colNum];
1068                 }
1069                 $col = $pagelist->_columns[$colkey];
1070
1071                 $revision_handle = false;
1072                 $pagea = PageList::_getPageFromHandle($pagea);  // If a string, convert to page
1073                 assert(isa($pagea, 'WikiDB_Page'));
1074                 assert(isset($col));
1075                 $aval = $col->_getSortableValue($pagea, $revision_handle);
1076                 $pageb = PageList::_getPageFromHandle($pageb);  // If a string, convert to page
1077                 
1078                 $revision_handle = false;
1079                 assert(isa($pageb, 'WikiDB_Page'));
1080                 $bval = $col->_getSortableValue($pageb, $revision_handle);
1081
1082                 $cmp = $col->_compare($aval, $bval);
1083                 if ($direction === "-") {
1084                     // Reverse the sense of the comparison
1085                     $cmp *= -1;
1086                 }
1087
1088                 if ($cmp !== 0) {
1089                     // This is the first comparison that is not equal-- go with it
1090                     return $cmp;
1091                 }
1092             }
1093             return 0;
1094         }
1095     }
1096
1097     /**
1098      * Put pages in order according to the sortby arg, if given
1099      */
1100     function _sortPages() {
1101         //TODO: if the sortby cols are already sorted by the DB call don't do usort.
1102         if (count($this->_sortby) > 0) {
1103             $need_sort = 0;
1104             foreach ($this->_sortby as $col) {
1105                 if (!$this->sortby($col, 'db'))
1106                     $need_sort = 1;
1107             }
1108             if ($need_sort) {
1109                 // There are columns to sort by
1110                 usort($this->_pages, array('PageList', '_pageCompare'));
1111             }
1112         }        
1113     }
1114
1115     function limit($limit) {
1116         if (strstr($limit, ','))
1117             return split(',', $limit);
1118         else
1119             return array(0, $limit);
1120     }
1121
1122     function PageingTokens($numrows = false, $ncolumns = false, $limit = false) {
1123         if ($numrows === false)
1124             $numrows = $this->getTotal();
1125         if ($limit === false)
1126             $limit = $this->_options['limit'];
1127         if ($ncolumns === false)
1128             $ncolumns = count($this->_columns);
1129
1130         list($offset,$pagesize) = $this->limit($limit);
1131         if (!$pagesize or
1132             (!$offset and $numrows <= $pagesize) or
1133             ($offset + $pagesize < 0))
1134             return false;
1135
1136         $request = &$GLOBALS['request'];
1137         $pagename = $request->getArg('pagename');
1138         $defargs = $request->args;
1139         $prev = $defargs;
1140
1141         $tokens = array();
1142         $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
1143         $tokens['COLS'] = count($this->_columns);
1144         $tokens['COUNT'] = $numrows; 
1145         $tokens['OFFSET'] = $offset; 
1146         $tokens['SIZE'] = $pagesize;
1147         $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
1148         $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
1149         if ($offset > 0) {
1150             $prev['limit'] = min(0,$offset - $pagesize) . ",$pagesize";
1151             $prev['count'] = $numrows;
1152             $tokens['LIMIT'] = $prev['limit'];
1153             $tokens['PREV'] = true;
1154             $tokens['PREV_LINK'] = WikiURL($pagename, $prev);
1155             $prev['limit'] = "0,$pagesize";
1156             $tokens['FIRST_LINK'] = WikiURL($pagename, $prev);
1157         }
1158         $next = $defargs;
1159         $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
1160         if ($offset + $pagesize < $numrows) {
1161             $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) . ",$pagesize";
1162             $next['count'] = $numrows;
1163             $tokens['LIMIT'] = $next['limit'];
1164             $tokens['NEXT'] = true;
1165             $tokens['NEXT_LINK'] = WikiURL($pagename, $next);
1166             $next['limit'] = $numrows - $pagesize . ",$pagesize";
1167             $tokens['LAST_LINK'] = WikiURL($pagename, $next);
1168         }
1169         return $tokens;
1170     }
1171     
1172     // make a table given the caption
1173     function _generateTable($caption) {
1174         if (count($this->_sortby) > 0) $this->_sortPages();
1175
1176         $rows = array(); $i = 0;
1177         foreach ($this->_pages as $pagenum => $page) {
1178             $rows[] = $this->_renderPageRow($page, $i++);
1179         }
1180
1181         $table = HTML::table(array('cellpadding' => 0,
1182                                    'cellspacing' => 1,
1183                                    'border'      => 0,
1184                                    'class'       => 'pagelist'));
1185         if ($caption)
1186             $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
1187
1188         //Warning: This is quite fragile. It depends solely on a private variable
1189         //         in ->_addColumn()
1190         if (!empty($this->_columns_seen['checkbox'])) {
1191             $table->pushContent($this->_jsFlipAll());
1192         }
1193         $do_paging = ( isset($this->_options['paging']) and 
1194                        !empty($this->_options['limit']) and $this->getTotal() and
1195                        $this->_options['paging'] != 'none' );
1196         $row = HTML::tr();
1197         $table_summary = array();
1198         $i = 0;
1199         foreach ($this->_columns as $col) {
1200             $heading = $col->button_heading($this, $i);
1201             if ($do_paging and 
1202                 isset($col->_field) and $col->_field == 'pagename' and 
1203                 ($maxlen = $this->maxLen()))
1204                 $heading->setAttr('width', $maxlen * 7);
1205             $row->pushContent($heading);
1206             if (is_string($col->getHeading()))
1207                 $table_summary[] = $col->getHeading();
1208             $i++;
1209         }
1210         // Table summary for non-visual browsers.
1211         $table->setAttr('summary', sprintf(_("Columns: %s."), 
1212                                            implode(", ", $table_summary)));
1213
1214         if ( $do_paging ) {
1215             /*
1216             list($offset,$pagesize) = $this->limit($this->_options['limit']);
1217             // if there are more pages than the limit, show a table-header, -footer
1218             $numrows = $this->getTotal();
1219             if (!$pagesize or
1220                 (!$offset and $numrows <= $pagesize) or
1221                 ($offset + $pagesize < 0)) 
1222             {
1223                 $table->pushContent(HTML::thead($row),
1224                                     HTML::tbody(false, $rows));
1225                 return $table;
1226             }
1227             */
1228             $tokens = $this->PageingTokens($this->getTotal(), 
1229                                            count($this->_columns), 
1230                                            $this->_options['limit']);
1231             if ($tokens === false) {
1232                 $table->pushContent(HTML::thead($row),
1233                                     HTML::tbody(false, $rows));
1234                 return $table;
1235             }
1236
1237             /*
1238             global $request;
1239             include_once('lib/Template.php');
1240             $pagename = $request->getArg('pagename');
1241             $defargs = $request->args;
1242             unset($defargs['pagename']); unset($defargs['action']);
1243             //$defargs['nocache'] = 1;
1244             $prev = $defargs;
1245             $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
1246             $tokens['COLS'] = count($this->_columns);
1247             $tokens['COUNT'] = $numrows; 
1248             $tokens['OFFSET'] = $offset; 
1249             $tokens['SIZE'] = $pagesize;
1250             $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
1251             $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
1252             if ($offset > 0) {
1253                 $prev['limit'] = min(0,$offset - $pagesize) . ",$pagesize";
1254                 $prev['count'] = $numrows;
1255                 $tokens['LIMIT'] = $prev['limit'];
1256                 $tokens['PREV'] = true;
1257                 $tokens['PREV_LINK'] = WikiURL($pagename,$prev);
1258                 $prev['limit'] = "0,$pagesize";
1259                 $tokens['FIRST_LINK'] = WikiURL($pagename,$prev);
1260             }
1261             $next = $defargs;
1262             $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
1263             if ($offset + $pagesize < $numrows) {
1264                 $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) . ",$pagesize";
1265                 $next['count'] = $numrows;
1266                 $tokens['LIMIT'] = $next['limit'];
1267                 $tokens['NEXT'] = true;
1268                 $tokens['NEXT_LINK'] = WikiURL($pagename,$next);
1269                 $next['limit'] = $numrows - $pagesize . ",$pagesize";
1270                 $tokens['LAST_LINK'] = WikiURL($pagename,$next);
1271             }
1272             */
1273
1274             $paging = Template("pagelink", $tokens);
1275             $table->pushContent(HTML::thead($paging),
1276                                 HTML::tbody(false, HTML($row, $rows)),
1277                                 HTML::tfoot($paging));
1278             return $table;
1279         }
1280         $table->pushContent(HTML::thead($row),
1281                             HTML::tbody(false, $rows));
1282         return $table;
1283     }
1284
1285     function _jsFlipAll() {
1286       return JavaScript("
1287 function flipAll(formObj) {
1288   var isFirstSet = -1;
1289   for (var i=0; i < formObj.length; i++) {
1290       fldObj = formObj.elements[i];
1291       if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,2) == 'p[')) { 
1292          if (isFirstSet == -1)
1293            isFirstSet = (fldObj.checked) ? true : false;
1294          fldObj.checked = (isFirstSet) ? false : true;
1295        }
1296    }
1297 }");
1298     }
1299
1300     function _generateList($caption) {
1301         $list = HTML::ul(array('class' => 'pagelist'));
1302         $i = 0;
1303         foreach ($this->_pages as $pagenum => $page) {
1304             $pagehtml = $this->_renderPageRow($page);
1305             $group = ($i++ / $this->_group_rows);
1306             $class = ($group % 2) ? 'oddrow' : 'evenrow';
1307             $list->pushContent(HTML::li(array('class' => $class),$pagehtml));
1308         }
1309         $out = HTML();
1310         //Warning: This is quite fragile. It depends solely on a private variable
1311         //         in ->_addColumn()
1312         // Questionable if its of use here anyway. This is a one-col pagename list only.
1313         //if (!empty($this->_columns_seen['checkbox'])) $out->pushContent($this->_jsFlipAll());
1314         if ($caption)
1315             $out->pushContent(HTML::p($caption));
1316         $out->pushContent($list);
1317         return $out;
1318     }
1319
1320     function _emptyList($caption) {
1321         $html = HTML();
1322         if ($caption)
1323             $html->pushContent(HTML::p($caption));
1324         if ($this->_messageIfEmpty)
1325             $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
1326         return $html;
1327     }
1328
1329     // Condense list: "Page1, Page2, ..." 
1330     // Alternative $seperator = HTML::Raw(' &middot; ')
1331     function _generateCommaList($seperator = ', ') {
1332         return HTML(join($seperator, $list));
1333     }
1334
1335 };
1336
1337 /* List pages with checkboxes to select from.
1338  * The [Select] button toggles via _jsFlipAll
1339  */
1340
1341 class PageList_Selectable
1342 extends PageList {
1343
1344     function PageList_Selectable ($columns=false, $exclude=false, $options = false) {
1345         if ($columns) {
1346             if (!is_array($columns))
1347                 $columns = explode(',', $columns);
1348             if (!in_array('checkbox',$columns))
1349                 array_unshift($columns,'checkbox');
1350         } else {
1351             $columns = array('checkbox','pagename');
1352         }
1353         $this->PageList($columns, $exclude, $options);
1354     }
1355
1356     function addPageList ($array) {
1357         while (list($pagename,$selected) = each($array)) {
1358             if ($selected) $this->addPageSelected((string)$pagename);
1359             $this->addPage((string)$pagename);
1360         }
1361     }
1362
1363     function addPageSelected ($pagename) {
1364         $this->_selected[$pagename] = 1;
1365     }
1366 }
1367
1368 // $Log: not supported by cvs2svn $
1369 // Revision 1.106  2004/09/06 10:22:14  rurban
1370 // oops, forgot global request
1371 //
1372 // Revision 1.105  2004/09/06 08:38:30  rurban
1373 // modularize paging helper (for SqlResult)
1374 //
1375 // Revision 1.104  2004/08/18 11:01:55  rurban
1376 // fixed checkbox list Select button:
1377 //   no GET request on click,
1378 //   only select the list checkbox entries, no other options.
1379 //
1380 // Revision 1.103  2004/07/09 10:06:49  rurban
1381 // Use backend specific sortby and sortable_columns method, to be able to
1382 // select between native (Db backend) and custom (PageList) sorting.
1383 // Fixed PageList::AddPageList (missed the first)
1384 // Added the author/creator.. name to AllPagesBy...
1385 //   display no pages if none matched.
1386 // Improved dba and file sortby().
1387 // Use &$request reference
1388 //
1389 // Revision 1.102  2004/07/08 21:32:35  rurban
1390 // Prevent from more warnings, minor db and sort optimizations
1391 //
1392 // Revision 1.101  2004/07/08 19:04:41  rurban
1393 // more unittest fixes (file backend, metadata RatingsDb)
1394 //
1395 // Revision 1.100  2004/07/07 15:02:26  dfrankow
1396 // Take out if that prevents column sorting
1397 //
1398 // Revision 1.99  2004/07/02 18:49:02  dfrankow
1399 // Change one line so that if addPageList() is passed null, it is still
1400 // okay.  The unit tests do this (ask to list AllUsers where there are no
1401 // users, or something like that).
1402 //
1403 // Revision 1.98  2004/07/01 08:51:22  rurban
1404 // dumphtml: added exclude, print pagename before processing
1405 //
1406 // Revision 1.97  2004/06/29 09:11:10  rurban
1407 // More memory optimization:
1408 //   don't cache unneeded _cached_html and %content for content and size columns
1409 //   (only if sortable, which will fail for too many pages)
1410 //
1411 // Revision 1.96  2004/06/29 08:47:42  rurban
1412 // Memory optimization (reference to parent, smart bool %content)
1413 // Fixed class grouping in table
1414 //
1415 // Revision 1.95  2004/06/28 19:00:01  rurban
1416 // removed non-portable LIMIT 1 (it's getOne anyway)
1417 // removed size from info=most: needs to much memory
1418 //
1419 // Revision 1.94  2004/06/27 10:26:02  rurban
1420 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1421 //
1422 // Revision 1.93  2004/06/25 14:29:17  rurban
1423 // WikiGroup refactoring:
1424 //   global group attached to user, code for not_current user.
1425 //   improved helpers for special groups (avoid double invocations)
1426 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1427 // fixed a XHTML validation error on userprefs.tmpl
1428 //
1429 // Revision 1.92  2004/06/21 17:01:39  rurban
1430 // fix typo and rating method call
1431 //
1432 // Revision 1.91  2004/06/21 16:22:29  rurban
1433 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1434 // fixed dumping buttons locally (images/buttons/),
1435 // support pages arg for dumphtml,
1436 // optional directory arg for dumpserial + dumphtml,
1437 // fix a AllPages warning,
1438 // show dump warnings/errors on DEBUG,
1439 // don't warn just ignore on wikilens pagelist columns, if not loaded.
1440 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1441 //
1442 // Revision 1.90  2004/06/18 14:38:21  rurban
1443 // adopt new PageList style
1444 //
1445 // Revision 1.89  2004/06/17 13:16:08  rurban
1446 // apply wikilens work to PageList: all columns are sortable (slightly fixed)
1447 //
1448 // Revision 1.88  2004/06/14 11:31:35  rurban
1449 // renamed global $Theme to $WikiTheme (gforge nameclash)
1450 // inherit PageList default options from PageList
1451 //   default sortby=pagename
1452 // use options in PageList_Selectable (limit, sortby, ...)
1453 // added action revert, with button at action=diff
1454 // added option regex to WikiAdminSearchReplace
1455 //
1456 // Revision 1.87  2004/06/13 16:02:12  rurban
1457 // empty list of pages if user=[] and not authenticated.
1458 //
1459 // Revision 1.86  2004/06/13 15:51:37  rurban
1460 // Support pagelist filter for current author,owner,creator by []
1461 //
1462 // Revision 1.85  2004/06/13 15:33:19  rurban
1463 // new support for arguments owner, author, creator in most relevant
1464 // PageList plugins. in WikiAdmin* via preSelectS()
1465 //
1466 // Revision 1.84  2004/06/08 13:51:56  rurban
1467 // some comments only
1468 //
1469 // Revision 1.83  2004/05/18 13:35:39  rurban
1470 //  improve Pagelist layout by equal pagename width for limited lists
1471 //
1472 // Revision 1.82  2004/05/16 22:07:35  rurban
1473 // check more config-default and predefined constants
1474 // various PagePerm fixes:
1475 //   fix default PagePerms, esp. edit and view for Bogo and Password users
1476 //   implemented Creator and Owner
1477 //   BOGOUSERS renamed to BOGOUSER
1478 // fixed syntax errors in signin.tmpl
1479 //
1480 // Revision 1.81  2004/05/13 12:30:35  rurban
1481 // fix for MacOSX border CSS attr, and if sort buttons are not found
1482 //
1483 // Revision 1.80  2004/04/20 00:56:00  rurban
1484 // more paging support and paging fix for shorter lists
1485 //
1486 // Revision 1.79  2004/04/20 00:34:16  rurban
1487 // more paging support
1488 //
1489 // Revision 1.78  2004/04/20 00:06:03  rurban
1490 // themable paging support
1491 //
1492 // Revision 1.77  2004/04/18 01:11:51  rurban
1493 // more numeric pagename fixes.
1494 // fixed action=upload with merge conflict warnings.
1495 // charset changed from constant to global (dynamic utf-8 switching)
1496 //
1497
1498 // (c-file-style: "gnu")
1499 // Local Variables:
1500 // mode: php
1501 // tab-width: 8
1502 // c-basic-offset: 4
1503 // c-hanging-comment-ender-p: nil
1504 // indent-tabs-mode: nil
1505 // End:
1506 ?>