1 <?php rcs_id('$Id: PageList.php,v 1.78 2004-04-20 00:06:03 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 * '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
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 = HTML::img(array('src' => $Theme->getButtonURL('no_order'),
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');
124 $sortby = PageList::sortby($this->_field,'init');
127 $sortby = PageList::sortby($this->_field,'init');
131 $img->setAttr('alt', _("Click to sort"));
133 $img = HTML::img(array('src' => $src,
136 'alt' => _("Click to reverse sort order")));
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,
143 'class' => 'gridbutton',
144 'title' => sprintf(_("Click to sort by %s"),$this->_field)),
151 HTML::raw(' '));
153 $s = HTML(HTML::raw(' '), $this->_heading, HTML::raw(' '));
155 return HTML::th(array('align' => 'center', 'valign' => 'middle',
156 'class' => 'gridbutton'), $s);
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);
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);
171 $this->_field = $field;
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);
181 return $page_handle->get($this->_field);
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);
193 function _getSize($revision_handle) {
194 $bytes = @strlen($revision_handle->_data['%content']);
195 return ByteFormatter($bytes);
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('—'); //mdash
207 function _getValue ($page_handle, &$revision_handle) {
208 $val = _PageList_Column::_getValue($page_handle, $revision_handle);
209 return $val ? $this->_textIfTrue : $this->_textIfFalse;
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"),
219 'name' => $default_heading,
220 'value' => $default_heading,
221 'onclick' => "flipAll(this.form)"
223 $this->_PageList_Column($field, $heading, 'center');
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);
232 return HTML::input(array('type' => 'checkbox',
233 'name' => $this->_name . "[$pagename]",
235 'checked' => 'CHECKED'));
237 return HTML::input(array('type' => 'checkbox',
238 'name' => $this->_name . "[$pagename]",
242 function format ($pagelist, $page_handle, &$revision_handle) {
243 return HTML::td($this->_tdattr,
245 $this->_getValue($pagelist, $page_handle, $revision_handle),
246 HTML::raw(' '));
250 class _PageList_Column_time extends _PageList_Column {
251 function _PageList_Column_time ($field, $default_heading) {
252 $this->_PageList_Column($field, $default_heading, 'right');
254 $this->Theme = &$Theme;
257 function _getValue ($page_handle, &$revision_handle) {
258 $time = _PageList_Column::_getValue($page_handle, $revision_handle);
259 return $this->Theme->formatDateTime($time);
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();
271 // Output is hardcoded to limit of first 50 bytes. Otherwise
272 // on very large Wikis this will fail if used with AllPages
273 // (PHP memory limit exceeded)
274 // FIXME: old PHP without superglobals
275 class _PageList_Column_content extends _PageList_Column {
276 function _PageList_Column_content ($field, $default_heading, $align = false) {
277 _PageList_Column::_PageList_Column($field, $default_heading, $align);
279 if ($field == 'content') {
280 $this->_heading .= sprintf(_(" ... first %d bytes"),
282 } elseif ($field == 'hi_content') {
283 if (!empty($_POST['admin_replace'])) {
284 $search = $_POST['admin_replace']['from'];
285 $this->_heading .= sprintf(_(" ... around %s"),
290 function _getValue ($page_handle, &$revision_handle) {
291 if (!$revision_handle)
292 $revision_handle = $page_handle->getCurrentRevision();
293 // Not sure why implode is needed here, I thought
294 // getContent() already did this, but it seems necessary.
295 $c = implode("\n", $revision_handle->getContent());
296 if ($this->_field == 'hi_content') {
297 $search = $_POST['admin_replace']['from'];
298 if ($search and ($i = strpos($c,$search))) {
299 $l = strlen($search);
300 $j = max(0,$i - ($this->bytes / 2));
301 return HTML::div(array('style' => 'font-size:x-small'),
302 HTML::div(array('class' => 'transclusion'),
303 HTML::span(substr($c, $j, ($this->bytes / 2))),
304 HTML::span(array("style"=>"background:yellow"),$search),
305 HTML::span(substr($c, $i+$l, ($this->bytes / 2))))
308 $c = sprintf(_("%s not found"),
310 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
313 } elseif (($len = strlen($c)) > $this->bytes) {
314 $c = substr($c, 0, $this->bytes);
316 include_once('lib/BlockParser.php');
317 // false --> don't bother processing hrefs for embedded WikiLinks
318 $ct = TransformText($c, $revision_handle->get('markup'), false);
319 return HTML::div(array('style' => 'font-size:x-small'),
320 HTML::div(array('class' => 'transclusion'), $ct),
321 // Don't show bytes here if size column present too
322 ($this->parent->_columns_seen['size'] or !$len) ? "" :
323 ByteFormatter($len, /*$longformat = */true));
327 class _PageList_Column_author extends _PageList_Column {
328 function _PageList_Column_author ($field, $default_heading, $align = false) {
329 _PageList_Column::_PageList_Column($field, $default_heading, $align);
330 global $WikiNameRegexp, $request;
331 $this->WikiNameRegexp = $WikiNameRegexp;
332 $this->dbi = &$request->getDbh();
335 function _getValue ($page_handle, &$revision_handle) {
336 $author = _PageList_Column::_getValue($page_handle, $revision_handle);
337 if (preg_match("/^$this->WikiNameRegexp\$/", $author) && $this->dbi->isWikiPage($author))
338 return WikiLink($author);
344 // DONE: only if RateIt is used
345 // class _PageList_Column_rating extends _PageList_Column
346 // moved to theme/wikilens/themeinfo.php
348 class _PageList_Column_pagename extends _PageList_Column_base {
349 var $_field = 'pagename';
351 function _PageList_Column_pagename () {
352 $this->_PageList_Column_base(_("Page Name"));
354 $this->dbi = &$request->getDbh();
357 function _getValue ($page_handle, &$revision_handle) {
358 if ($this->dbi->isWikiPage($page_handle->getName()))
359 return WikiLink($page_handle);
361 return WikiLink($page_handle, 'unknown');
368 var $_group_rows = 3;
369 var $_columns = array();
370 var $_excluded_pages = array();
371 var $_rows = array();
373 var $_pagename_seen = false;
374 var $_types = array();
375 var $_options = array();
376 var $_selected = array();
377 var $_sortby = array();
379 function PageList ($columns = false, $exclude = false, $options = false) {
380 // let plugins predefine only certain objects, such its own custom pagelist columns
381 if (!empty($options['types'])) {
382 $this->_types = $options['types'];
383 unset($options['types']);
385 $this->_initAvailableColumns();
388 'all' => array_diff(array_keys($this->_types), // all but...
389 array('checkbox','remove','renamed_pagename',
390 'content','hi_content','perm','acl')),
391 'most' => array('pagename','mtime','author','size','hits'),
392 'some' => array('pagename','mtime','author')
395 if (!is_array($columns))
396 $columns = explode(',', $columns);
397 // expand symbolic columns:
398 foreach ($symbolic_columns as $symbol => $cols) {
399 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
400 $columns = array_diff(array_merge($columns,$cols),array($symbol));
403 if (!in_array('pagename',$columns))
404 $this->_addColumn('pagename');
405 foreach ($columns as $col) {
406 $this->_addColumn($col);
409 $this->_addColumn('pagename');
411 $this->_options = $options;
412 foreach (array('sortby','limit','paging','count') as $key) {
413 if (!empty($options) and !empty($options[$key])) {
414 $this->_options[$key] = $options[$key];
416 $this->_options[$key] = $GLOBALS['request']->getArg($key);
419 $this->_options['sortby'] = $this->sortby($this->_options['sortby'], 'init');
421 if (!is_array($exclude))
422 $exclude = $this->explodePageList($exclude,false,
423 $this->_options['sortby'],
424 $this->_options['limit']);
425 $this->_excluded_pages = $exclude;
427 $this->_messageIfEmpty = _("<no matches>");
430 // Currently PageList takes these arguments:
431 // 1: info, 2: exclude, 3: hash of options
432 // Here we declare which options are supported, so that
433 // the calling plugin may simply merge this with its own default arguments
434 function supportedArgs () {
435 return array(//Currently supported options:
436 'info' => 'pagename',
437 'exclude' => '', // also wildcards and comma-seperated lists
439 // for the sort buttons in <th>
440 'sortby' => '', // same as for WikiDB::getAllPages
442 //PageList pager options:
443 // These options may also be given to _generate(List|Table) later
444 // But limit and offset might help the query WikiDB::getAllPages()
445 'cols' => 1, // side-by-side display of list (1-3)
446 'limit' => 50, // number of rows
447 'paging' => 'auto', // 'auto' normal paging mode
448 // // 'smart' drop 'info' columns and enhance rows
449 // // when the list becomes large
450 // // 'none' don't page at all
451 //'azhead' => 0 // provide shortcut links to pages starting with different letters
455 function setCaption ($caption_string) {
456 $this->_caption = $caption_string;
459 function getCaption () {
460 // put the total into the caption if needed
461 if (is_string($this->_caption) && strstr($this->_caption, '%d'))
462 return sprintf($this->_caption, $this->getTotal());
463 return $this->_caption;
466 function setMessageIfEmpty ($msg) {
467 $this->_messageIfEmpty = $msg;
471 function getTotal () {
472 return !empty($this->_options['count'])
473 ? $this->_options['count'] : count($this->_rows);
476 function isEmpty () {
477 return empty($this->_rows);
480 function addPage ($page_handle) {
481 if (is_string($page_handle)) {
482 if ($page_handle == '') return;
483 if (in_array($page_handle, $this->_excluded_pages))
484 return; // exclude page.
485 $dbi = $GLOBALS['request']->getDbh();
486 $page_handle = $dbi->getPage($page_handle);
487 } elseif (is_object($page_handle)) {
488 if (in_array($page_handle->getName(), $this->_excluded_pages))
489 return; // exclude page.
491 //FIXME. only on sf.net
492 if (!is_object($page_handle)) {
493 trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
496 // enforce view permission
497 if (!mayAccessPage('view',$page_handle->getName()))
500 $group = (int)(count($this->_rows) / $this->_group_rows);
501 $class = ($group % 2) ? 'oddrow' : 'evenrow';
502 $revision_handle = false;
504 if (count($this->_columns) > 1) {
505 $row = HTML::tr(array('class' => $class));
506 foreach ($this->_columns as $col)
507 $row->pushContent($col->format($this, $page_handle, $revision_handle));
510 $col = $this->_columns[0];
511 $row = $col->_getValue($page_handle, $revision_handle);
514 $this->_rows[] = $row;
517 function addPages ($page_iter) {
518 while ($page = $page_iter->next())
519 $this->addPage($page);
522 function addPageList (&$list) {
524 while ($page = next($list))
525 $this->addPage((string)$page);
528 function getContent() {
529 // Note that the <caption> element wants inline content.
530 $caption = $this->getCaption();
532 if ($this->isEmpty())
533 return $this->_emptyList($caption);
534 elseif (count($this->_columns) == 1)
535 return $this->_generateList($caption);
537 return $this->_generateTable($caption);
540 function printXML() {
541 PrintXML($this->getContent());
545 return AsXML($this->getContent());
548 function sortable_columns() {
549 return array('pagename','mtime','hits');
553 * Handle sortby requests for the DB iterator and table header links.
554 * Prefix the column with + or - like "+pagename","-mtime", ...
555 * db supported columns: 'pagename','mtime','hits'
556 * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
557 * 'db' "-pagename" => "pagename DESC"
558 * which other column types should be sortable?
560 function sortby ($column, $action) {
561 if (empty($column)) return;
562 //support multiple comma-delimited sortby args: "+hits,+pagename"
563 if (strstr($column,',')) {
565 foreach (explode(',',$column) as $col) {
566 $result[] = $this->sortby($col,$action);
568 return join(",",$result);
570 if (substr($column,0,1) == '+') {
571 $order = '+'; $column = substr($column,1);
572 } elseif (substr($column,0,1) == '-') {
573 $order = '-'; $column = substr($column,1);
575 if (in_array($column,PageList::sortable_columns())) {
576 // default order: +pagename, -mtime, -hits
578 if (in_array($column,array('mtime','hits')))
582 if ($action == 'flip_order') {
583 return ($order == '+' ? '-' : '+') . $column;
584 } elseif ($action == 'init') {
585 $this->_sortby[$column] = $order;
586 return $order . $column;
587 } elseif ($action == 'check') {
588 return (!empty($this->_sortby[$column]) or
589 ($GLOBALS['request']->getArg('sortby') and
590 strstr($GLOBALS['request']->getArg('sortby'),$column)));
591 } elseif ($action == 'db') {
592 // asc or desc: +pagename, -pagename
593 return $column . ($order == '+' ? ' ASC' : ' DESC');
599 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
600 function explodePageList($input, $perm = false, $sortby=false, $limit=false) {
601 // expand wildcards from list of all pages
602 if (preg_match('/[\?\*]/',$input)) {
603 $dbi = $GLOBALS['request']->getDbh();
604 $allPagehandles = $dbi->getAllPages($perm,$sortby,$limit);
605 while ($pagehandle = $allPagehandles->next()) {
606 $allPages[] = $pagehandle->getName();
608 return explodeList($input, $allPages);
610 //TODO: do the sorting, normally not needed if used for exclude only
611 return explode(',',$input);
619 /** Plugin and theme hooks:
620 * If the pageList is initialized with $options['types'] these types are also initialized,
621 * overriding the standard types.
623 function _initAvailableColumns() {
624 global $customPageListColumns;
628 => new _PageList_Column_content('rev:content', _("Content")),
629 // new: plugin specific column types initialised by the relevant plugins
631 'hi_content' // with highlighted search for SearchReplace
632 => new _PageList_Column_content('rev:hi_content', _("Content")),
634 => new _PageList_Column_remove('remove', _("Remove")),
635 // initialised by the plugin
637 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
639 => new _PageList_Column_perm('perm', _("Permission")),
641 => new _PageList_Column_acl('acl', _("ACL")),
644 => new _PageList_Column_checkbox('p', _("Select")),
646 => new _PageList_Column_pagename,
648 => new _PageList_Column_time('rev:mtime', _("Last Modified")),
650 => new _PageList_Column('hits', _("Hits"), 'right'),
652 => new _PageList_Column_size('rev:size', _("Size"), 'right'),
653 /*array('align' => 'char', 'char' => ' ')*/
655 => new _PageList_Column('rev:summary', _("Last Summary")),
657 => new _PageList_Column_version('rev:version', _("Version"),
660 => new _PageList_Column_author('rev:author', _("Last Author")),
662 => new _PageList_Column_author('owner', _("Owner")),
664 => new _PageList_Column_author('group', _("Group")),
666 => new _PageList_Column_bool('locked', _("Locked"),
669 => new _PageList_Column_bool('rev:is_minor_edit',
670 _("Minor Edit"), _("minor")),
672 => new _PageList_Column('rev:markup', _("Markup")),
673 // 'rating' initialised by the wikilens theme hook: addPageListColumn
676 => new _PageList_Column_rating('rating', _("Rate")),
679 if (empty($this->_types))
680 $this->_types = array();
681 // add plugin specific pageList columns, initialized by $options['types']
682 $this->_types = array_merge($standard_types, $this->_types);
683 // add theme specific pageList columns
684 if (!empty($customPageListColumns))
685 $this->_types = array_merge($this->_types, $customPageListColumns);
688 function _addColumn ($column) {
690 if (isset($this->_columns_seen[$column]))
691 return false; // Already have this one.
692 if (!isset($this->_types[$column]))
693 $this->_initAvailableColumns();
694 $this->_columns_seen[$column] = true;
696 if (strstr($column, ':'))
697 list ($column, $heading) = explode(':', $column, 2);
699 if (!isset($this->_types[$column])) {
700 //trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
703 if ($column == 'rating' and !$GLOBALS['request']->_user->isSignedIn())
706 $col = $this->_types[$column];
707 if (!empty($heading))
708 $col->setHeading($heading);
710 $this->_columns[] = $col;
715 // make a table given the caption
716 function _generateTable($caption) {
717 $table = HTML::table(array('cellpadding' => 0,
720 'class' => 'pagelist'));
722 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
724 //Warning: This is quite fragile. It depends solely on a private variable
726 if (!empty($this->_columns_seen['checkbox'])) {
727 $table->pushContent($this->_jsFlipAll());
730 $table_summary = array();
731 foreach ($this->_columns as $col) {
732 $row->pushContent($col->button_heading());
733 if (is_string($col->_heading))
734 $table_summary[] = $col->_heading;
736 // Table summary for non-visual browsers.
737 $table->setAttr('summary', sprintf(_("Columns: %s."),
738 implode(", ", $table_summary)));
740 if ( isset($this->_options['paging']) and
741 !empty($this->_options['limit']) and $this->getTotal() and
742 $this->_options['paging'] != 'none')
744 // if there are more pages than the limit, show a table-header, -footer
745 if (strstr($this->_options['limit'],','))
746 list($offset,$pagesize) = split(',',$this->_options['limit']);
749 $pagesize = $this->_options['limit'];
751 $numrows = $this->getTotal();
752 if ($numrows <= $pagesize or ($offset + $pagesize < 0))
756 include_once('lib/Template.php');
759 $pagename = $request->getArg('pagename');
760 $defargs = $request->args;
761 unset($defargs['pagename']); unset($defargs['action']);
762 //$defargs['nocache'] = 1;
764 $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
765 $tokens['COLS'] = count($this->_columns);
766 $tokens['COUNT'] = $numrows;
767 $tokens['OFFSET'] = $offset;
768 $tokens['SIZE'] = $pagesize;
769 $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
770 $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
771 if ($offset >= $pagesize) {
772 $prev['limit'] = $offset - $pagesize . ',' . $pagesize;
773 $prev['count'] = $numrows;
774 $tokens['LIMIT'] = $prev['limit'];
775 $tokens['PREV'] = true;
776 $tokens['PREV_LINK'] = WikiURL($pagename,$prev);
777 $prev['limit'] = "0,$pagesize";
778 $tokens['FIRST_LINK'] = WikiURL($pagename,$prev);
781 $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
782 if ($offset + $pagesize < $numrows) {
783 $next['limit'] = $offset + $pagesize . ',' . $pagesize;
784 $next['count'] = $numrows;
785 $tokens['LIMIT'] = $next['limit'];
786 $tokens['NEXT'] = true;
787 $tokens['NEXT_LINK'] = WikiURL($pagename,$next);
788 $next['limit'] = $numrows - $pagesize . ",$pagesize";
789 $tokens['LAST_LINK'] = WikiURL($pagename,$next);
791 $paging = new Template("pagelink", $request, $tokens);
792 $table->pushContent(HTML::thead($paging),
793 HTML::tbody(false,HTML($row,$this->_rows)),
794 HTML::tfoot($paging));
797 $table->pushContent(HTML::thead($row),
798 HTML::tbody(false, $this->_rows));
802 function _jsFlipAll() {
804 function flipAll(formObj) {
806 for (var i=0;i < formObj.length;i++) {
807 fldObj = formObj.elements[i];
808 if (fldObj.type == 'checkbox') {
809 if (isFirstSet == -1)
810 isFirstSet = (fldObj.checked) ? true : false;
811 fldObj.checked = (isFirstSet) ? false : true;
817 function _generateList($caption) {
818 $list = HTML::ul(array('class' => 'pagelist'));
820 foreach ($this->_rows as $page) {
821 $group = ($i++ / $this->_group_rows);
822 $class = ($group % 2) ? 'oddrow' : 'evenrow';
823 $list->pushContent(HTML::li(array('class' => $class),$page));
826 //Warning: This is quite fragile. It depends solely on a private variable
828 // Questionable if its of use here anyway. This is a one-col pagename list only.
829 //if (!empty($this->_columns_seen['checkbox'])) $out->pushContent($this->_jsFlipAll());
831 $out->pushContent(HTML::p($caption));
832 $out->pushContent($list);
836 function _emptyList($caption) {
839 $html->pushContent(HTML::p($caption));
840 if ($this->_messageIfEmpty)
841 $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
845 // Condense list: "Page1, Page2, ..."
846 // Alternative $seperator = HTML::Raw(' · ')
847 function _generateCommaList($seperator = ', ') {
848 return HTML(join($seperator, $list));
853 /* List pages with checkboxes to select from.
854 * The [Select] button toggles via _jsFlipAll
857 class PageList_Selectable
860 function PageList_Selectable ($columns=false, $exclude=false) {
862 if (!is_array($columns))
863 $columns = explode(',', $columns);
864 if (!in_array('checkbox',$columns))
865 array_unshift($columns,'checkbox');
867 $columns = array('checkbox','pagename');
869 PageList::PageList($columns,$exclude);
872 function addPageList ($array) {
873 while (list($pagename,$selected) = each($array)) {
874 if ($selected) $this->addPageSelected((string)$pagename);
875 $this->addPage((string)$pagename);
879 function addPageSelected ($pagename) {
880 $this->_selected[$pagename] = 1;
883 //insert javascript when clicked on Selected Select/Deselect all
886 // $Log: not supported by cvs2svn $
887 // Revision 1.77 2004/04/18 01:11:51 rurban
888 // more numeric pagename fixes.
889 // fixed action=upload with merge conflict warnings.
890 // charset changed from constant to global (dynamic utf-8 switching)
893 // (c-file-style: "gnu")
898 // c-hanging-comment-ender-p: nil
899 // indent-tabs-mode: nil