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