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