1 <?php rcs_id('$Id: PageList.php,v 1.82 2004-05-16 22:07:35 rurban Exp $');
4 * List a number of pagenames, optionally as table with various columns.
5 * This library relieves some work for these plugins:
7 * AllPages, BackLinks, LikePages, Mostpopular, TitleSearch and more
9 * It also allows dynamic expansion of those plugins to include more
10 * columns in their output.
12 * Column 'info=' arguments:
14 * 'pagename' _("Page Name")
15 * 'mtime' _("Last Modified")
17 * 'summary' _("Last Summary")
18 * 'version' _("Version")),
19 * 'author' _("Last Author")),
20 * 'locked' _("Locked"), _("locked")
21 * 'minor' _("Minor Edit"), _("minor")
22 * 'markup' _("Markup")
24 * 'creator' _("Creator"), //todo: implement this again for PagePerm
25 * 'owner' _("Owner"), //todo: implement this again for PagePerm
26 * 'checkbox' A selectable checkbox appears at the left.
27 * Todo: move this admin action away, not really an info column
30 * Special, custom columns: Either theme or plugin specific.
31 * 'remove' _("Remove")
32 * 'perm' _("Permission Mask")
34 * 'renamed_pagename' _("Rename to")
35 * 'rating' wikilens theme specific.
36 * 'custom' See plugin/WikiTranslation
38 * Symbolic 'info=' arguments:
39 * 'all' All columns except the special columns
40 * 'most' pagename, mtime, author, size, hits, ...
41 * 'some' pagename, mtime, author
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).
50 * check PagePerm "list" access-type
53 * limit, offset, rows arguments for multiple pages/multiple rows.
55 * ->supportedArgs() which arguments are supported, so that the plugin
56 * doesn't explictly need to declare it
58 * list not as <ul> or table, but as simple comma-seperated list
60 class _PageList_Column_base {
61 var $_tdattr = array();
63 function _PageList_Column_base ($default_heading, $align = false) {
64 $this->_heading = $default_heading;
67 // align="char" isn't supported by any browsers yet :(
68 //if (is_array($align))
69 // $this->_tdattr = $align;
71 $this->_tdattr['align'] = $align;
75 function format ($pagelist, $page_handle, &$revision_handle) {
76 return HTML::td($this->_tdattr,
78 $this->_getValue($page_handle, $revision_handle),
82 function setHeading ($heading) {
83 $this->_heading = $heading;
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,
96 'class' => 'pagetitle',
97 'title' => sprintf(_("Sort by %s"),$this->_field)),
98 HTML::raw(' '), HTML::u($this->_heading), HTML::raw(' '));
100 $s = HTML(HTML::raw(' '), HTML::u($this->_heading), HTML::raw(' '));
102 return HTML::th(array('align' => 'center'),$s);
107 function button_heading () {
108 global $Theme, $request;
110 if (in_array($this->_field,PageList::sortable_columns())) {
111 // multiple comma-delimited sortby args: "+hits,+pagename"
113 $noimg_src = $Theme->getButtonURL('no_order');
115 $noimg = HTML::img(array('src' => $noimg_src,
120 else $noimg = HTML::raw(' ');
121 if ($request->getArg('sortby')) {
122 if (PageList::sortby($this->_field,'check')) { // show icon?
123 $sortby = PageList::sortby($request->getArg('sortby'),'flip_order');
124 $request->setArg('sortby',$sortby);
125 $desc = (substr($sortby,0,1) == '-'); // asc or desc? (+pagename, -pagename)
126 $src = $Theme->getButtonURL($desc ? 'asc_order' : 'desc_order');
128 $sortby = PageList::sortby($this->_field,'init');
131 $sortby = PageList::sortby($this->_field,'init');
135 //$img->setAttr('alt', _("Click to sort"));
137 $img = HTML::img(array('src' => $src,
141 'alt' => _("Click to reverse sort order")));
143 $s = HTML::a(array('href' =>
144 //Fixme: pass all also other GET args along. (limit, p[])
145 //Fixme: convert to POST submit[sortby]
146 $request->GetURLtoSelf(array('sortby' => $sortby,
148 'class' => 'gridbutton',
149 'title' => sprintf(_("Click to sort by %s"),$this->_field)),
156 HTML::raw(' '));
158 $s = HTML(HTML::raw(' '), $this->_heading, HTML::raw(' '));
160 return HTML::th(array('align' => 'center', 'valign' => 'middle',
161 'class' => 'gridbutton'), $s);
165 class _PageList_Column extends _PageList_Column_base {
166 function _PageList_Column ($field, $default_heading, $align = false) {
167 $this->_PageList_Column_base($default_heading, $align);
169 $this->_need_rev = substr($field, 0, 4) == 'rev:';
170 $this->_iscustom = substr($field, 0, 7) == 'custom:';
171 if ($this->_iscustom)
172 $this->_field = substr($field, 7);
173 elseif ($this->_need_rev)
174 $this->_field = substr($field, 4);
176 $this->_field = $field;
179 function _getValue ($page_handle, &$revision_handle) {
180 if ($this->_need_rev) {
181 if (!$revision_handle)
182 $revision_handle = $page_handle->getCurrentRevision();
183 return $revision_handle->get($this->_field);
186 return $page_handle->get($this->_field);
191 class _PageList_Column_size extends _PageList_Column {
192 function _getValue ($page_handle, &$revision_handle) {
193 if (!$revision_handle)
194 $revision_handle = $page_handle->getCurrentRevision();
195 return $this->_getSize($revision_handle);
198 function _getSize($revision_handle) {
199 $bytes = @strlen($revision_handle->_data['%content']);
200 return ByteFormatter($bytes);
205 class _PageList_Column_bool extends _PageList_Column {
206 function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
207 $this->_PageList_Column($field, $default_heading, 'center');
208 $this->_textIfTrue = $text;
209 $this->_textIfFalse = new RawXml('—'); //mdash
212 function _getValue ($page_handle, &$revision_handle) {
213 $val = _PageList_Column::_getValue($page_handle, $revision_handle);
214 return $val ? $this->_textIfTrue : $this->_textIfFalse;
218 class _PageList_Column_checkbox extends _PageList_Column {
219 function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
220 $this->_name = $name;
221 $heading = HTML::input(array('type' => 'button',
222 'title' => _("Click to de-/select all pages"),
224 'name' => $default_heading,
225 'value' => $default_heading,
226 'onclick' => "flipAll(this.form)"
228 $this->_PageList_Column($field, $heading, 'center');
230 function _getValue ($pagelist, $page_handle, &$revision_handle) {
231 $pagename = $page_handle->getName();
232 $selected = !empty($pagelist->_selected[$pagename]);
233 if (strstr($pagename,'[') or strstr($pagename,']')) {
234 $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
237 return HTML::input(array('type' => 'checkbox',
238 'name' => $this->_name . "[$pagename]",
240 'checked' => 'CHECKED'));
242 return HTML::input(array('type' => 'checkbox',
243 'name' => $this->_name . "[$pagename]",
247 function format ($pagelist, $page_handle, &$revision_handle) {
248 return HTML::td($this->_tdattr,
250 $this->_getValue($pagelist, $page_handle, $revision_handle),
251 HTML::raw(' '));
255 class _PageList_Column_time extends _PageList_Column {
256 function _PageList_Column_time ($field, $default_heading) {
257 $this->_PageList_Column($field, $default_heading, 'right');
259 $this->Theme = &$Theme;
262 function _getValue ($page_handle, &$revision_handle) {
263 $time = _PageList_Column::_getValue($page_handle, $revision_handle);
264 return $this->Theme->formatDateTime($time);
268 class _PageList_Column_version extends _PageList_Column {
269 function _getValue ($page_handle, &$revision_handle) {
270 if (!$revision_handle)
271 $revision_handle = $page_handle->getCurrentRevision();
272 return $revision_handle->getVersion();
276 // Output is hardcoded to limit of first 50 bytes. Otherwise
277 // on very large Wikis this will fail if used with AllPages
278 // (PHP memory limit exceeded)
279 // FIXME: old PHP without superglobals
280 class _PageList_Column_content extends _PageList_Column {
281 function _PageList_Column_content ($field, $default_heading, $align = false) {
282 _PageList_Column::_PageList_Column($field, $default_heading, $align);
284 if ($field == 'content') {
285 $this->_heading .= sprintf(_(" ... first %d bytes"),
287 } elseif ($field == 'hi_content') {
288 if (!empty($_POST['admin_replace'])) {
289 $search = $_POST['admin_replace']['from'];
290 $this->_heading .= sprintf(_(" ... around %s"),
295 function _getValue ($page_handle, &$revision_handle) {
296 if (!$revision_handle)
297 $revision_handle = $page_handle->getCurrentRevision();
298 // Not sure why implode is needed here, I thought
299 // getContent() already did this, but it seems necessary.
300 $c = implode("\n", $revision_handle->getContent());
301 if ($this->_field == 'hi_content') {
302 $search = $_POST['admin_replace']['from'];
303 if ($search and ($i = strpos($c,$search))) {
304 $l = strlen($search);
305 $j = max(0,$i - ($this->bytes / 2));
306 return HTML::div(array('style' => 'font-size:x-small'),
307 HTML::div(array('class' => 'transclusion'),
308 HTML::span(substr($c, $j, ($this->bytes / 2))),
309 HTML::span(array("style"=>"background:yellow"),$search),
310 HTML::span(substr($c, $i+$l, ($this->bytes / 2))))
313 $c = sprintf(_("%s not found"),
315 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
318 } elseif (($len = strlen($c)) > $this->bytes) {
319 $c = substr($c, 0, $this->bytes);
321 include_once('lib/BlockParser.php');
322 // false --> don't bother processing hrefs for embedded WikiLinks
323 $ct = TransformText($c, $revision_handle->get('markup'), false);
324 return HTML::div(array('style' => 'font-size:x-small'),
325 HTML::div(array('class' => 'transclusion'), $ct),
326 // Don't show bytes here if size column present too
327 ($this->parent->_columns_seen['size'] or !$len) ? "" :
328 ByteFormatter($len, /*$longformat = */true));
332 class _PageList_Column_author extends _PageList_Column {
333 function _PageList_Column_author ($field, $default_heading, $align = false) {
334 _PageList_Column::_PageList_Column($field, $default_heading, $align);
335 $this->dbi =& $GLOBALS['request']->getDbh();
338 function _getValue ($page_handle, &$revision_handle) {
339 $author = _PageList_Column::_getValue($page_handle, $revision_handle);
340 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
341 return WikiLink($author);
347 class _PageList_Column_owner extends _PageList_Column_author {
348 function _getValue ($page_handle, &$revision_handle) {
349 $author = $page_handle->getOwner();
350 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
351 return WikiLink($author);
356 class _PageList_Column_creator extends _PageList_Column_author {
357 function _getValue ($page_handle, &$revision_handle) {
358 $author = $page_handle->getCreator();
359 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
360 return WikiLink($author);
366 // DONE: only if RateIt is used
367 // class _PageList_Column_rating extends _PageList_Column
368 // moved to theme/wikilens/themeinfo.php
370 class _PageList_Column_pagename extends _PageList_Column_base {
371 var $_field = 'pagename';
373 function _PageList_Column_pagename () {
374 $this->_PageList_Column_base(_("Page Name"));
376 $this->dbi = &$request->getDbh();
379 function _getValue ($page_handle, &$revision_handle) {
380 if ($this->dbi->isWikiPage($page_handle->getName()))
381 return WikiLink($page_handle);
383 return WikiLink($page_handle, 'unknown');
390 var $_group_rows = 3;
391 var $_columns = array();
392 var $_excluded_pages = array();
393 var $_rows = array();
395 var $_pagename_seen = false;
396 var $_types = array();
397 var $_options = array();
398 var $_selected = array();
399 var $_sortby = array();
401 function PageList ($columns = false, $exclude = false, $options = false) {
402 // let plugins predefine only certain objects, such its own custom pagelist columns
403 if (!empty($options['types'])) {
404 $this->_types = $options['types'];
405 unset($options['types']);
407 $this->_initAvailableColumns();
410 'all' => array_diff(array_keys($this->_types), // all but...
411 array('checkbox','remove','renamed_pagename',
412 'content','hi_content','perm','acl')),
413 'most' => array('pagename','mtime','author','size','hits'),
414 'some' => array('pagename','mtime','author')
417 if (!is_array($columns))
418 $columns = explode(',', $columns);
419 // expand symbolic columns:
420 foreach ($symbolic_columns as $symbol => $cols) {
421 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
422 $columns = array_diff(array_merge($columns,$cols),array($symbol));
425 if (!in_array('pagename',$columns))
426 $this->_addColumn('pagename');
427 foreach ($columns as $col) {
428 $this->_addColumn($col);
431 $this->_addColumn('pagename');
433 $this->_options = $options;
434 foreach (array('sortby','limit','paging','count') as $key) {
435 if (!empty($options) and !empty($options[$key])) {
436 $this->_options[$key] = $options[$key];
438 $this->_options[$key] = $GLOBALS['request']->getArg($key);
441 $this->_options['sortby'] = $this->sortby($this->_options['sortby'], 'init');
443 if (!is_array($exclude))
444 $exclude = $this->explodePageList($exclude,false,
445 $this->_options['sortby'],
446 $this->_options['limit']);
447 $this->_excluded_pages = $exclude;
449 $this->_messageIfEmpty = _("<no matches>");
452 // Currently PageList takes these arguments:
453 // 1: info, 2: exclude, 3: hash of options
454 // Here we declare which options are supported, so that
455 // the calling plugin may simply merge this with its own default arguments
456 function supportedArgs () {
457 return array(//Currently supported options:
458 'info' => 'pagename',
459 'exclude' => '', // also wildcards and comma-seperated lists
461 // for the sort buttons in <th>
462 'sortby' => '', // same as for WikiDB::getAllPages
464 //PageList pager options:
465 // These options may also be given to _generate(List|Table) later
466 // But limit and offset might help the query WikiDB::getAllPages()
467 'cols' => 1, // side-by-side display of list (1-3)
468 'limit' => 50, // number of rows
469 'paging' => 'auto', // 'auto' normal paging mode
470 // // 'smart' drop 'info' columns and enhance rows
471 // // when the list becomes large
472 // // 'none' don't page at all
473 //'azhead' => 0 // provide shortcut links to pages starting with different letters
477 function setCaption ($caption_string) {
478 $this->_caption = $caption_string;
481 function getCaption () {
482 // put the total into the caption if needed
483 if (is_string($this->_caption) && strstr($this->_caption, '%d'))
484 return sprintf($this->_caption, $this->getTotal());
485 return $this->_caption;
488 function setMessageIfEmpty ($msg) {
489 $this->_messageIfEmpty = $msg;
493 function getTotal () {
494 return !empty($this->_options['count'])
495 ? $this->_options['count'] : count($this->_rows);
498 function isEmpty () {
499 return empty($this->_rows);
502 function addPage ($page_handle) {
503 if (is_string($page_handle)) {
504 if ($page_handle == '') return;
505 if (in_array($page_handle, $this->_excluded_pages))
506 return; // exclude page.
507 $dbi = $GLOBALS['request']->getDbh();
508 $page_handle = $dbi->getPage($page_handle);
509 } elseif (is_object($page_handle)) {
510 if (in_array($page_handle->getName(), $this->_excluded_pages))
511 return; // exclude page.
513 //FIXME. only on sf.net
514 if (!is_object($page_handle)) {
515 trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
518 // enforce view permission
519 if (!mayAccessPage('view',$page_handle->getName()))
522 $group = (int)(count($this->_rows) / $this->_group_rows);
523 $class = ($group % 2) ? 'oddrow' : 'evenrow';
524 $revision_handle = false;
526 if (count($this->_columns) > 1) {
527 $row = HTML::tr(array('class' => $class));
528 foreach ($this->_columns as $col)
529 $row->pushContent($col->format($this, $page_handle, $revision_handle));
532 $col = $this->_columns[0];
533 $row = $col->_getValue($page_handle, $revision_handle);
536 $this->_rows[] = $row;
539 function addPages ($page_iter) {
540 while ($page = $page_iter->next())
541 $this->addPage($page);
544 function addPageList (&$list) {
546 while ($page = next($list))
547 $this->addPage((string)$page);
550 function getContent() {
551 // Note that the <caption> element wants inline content.
552 $caption = $this->getCaption();
554 if ($this->isEmpty())
555 return $this->_emptyList($caption);
556 elseif (count($this->_columns) == 1)
557 return $this->_generateList($caption);
559 return $this->_generateTable($caption);
562 function printXML() {
563 PrintXML($this->getContent());
567 return AsXML($this->getContent());
570 function sortable_columns() {
571 return array('pagename','mtime','hits');
575 * Handle sortby requests for the DB iterator and table header links.
576 * Prefix the column with + or - like "+pagename","-mtime", ...
577 * db supported columns: 'pagename','mtime','hits'
578 * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
579 * 'db' "-pagename" => "pagename DESC"
580 * which other column types should be sortable?
582 function sortby ($column, $action) {
583 if (empty($column)) return;
584 //support multiple comma-delimited sortby args: "+hits,+pagename"
585 if (strstr($column,',')) {
587 foreach (explode(',',$column) as $col) {
588 $result[] = $this->sortby($col,$action);
590 return join(",",$result);
592 if (substr($column,0,1) == '+') {
593 $order = '+'; $column = substr($column,1);
594 } elseif (substr($column,0,1) == '-') {
595 $order = '-'; $column = substr($column,1);
597 if (in_array($column,PageList::sortable_columns())) {
598 // default order: +pagename, -mtime, -hits
600 if (in_array($column,array('mtime','hits')))
604 if ($action == 'flip_order') {
605 return ($order == '+' ? '-' : '+') . $column;
606 } elseif ($action == 'init') {
607 $this->_sortby[$column] = $order;
608 return $order . $column;
609 } elseif ($action == 'check') {
610 return (!empty($this->_sortby[$column]) or
611 ($GLOBALS['request']->getArg('sortby') and
612 strstr($GLOBALS['request']->getArg('sortby'),$column)));
613 } elseif ($action == 'db') {
614 // asc or desc: +pagename, -pagename
615 return $column . ($order == '+' ? ' ASC' : ' DESC');
621 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
622 function explodePageList($input, $perm = false, $sortby=false, $limit=false) {
623 // expand wildcards from list of all pages
624 if (preg_match('/[\?\*]/',$input)) {
625 $dbi = $GLOBALS['request']->getDbh();
626 $allPagehandles = $dbi->getAllPages($perm,$sortby,$limit);
627 while ($pagehandle = $allPagehandles->next()) {
628 $allPages[] = $pagehandle->getName();
630 return explodeList($input, $allPages);
632 //TODO: do the sorting, normally not needed if used for exclude only
633 return explode(',',$input);
641 /** Plugin and theme hooks:
642 * If the pageList is initialized with $options['types'] these types are also initialized,
643 * overriding the standard types.
645 function _initAvailableColumns() {
646 global $customPageListColumns;
650 => new _PageList_Column_content('rev:content', _("Content")),
651 // new: plugin specific column types initialised by the relevant plugins
653 'hi_content' // with highlighted search for SearchReplace
654 => new _PageList_Column_content('rev:hi_content', _("Content")),
656 => new _PageList_Column_remove('remove', _("Remove")),
657 // initialised by the plugin
659 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
661 => new _PageList_Column_perm('perm', _("Permission")),
663 => new _PageList_Column_acl('acl', _("ACL")),
666 => new _PageList_Column_checkbox('p', _("Select")),
668 => new _PageList_Column_pagename,
670 => new _PageList_Column_time('rev:mtime', _("Last Modified")),
672 => new _PageList_Column('hits', _("Hits"), 'right'),
674 => new _PageList_Column_size('rev:size', _("Size"), 'right'),
675 /*array('align' => 'char', 'char' => ' ')*/
677 => new _PageList_Column('rev:summary', _("Last Summary")),
679 => new _PageList_Column_version('rev:version', _("Version"),
682 => new _PageList_Column_author('rev:author', _("Last Author")),
684 => new _PageList_Column_owner('author_id', _("Owner")),
686 => new _PageList_Column_creator('author_id', _("Creator")),
689 => new _PageList_Column_author('group', _("Group")),
692 => new _PageList_Column_bool('locked', _("Locked"),
695 => new _PageList_Column_bool('rev:is_minor_edit',
696 _("Minor Edit"), _("minor")),
698 => new _PageList_Column('rev:markup', _("Markup")),
699 // 'rating' initialised by the wikilens theme hook: addPageListColumn
702 => new _PageList_Column_rating('rating', _("Rate")),
705 if (empty($this->_types))
706 $this->_types = array();
707 // add plugin specific pageList columns, initialized by $options['types']
708 $this->_types = array_merge($standard_types, $this->_types);
709 // add theme specific pageList columns
710 if (!empty($customPageListColumns))
711 $this->_types = array_merge($this->_types, $customPageListColumns);
714 function _addColumn ($column) {
716 if (isset($this->_columns_seen[$column]))
717 return false; // Already have this one.
718 if (!isset($this->_types[$column]))
719 $this->_initAvailableColumns();
720 $this->_columns_seen[$column] = true;
722 if (strstr($column, ':'))
723 list ($column, $heading) = explode(':', $column, 2);
725 if (!isset($this->_types[$column])) {
726 //trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
729 if ($column == 'rating' and !$GLOBALS['request']->_user->isSignedIn())
732 $col = $this->_types[$column];
733 if (!empty($heading))
734 $col->setHeading($heading);
736 $this->_columns[] = $col;
741 function limit($limit) {
742 if (strstr($limit,','))
743 return split(',',$limit);
745 return array(0,$limit);
748 // make a table given the caption
749 function _generateTable($caption) {
750 $table = HTML::table(array('cellpadding' => 0,
753 'class' => 'pagelist'));
755 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
757 //Warning: This is quite fragile. It depends solely on a private variable
759 if (!empty($this->_columns_seen['checkbox'])) {
760 $table->pushContent($this->_jsFlipAll());
763 $table_summary = array();
764 foreach ($this->_columns as $col) {
765 $row->pushContent($col->button_heading());
766 if (is_string($col->_heading))
767 $table_summary[] = $col->_heading;
769 // Table summary for non-visual browsers.
770 $table->setAttr('summary', sprintf(_("Columns: %s."),
771 implode(", ", $table_summary)));
773 if ( isset($this->_options['paging']) and
774 !empty($this->_options['limit']) and $this->getTotal() and
775 $this->_options['paging'] != 'none')
777 // if there are more pages than the limit, show a table-header, -footer
778 list($offset,$pagesize) = $this->limit($this->_options['limit']);
779 $numrows = $this->getTotal();
781 (!$offset and $numrows <= $pagesize) or
782 ($offset + $pagesize < 0))
784 $table->pushContent(HTML::thead($row),
785 HTML::tbody(false, $this->_rows));
789 include_once('lib/Template.php');
792 $pagename = $request->getArg('pagename');
793 $defargs = $request->args;
794 unset($defargs['pagename']); unset($defargs['action']);
795 //$defargs['nocache'] = 1;
797 $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
798 $tokens['COLS'] = count($this->_columns);
799 $tokens['COUNT'] = $numrows;
800 $tokens['OFFSET'] = $offset;
801 $tokens['SIZE'] = $pagesize;
802 $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
803 $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
805 $prev['limit'] = min(0,$offset - $pagesize) . ",$pagesize";
806 $prev['count'] = $numrows;
807 $tokens['LIMIT'] = $prev['limit'];
808 $tokens['PREV'] = true;
809 $tokens['PREV_LINK'] = WikiURL($pagename,$prev);
810 $prev['limit'] = "0,$pagesize";
811 $tokens['FIRST_LINK'] = WikiURL($pagename,$prev);
814 $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
815 if ($offset + $pagesize < $numrows) {
816 $next['limit'] = min($offset + $pagesize,$numrows - $pagesize) . ",$pagesize";
817 $next['count'] = $numrows;
818 $tokens['LIMIT'] = $next['limit'];
819 $tokens['NEXT'] = true;
820 $tokens['NEXT_LINK'] = WikiURL($pagename,$next);
821 $next['limit'] = $numrows - $pagesize . ",$pagesize";
822 $tokens['LAST_LINK'] = WikiURL($pagename,$next);
824 $paging = new Template("pagelink", $request, $tokens);
825 $table->pushContent(HTML::thead($paging),
826 HTML::tbody(false,HTML($row,$this->_rows)),
827 HTML::tfoot($paging));
830 $table->pushContent(HTML::thead($row),
831 HTML::tbody(false, $this->_rows));
835 function _jsFlipAll() {
837 function flipAll(formObj) {
839 for (var i=0;i < formObj.length;i++) {
840 fldObj = formObj.elements[i];
841 if (fldObj.type == 'checkbox') {
842 if (isFirstSet == -1)
843 isFirstSet = (fldObj.checked) ? true : false;
844 fldObj.checked = (isFirstSet) ? false : true;
850 function _generateList($caption) {
851 $list = HTML::ul(array('class' => 'pagelist'));
853 foreach ($this->_rows as $page) {
854 $group = ($i++ / $this->_group_rows);
855 $class = ($group % 2) ? 'oddrow' : 'evenrow';
856 $list->pushContent(HTML::li(array('class' => $class),$page));
859 //Warning: This is quite fragile. It depends solely on a private variable
861 // Questionable if its of use here anyway. This is a one-col pagename list only.
862 //if (!empty($this->_columns_seen['checkbox'])) $out->pushContent($this->_jsFlipAll());
864 $out->pushContent(HTML::p($caption));
865 $out->pushContent($list);
869 function _emptyList($caption) {
872 $html->pushContent(HTML::p($caption));
873 if ($this->_messageIfEmpty)
874 $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
878 // Condense list: "Page1, Page2, ..."
879 // Alternative $seperator = HTML::Raw(' · ')
880 function _generateCommaList($seperator = ', ') {
881 return HTML(join($seperator, $list));
886 /* List pages with checkboxes to select from.
887 * The [Select] button toggles via _jsFlipAll
890 class PageList_Selectable
893 function PageList_Selectable ($columns=false, $exclude=false) {
895 if (!is_array($columns))
896 $columns = explode(',', $columns);
897 if (!in_array('checkbox',$columns))
898 array_unshift($columns,'checkbox');
900 $columns = array('checkbox','pagename');
902 PageList::PageList($columns,$exclude);
905 function addPageList ($array) {
906 while (list($pagename,$selected) = each($array)) {
907 if ($selected) $this->addPageSelected((string)$pagename);
908 $this->addPage((string)$pagename);
912 function addPageSelected ($pagename) {
913 $this->_selected[$pagename] = 1;
916 //insert javascript when clicked on Selected Select/Deselect all
919 // $Log: not supported by cvs2svn $
920 // Revision 1.81 2004/05/13 12:30:35 rurban
921 // fix for MacOSX border CSS attr, and if sort buttons are not found
923 // Revision 1.80 2004/04/20 00:56:00 rurban
924 // more paging support and paging fix for shorter lists
926 // Revision 1.79 2004/04/20 00:34:16 rurban
927 // more paging support
929 // Revision 1.78 2004/04/20 00:06:03 rurban
930 // themable paging support
932 // Revision 1.77 2004/04/18 01:11:51 rurban
933 // more numeric pagename fixes.
934 // fixed action=upload with merge conflict warnings.
935 // charset changed from constant to global (dynamic utf-8 switching)
938 // (c-file-style: "gnu")
943 // c-hanging-comment-ender-p: nil
944 // indent-tabs-mode: nil