]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/PageList.php
fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with...
[SourceForge/phpwiki.git] / lib / PageList.php
1 <?php rcs_id('$Id: PageList.php,v 1.69 2004-03-17 20:23:43 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 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  * 'owner'    _("Owner"),  //todo: implement this again for PagePerm
25  * 'group'    _("Group"),  //todo: implement this for PagePerm
26
27  * More columns for special plugins:
28  *    Todo: move this admin action away, not really an info column
29  * 'checkbox'  A selectable checkbox appears at the left.
30  * 'remove'   _("Remove")     
31  * 'perm'     _("Permission Mask")
32  * 'acl'      _("ACL")
33  * 'renamed_pagename'   _("Rename to")
34  * 'custom'   
35  *
36  * Symbolic 'info=' arguments:
37  * 'all'       All columns except remove, content and renamed_pagename
38  * 'most'      pagename, mtime, author, size, hits, ...
39  * 'some'      pagename, mtime, author
40  *
41  * FIXME: In this refactoring I have un-implemented _ctime, _cauthor, and
42  * number-of-revision.  Note the _ctime and _cauthor as they were implemented
43  * were somewhat flawed: revision 1 of a page doesn't have to exist in the
44  * database.  If lots of revisions have been made to a page, it's more than likely
45  * that some older revisions (include revision 1) have been cleaned (deleted).
46  *
47  * TODO: 
48  *   limit, offset, rows arguments for multiple pages/multiple rows.
49  *
50  *   check PagePerm "list" access-type
51  *
52  *   ->supportedArgs() which arguments are supported, so that the plugin 
53  *                     doesn't explictly need to declare it
54  */
55 class _PageList_Column_base {
56     var $_tdattr = array();
57
58     function _PageList_Column_base ($default_heading, $align = false) {
59         $this->_heading = $default_heading;
60
61         if ($align) {
62             // align="char" isn't supported by any browsers yet :(
63             //if (is_array($align))
64             //    $this->_tdattr = $align;
65             //else
66             $this->_tdattr['align'] = $align;
67         }
68     }
69
70     function format ($pagelist, $page_handle, &$revision_handle) {
71         return HTML::td($this->_tdattr,
72                         HTML::raw('&nbsp;'),
73                         $this->_getValue($page_handle, $revision_handle),
74                         HTML::raw('&nbsp;'));
75     }
76
77     function setHeading ($heading) {
78         $this->_heading = $heading;
79     }
80
81     function heading () {
82         // allow sorting?
83         if (in_array($this->_field,PageList::sortable_columns())) {
84             // multiple comma-delimited sortby args: "+hits,+pagename"
85             // asc or desc: +pagename, -pagename
86             $sortby = PageList::sortby($this->_field,'flip_order');
87             //Fixme: pass all also other GET args along. (limit, p[])
88             $s = HTML::a(array('href' => 
89                                $GLOBALS['request']->GetURLtoSelf(array('sortby' => $sortby,
90                                                                        'nopurge' => '1')),
91                                'class' => 'pagetitle',
92                                'title' => sprintf(_("Sort by %s"),$this->_field)), 
93                          HTML::raw('&nbsp;'), HTML::u($this->_heading), HTML::raw('&nbsp;'));
94         } else {
95             $s = HTML(HTML::raw('&nbsp;'), HTML::u($this->_heading), HTML::raw('&nbsp;'));
96         }
97         return HTML::th(array('align' => 'center'),$s);
98     }
99
100     // new grid-style
101     // see activeui.js 
102     function button_heading () {
103         global $Theme, $request;
104         // allow sorting?
105         if (in_array($this->_field,PageList::sortable_columns())) {
106             // multiple comma-delimited sortby args: "+hits,+pagename"
107             $src = false; 
108             $noimg = HTML::img(array('src' => $Theme->getButtonURL('no_order'),
109                                      'width' => '7', 
110                                      'height' => '7',
111                                      'alt'    => '.'));
112             if ($request->getArg('sortby')) {
113                 if (PageList::sortby($this->_field,'check')) { // show icon?
114                     $sortby = PageList::sortby($request->getArg('sortby'),'flip_order');
115                     $request->setArg('sortby',$sortby);
116                     $desc = (substr($sortby,0,1) == '-');      // asc or desc? (+pagename, -pagename)
117                     $src = $Theme->getButtonURL($desc ? 'asc_order' : 'desc_order');
118                 } else {
119                     $sortby = PageList::sortby($this->_field,'init');
120                 }
121             } else {
122                 $sortby = PageList::sortby($this->_field,'init');
123             }
124             if (!$src) {
125                 $img = $noimg;
126                 $img->setAttr('alt', _("Click to sort"));
127             } else {
128                 $img = HTML::img(array('src' => $src, 
129                                        'width' => '7', 
130                                        'height' => '7', 
131                                        'alt' => _("Click to reverse sort order")));
132             }
133             $s = HTML::a(array('href' => 
134                                //Fixme: pass all also other GET args along. (limit, p[])
135                                //Fixme: convert to POST submit[sortby]
136                                $request->GetURLtoSelf(array('sortby' => $sortby,
137                                                             'nopurge' => '1')),
138                                'class' => 'gridbutton', 
139                                'title' => sprintf(_("Click to sort by %s"),$this->_field)),
140                          HTML::raw('&nbsp;'),
141                          $noimg,
142                          HTML::raw('&nbsp;'),
143                          $this->_heading,
144                          HTML::raw('&nbsp;'),
145                          $img,
146                          HTML::raw('&nbsp;'));
147         } else {
148             $s = HTML(HTML::raw('&nbsp;'), $this->_heading, HTML::raw('&nbsp;'));
149         }
150         return HTML::th(array('align' => 'center', 'valign' => 'middle', 
151                               'class' => 'gridbutton'), $s);
152     }
153 };
154
155 class _PageList_Column extends _PageList_Column_base {
156     function _PageList_Column ($field, $default_heading, $align = false) {
157         $this->_PageList_Column_base($default_heading, $align);
158
159         $this->_need_rev = substr($field, 0, 4) == 'rev:';
160         $this->_iscustom = substr($field, 0, 7) == 'custom:';
161         if ($this->_iscustom)
162             $this->_field = substr($field, 7);
163         elseif ($this->_need_rev)
164             $this->_field = substr($field, 4);
165         else
166             $this->_field = $field;
167     }
168
169     function _getValue ($page_handle, &$revision_handle) {
170         if ($this->_need_rev) {
171             if (!$revision_handle)
172                 $revision_handle = $page_handle->getCurrentRevision();
173             return $revision_handle->get($this->_field);
174         }
175         else {
176             return $page_handle->get($this->_field);
177         }
178     }
179 };
180
181 class _PageList_Column_size extends _PageList_Column {
182     function _getValue ($page_handle, &$revision_handle) {
183         if (!$revision_handle)
184             $revision_handle = $page_handle->getCurrentRevision();
185         return $this->_getSize($revision_handle);
186     }
187
188     function _getSize($revision_handle) {
189         $bytes = @strlen($revision_handle->_data['%content']);
190         return ByteFormatter($bytes);
191     }
192 }
193
194
195 class _PageList_Column_bool extends _PageList_Column {
196     function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
197         $this->_PageList_Column($field, $default_heading, 'center');
198         $this->_textIfTrue = $text;
199         $this->_textIfFalse = new RawXml('&#8212;'); //mdash
200     }
201
202     function _getValue ($page_handle, &$revision_handle) {
203         $val = _PageList_Column::_getValue($page_handle, $revision_handle);
204         return $val ? $this->_textIfTrue : $this->_textIfFalse;
205     }
206 };
207
208 class _PageList_Column_checkbox extends _PageList_Column {
209     function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
210         $this->_name = $name;
211         $heading = HTML::input(array('type'  => 'button',
212                                      'title' => _("Click to de-/select all pages"),
213                                      //'width' => '100%',
214                                      'name'  => $default_heading,
215                                      'value' => $default_heading,
216                                      'onclick' => "flipAll(this.form)"
217                                      ));
218         $this->_PageList_Column($field, $heading, 'center');
219     }
220     function _getValue ($pagelist, $page_handle, &$revision_handle) {
221         $pagename = $page_handle->getName();
222         $selected = !empty($pagelist->_selected[$pagename]);
223         if (strstr($pagename,'[') or strstr($pagename,']')) {
224             $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
225         }
226         if ($selected) {
227             return HTML::input(array('type' => 'checkbox',
228                                      'name' => $this->_name . "[$pagename]",
229                                      'value' => 1,
230                                      'checked' => 'CHECKED'));
231         } else {
232             return HTML::input(array('type' => 'checkbox',
233                                      'name' => $this->_name . "[$pagename]",
234                                      'value' => 1));
235         }
236     }
237     function format ($pagelist, $page_handle, &$revision_handle) {
238         return HTML::td($this->_tdattr,
239                         HTML::raw('&nbsp;'),
240                         $this->_getValue($pagelist, $page_handle, $revision_handle),
241                         HTML::raw('&nbsp;'));
242     }
243 };
244
245 class _PageList_Column_time extends _PageList_Column {
246     function _PageList_Column_time ($field, $default_heading) {
247         $this->_PageList_Column($field, $default_heading, 'right');
248         global $Theme;
249         $this->Theme = &$Theme;
250     }
251
252     function _getValue ($page_handle, &$revision_handle) {
253         $time = _PageList_Column::_getValue($page_handle, $revision_handle);
254         return $this->Theme->formatDateTime($time);
255     }
256 };
257
258 class _PageList_Column_version extends _PageList_Column {
259     function _getValue ($page_handle, &$revision_handle) {
260         if (!$revision_handle)
261             $revision_handle = $page_handle->getCurrentRevision();
262         return $revision_handle->getVersion();
263     }
264 };
265
266 // If needed this could eventually become a subclass
267 // of a new _PageList_Column_action class for other actions.
268 // only for WikiAdminRemove or WikiAdminSelect
269 class _PageList_Column_remove extends _PageList_Column {
270     function _getValue ($page_handle, &$revision_handle) {
271         return Button(array('action' => 'remove'), _("Remove"),
272                       $page_handle->getName());
273     }
274 };
275
276 // only for WikiAdminRename
277 class _PageList_Column_renamed_pagename extends _PageList_Column {
278     function _getValue ($page_handle, &$revision_handle) {
279         $post_args = $GLOBALS['request']->getArg('admin_rename');
280         $value = str_replace($post_args['from'], $post_args['to'],$page_handle->getName());
281         $div = HTML::div(" => ",HTML::input(array('type' => 'text',
282                                                   'name' => 'rename[]',
283                                                   'value' => $value)));
284         $new_page = $GLOBALS['request']->getPage($value);
285         if ($new_page->exists()) {
286             $div->setAttr('class','error');
287             $div->setAttr('title',_("This page already exists"));
288         }
289         return $div;
290     }
291 };
292
293 // Output is hardcoded to limit of first 50 bytes. Otherwise
294 // on very large Wikis this will fail if used with AllPages
295 // (PHP memory limit exceeded)
296 class _PageList_Column_content extends _PageList_Column {
297     function _PageList_Column_content ($field, $default_heading, $align = false) {
298         _PageList_Column::_PageList_Column($field, $default_heading, $align);
299         $this->bytes = 50;
300         if ($field == 'content') {
301             $this->_heading .= sprintf(_(" ... first %d bytes"),
302                                        $this->bytes);
303         } elseif ($field == 'hi_content') {
304             if (!empty($_POST['admin_replace'])) {
305               $search = $_POST['admin_replace']['from'];
306               $this->_heading .= sprintf(_(" ... around %s"),
307                                        '»'.$search.'«');
308             }
309         }
310     }
311     function _getValue ($page_handle, &$revision_handle) {
312         if (!$revision_handle)
313             $revision_handle = $page_handle->getCurrentRevision();
314         // Not sure why implode is needed here, I thought
315         // getContent() already did this, but it seems necessary.
316         $c = implode("\n", $revision_handle->getContent());
317         if ($this->_field == 'hi_content') {
318             $search = $_POST['admin_replace']['from'];
319             if ($search and ($i = strpos($c,$search))) {
320                 $l = strlen($search);
321                 $j = max(0,$i - ($this->bytes / 2));
322                 return HTML::div(array('style' => 'font-size:x-small'),
323                                  HTML::div(array('class' => 'transclusion'),
324                                            HTML::span(substr($c, $j, ($this->bytes / 2))),
325                                            HTML::span(array("style"=>"background:yellow"),$search),
326                                            HTML::span(substr($c, $i+$l, ($this->bytes / 2))))
327                                  );
328             } else {
329                 $c = sprintf(_("%s not found"),
330                              '»'.$search.'«');
331                 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
332                                  $c);
333             }
334         } elseif (($len = strlen($c)) > $this->bytes) {
335             $c = substr($c, 0, $this->bytes);
336         }
337         include_once('lib/BlockParser.php');
338         // false --> don't bother processing hrefs for embedded WikiLinks
339         $ct = TransformText($c, $revision_handle->get('markup'), false);
340         return HTML::div(array('style' => 'font-size:x-small'),
341                          HTML::div(array('class' => 'transclusion'), $ct),
342                          // Don't show bytes here if size column present too
343                          ($this->parent->_columns_seen['size'] or !$len) ? "" :
344                            ByteFormatter($len, /*$longformat = */true));
345     }
346 };
347
348 class _PageList_Column_author extends _PageList_Column {
349     function _PageList_Column_author ($field, $default_heading, $align = false) {
350         _PageList_Column::_PageList_Column($field, $default_heading, $align);
351         global $WikiNameRegexp, $request;
352         $this->WikiNameRegexp = $WikiNameRegexp;
353         $this->dbi = &$request->getDbh();
354     }
355
356     function _getValue ($page_handle, &$revision_handle) {
357         $author = _PageList_Column::_getValue($page_handle, $revision_handle);
358         if (preg_match("/^$this->WikiNameRegexp\$/", $author) && $this->dbi->isWikiPage($author))
359             return WikiLink($author);
360         else
361             return $author;
362     }
363 };
364
365 class _PageList_Column_perm extends _PageList_Column {
366     function _getValue ($page_handle, &$revision_handle) {
367         $perm_array = pagePermissions($page_handle->_pagename);
368         return pagePermissionsSimpleFormat($perm_array,
369                                            $page_handle->get('author'),$page_handle->get('group'));
370         if (0) {
371             ob_start();
372             var_dump($perm_array);
373             $xml = ob_get_contents();
374             ob_end_clean();
375             return $xml;
376         }
377     }
378 };
379
380 class _PageList_Column_acl extends _PageList_Column {
381     function _getValue ($page_handle, &$revision_handle) {
382         $perm_tree = pagePermissions($page_handle->_pagename);
383         return pagePermissionsAclFormat($perm_tree);
384         if (0) {
385             ob_start();
386             var_dump($perm_array);
387             $xml = ob_get_contents();
388             ob_end_clean();
389             return $xml;
390         }
391     }
392 };
393
394 class _PageList_Column_pagename extends _PageList_Column_base {
395     var $_field = 'pagename';
396
397     function _PageList_Column_pagename () {
398         $this->_PageList_Column_base(_("Page Name"));
399         global $request;
400         $this->dbi = &$request->getDbh();
401     }
402
403     function _getValue ($page_handle, &$revision_handle) {
404         if ($this->dbi->isWikiPage($page_handle->getName()))
405             return WikiLink($page_handle);
406         else
407             return WikiLink($page_handle, 'unknown');
408     }
409 };
410
411
412
413 class PageList {
414     var $_group_rows = 3;
415     var $_columns = array();
416     var $_excluded_pages = array();
417     var $_rows = array();
418     var $_caption = "";
419     var $_pagename_seen = false;
420     var $_types = array();
421     var $_options = array();
422     var $_selected = array();
423     var $_sortby = array();
424
425     function PageList ($columns = false, $exclude = false, $options = false) {
426         $this->_initAvailableColumns();
427         $symbolic_columns = 
428             array(
429                   'all' =>  array_diff(array_keys($this->_types), // all but...
430                                        array('checkbox','remove','renamed_pagename',
431                                              'content','hi_content','perm','acl')),
432                   'most' => array('pagename','mtime','author','size','hits'),
433                   'some' => array('pagename','mtime','author')
434                   );
435         if ($columns) {
436             if (!is_array($columns))
437                 $columns = explode(',', $columns);
438             // expand symbolic columns:
439             foreach ($symbolic_columns as $symbol => $cols) {
440                 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
441                     $columns = array_diff(array_merge($columns,$cols),array($symbol));
442                 }
443             }
444             if (!in_array('pagename',$columns))
445                 $this->_addColumn('pagename');
446             foreach ($columns as $col) {
447                 $this->_addColumn($col);
448             }
449         }
450         $this->_addColumn('pagename');
451
452         $this->_options = $options;
453         if (!empty($options) and !empty($options['sortby'])) {
454             $sortby = $options['sortby'];
455         } else {
456             $sortby = $GLOBALS['request']->getArg('sortby');
457         }
458         $this->sortby($sortby,'init');
459         if (!empty($options) and !empty($options['limit'])) {
460             $limit = $options['limit'];
461         } else {
462             $limit = $GLOBALS['request']->getArg('limit');
463         }
464         if ($exclude) {
465             if (!is_array($exclude))
466                 $exclude = $this->explodePageList($exclude,false,$sortby,$limit);
467             $this->_excluded_pages = $exclude;
468         }
469             
470         $this->_messageIfEmpty = _("<no matches>");
471     }
472
473     // Currently PageList takes these arguments:
474     // 1: info, 2: exclude, 3: hash of options
475     // Here we declare which options are supported, so that 
476     // the calling plugin may simply merge this with its own default arguments 
477     function supportedArgs () {
478         return array(//Currently supported options:
479                      'info'              => 'pagename',
480                      'exclude'           => '',          // also wildcards and comma-seperated lists
481
482                      // for the sort buttons in <th>
483                      'sortby'            => '',   // same as for WikiDB::getAllPages
484
485                      //PageList pager options:
486                      // These options may also be given to _generate(List|Table) later
487                      // But limit and offset might help the query WikiDB::getAllPages()
488                      //cols    => 1,       // side-by-side display of list (1-3)
489                      //limit   => 50,      // length of one column
490                      //offset  => 0,       // needed internally for the pager
491                      //paging  => 'auto',  // '':     normal paging mode
492                      //                    // 'auto': drop 'info' columns and enhance rows 
493                      //                    //         when the list becomes large
494                      //                    // 'none': don't page at all
495                      );
496     }
497
498     function setCaption ($caption_string) {
499         $this->_caption = $caption_string;
500     }
501
502     function getCaption () {
503         // put the total into the caption if needed
504         if (is_string($this->_caption) && strstr($this->_caption, '%d'))
505             return sprintf($this->_caption, $this->getTotal());
506         return $this->_caption;
507     }
508
509     function setMessageIfEmpty ($msg) {
510         $this->_messageIfEmpty = $msg;
511     }
512
513
514     function getTotal () {
515         return count($this->_rows);
516     }
517
518     function isEmpty () {
519         return empty($this->_rows);
520     }
521
522     function addPage ($page_handle) {
523         if (is_string($page_handle)) {
524             if (empty($page_handle)) return;
525             if (in_array($page_handle, $this->_excluded_pages))
526                 return;             // exclude page.
527             $dbi = $GLOBALS['request']->getDbh();
528             $page_handle = $dbi->getPage($page_handle);
529         } elseif (is_object($page_handle)) {
530           if (in_array($page_handle->getName(), $this->_excluded_pages))
531             return;             // exclude page.
532         }
533         //FIXME. only on sf.net
534         if (!is_object($page_handle)) {
535             trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
536             return;
537         }
538         // enforce view permission
539         if (!mayAccessPage('view',$page_handle->getName()))
540             return;
541
542         $group = (int)(count($this->_rows) / $this->_group_rows);
543         $class = ($group % 2) ? 'oddrow' : 'evenrow';
544         $revision_handle = false;
545
546         if (count($this->_columns) > 1) {
547             $row = HTML::tr(array('class' => $class));
548             foreach ($this->_columns as $col)
549                 $row->pushContent($col->format($this, $page_handle, $revision_handle));
550         }
551         else {
552             $col = $this->_columns[0];
553             $row = HTML::li(array('class' => $class),
554                             $col->_getValue($page_handle, $revision_handle));
555         }
556
557         $this->_rows[] = $row;
558     }
559
560     function addPages ($page_iter) {
561         while ($page = $page_iter->next())
562             $this->addPage($page);
563     }
564
565     function addPageList (&$list) {
566         reset ($list);
567         while ($page = next($list))
568             $this->addPage($page);
569     }
570
571     function getContent() {
572         // Note that the <caption> element wants inline content.
573         $caption = $this->getCaption();
574
575         if ($this->isEmpty())
576             return $this->_emptyList($caption);
577         elseif (count($this->_columns) == 1)
578             return $this->_generateList($caption);
579         else
580             return $this->_generateTable($caption);
581     }
582
583     function printXML() {
584         PrintXML($this->getContent());
585     }
586
587     function asXML() {
588         return AsXML($this->getContent());
589     }
590
591     function sortable_columns() {
592         return array('pagename','mtime','hits');
593     }
594
595     /** 
596      * Handles sortby requests for the DB iterator and table header links
597      * Prefix the column with + or - like "+pagename","-mtime", ...
598      * supported columns: 'pagename','mtime','hits'
599      * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
600      *                    'db'         "-pagename" => "pagename DESC"
601      */
602     function sortby ($column, $action) {
603         if (empty($column)) return;
604         //support multiple comma-delimited sortby args: "+hits,+pagename"
605         if (strstr($column,',')) {
606             $result = array();
607             foreach (explode(',',$column) as $col) {
608                 $result[] = $this->sortby($col,$action);
609             }
610             return join(",",$result);
611         }
612         if (substr($column,0,1) == '+') {
613             $order = '+'; $column = substr($column,1);
614         } elseif (substr($column,0,1) == '-') {
615             $order = '-'; $column = substr($column,1);
616         }
617         if (in_array($column,PageList::sortable_columns())) {
618             // default order: +pagename, -mtime, -hits
619             if (empty($order))
620                 if (in_array($column,array('mtime','hits')))
621                     $order = '-';
622                 else
623                     $order = '+';
624             if ($action == 'flip_order') {
625                 return ($order == '+' ? '-' : '+') . $column;
626             } elseif ($action == 'init') {
627                 $this->_sortby[$column] = $order;
628                 return $order . $column;
629             } elseif ($action == 'check') {
630                 return (!empty($this->_sortby[$column]) or 
631                         ($GLOBALS['request']->getArg('sortby') and 
632                          strstr($GLOBALS['request']->getArg('sortby'),$column)));
633             } elseif ($action == 'db') {
634                 // asc or desc: +pagename, -pagename
635                 return $column . ($order == '+' ? ' ASC' : ' DESC');
636             }
637         }
638         return '';
639     }
640
641     // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
642     function explodePageList($input, $perm = false, $sortby=false, $limit=false) {
643         // expand wildcards from list of all pages
644         if (preg_match('/[\?\*]/',$input)) {
645             $dbi = $GLOBALS['request']->getDbh();
646             $allPagehandles = $dbi->getAllPages($perm,$sortby,$limit);
647             while ($pagehandle = $allPagehandles->next()) {
648                 $allPages[] = $pagehandle->getName();
649             }
650             return explodeList($input, $allPages);
651         } else {
652             //TODO: do the sorting, normally not needed if used for exclude only
653             return explode(',',$input);
654         }
655     }
656
657
658     ////////////////////
659     // private
660     ////////////////////
661     //Performance Fixme: Initialize only the requested objects
662     function _initAvailableColumns() {
663         if (!empty($this->_types))
664             return;
665
666         $this->_types =
667             array(
668                   'content'
669                   => new _PageList_Column_content('rev:content', _("Content")),
670                   'hi_content' // with highlighted search for SearchReplace
671                   => new _PageList_Column_content('rev:hi_content', _("Content")),
672                   'remove'
673                   => new _PageList_Column_remove('remove', _("Remove")),
674                   'renamed_pagename'
675                   => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
676                   'perm'
677                   => new _PageList_Column_perm('perm', _("Permission")),
678                   'acl'
679                   => new _PageList_Column_acl('acl', _("ACL")),
680                   'checkbox'
681                   => new _PageList_Column_checkbox('p', _("Select")),
682                   'pagename'
683                   => new _PageList_Column_pagename,
684                   'mtime'
685                   => new _PageList_Column_time('rev:mtime', _("Last Modified")),
686                   'hits'
687                   => new _PageList_Column('hits', _("Hits"), 'right'),
688                   'size'
689                   => new _PageList_Column_size('rev:size', _("Size"), 'right'),
690                                               /*array('align' => 'char', 'char' => ' ')*/
691                   'summary'
692                   => new _PageList_Column('rev:summary', _("Last Summary")),
693                   'version'
694                   => new _PageList_Column_version('rev:version', _("Version"),
695                                                  'right'),
696                   'author'
697                   => new _PageList_Column_author('rev:author', _("Last Author")),
698                   'owner'
699                   => new _PageList_Column_author('owner', _("Owner")),
700                   'group'
701                   => new _PageList_Column_author('group', _("Group")),
702                   'locked'
703                   => new _PageList_Column_bool('locked', _("Locked"),
704                                                _("locked")),
705                   'minor'
706                   => new _PageList_Column_bool('rev:is_minor_edit',
707                                                _("Minor Edit"), _("minor")),
708                   'markup'
709                   => new _PageList_Column('rev:markup', _("Markup"))
710                   );
711     }
712
713     function _addColumn ($column) {
714
715         $this->_initAvailableColumns();
716
717         if (isset($this->_columns_seen[$column]))
718             return false;       // Already have this one.
719         $this->_columns_seen[$column] = true;
720
721         if (strstr($column, ':'))
722             list ($column, $heading) = explode(':', $column, 2);
723
724         if (!isset($this->_types[$column])) {
725             trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
726             return false;
727         }
728
729         $col = $this->_types[$column];
730         if (!empty($heading))
731             $col->setHeading($heading);
732
733         $this->_columns[] = $col;
734
735         return true;
736     }
737
738     // make a table given the caption
739     function _generateTable($caption) {
740         $table = HTML::table(array('cellpadding' => 0,
741                                    'cellspacing' => 1,
742                                    'border'      => 0,
743                                    'class'       => 'pagelist'));
744         if ($caption)
745             $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
746
747         //Warning: This is quite fragile. It depends solely on a private variable
748         //         in ->_addColumn()
749         if (!empty($this->_columns_seen['checkbox'])) {
750             $table->pushContent($this->_jsFlipAll());
751         }
752         $row = HTML::tr();
753         $table_summary = array();
754         foreach ($this->_columns as $col) {
755             $row->pushContent($col->button_heading());
756             if (is_string($col->_heading))
757                 $table_summary[] = $col->_heading;
758         }
759         // Table summary for non-visual browsers.
760         $table->setAttr('summary', sprintf(_("Columns: %s."), 
761                                            implode(", ", $table_summary)));
762
763         $table->pushContent(HTML::thead($row),
764                             HTML::tbody(false, $this->_rows));
765         return $table;
766     }
767
768     function _jsFlipAll() {
769       return JavaScript("
770 function flipAll(formObj) {
771   var isFirstSet = -1;
772   for (var i=0;i < formObj.length;i++) {
773       fldObj = formObj.elements[i];
774       if (fldObj.type == 'checkbox') { 
775          if (isFirstSet == -1)
776            isFirstSet = (fldObj.checked) ? true : false;
777          fldObj.checked = (isFirstSet) ? false : true;
778        }
779    }
780 }");
781     }
782
783     function _generateList($caption) {
784         $list = HTML::ul(array('class' => 'pagelist'), $this->_rows);
785         $out = HTML();
786         //Warning: This is quite fragile. It depends solely on a private variable
787         //         in ->_addColumn()
788         // questionable if its of use here anyway. this is a one-col list only.
789         if (!empty($this->_columns_seen['checkbox'])) {
790             $out->pushContent($this->_jsFlipAll());
791         }
792         if ($caption)
793             $out->pushContent(HTML::p($caption));
794         $out->pushContent($list);
795         return $out;
796     }
797
798     function _emptyList($caption) {
799         $html = HTML();
800         if ($caption)
801             $html->pushContent(HTML::p($caption));
802         if ($this->_messageIfEmpty)
803             $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
804         return $html;
805     }
806
807 };
808
809 /* List pages with checkboxes to select from.
810  * The [Select] button toggles via _jsFlipAll
811  */
812
813 class PageList_Selectable
814 extends PageList {
815
816     function PageList_Selectable ($columns=false, $exclude=false) {
817         if ($columns) {
818             if (!is_array($columns))
819                 $columns = explode(',', $columns);
820             if (!in_array('checkbox',$columns))
821                 array_unshift($columns,'checkbox');
822         } else {
823             $columns = array('checkbox','pagename');
824         }
825         PageList::PageList($columns,$exclude);
826     }
827
828     function addPageList ($array) {
829         while (list($pagename,$selected) = each($array)) {
830             if ($selected) $this->addPageSelected($pagename);
831             $this->addPage($pagename);
832         }
833     }
834
835     function addPageSelected ($pagename) {
836         $this->_selected[$pagename] = 1;
837     }
838     //Todo:
839     //insert javascript when clicked on Selected Select/Deselect all
840 }
841
842 // (c-file-style: "gnu")
843 // Local Variables:
844 // mode: php
845 // tab-width: 8
846 // c-basic-offset: 4
847 // c-hanging-comment-ender-p: nil
848 // indent-tabs-mode: nil
849 // End:
850 ?>