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