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, WikiAdmin* 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")
26 * 'checkbox' selectable checkbox at the left.
29 * Special, custom columns: Either theme or plugin (WikiAdmin*) specific.
30 * 'remove' _("Remove")
31 * 'perm' _("Permission Mask")
33 * 'renamed_pagename' _("Rename to")
34 * 'ratingwidget', ... wikilens theme specific.
35 * 'custom' See plugin/_WikiTranslation
37 * Symbolic 'info=' arguments:
38 * 'all' All columns except the special columns
39 * 'most' pagename, mtime, author, size, hits, ...
40 * 'some' pagename, mtime, author
42 * FIXME: In this refactoring I (Jeff) have un-implemented _ctime, _cauthor, and
43 * number-of-revision. Note the _ctime and _cauthor as they were implemented
44 * were somewhat flawed: revision 1 of a page doesn't have to exist in the
45 * database. If lots of revisions have been made to a page, it's more than likely
46 * that some older revisions (include revision 1) have been cleaned (deleted).
49 * paging support: limit, offset args
50 * check PagePerm "list" access-type,
51 * all columns are sortable. Thanks to the wikilens team.
52 * cols > 1, comma, azhead, ordered (OL lists)
53 * ->supportedArgs() which arguments are supported, so that the plugin
54 * doesn't explictly need to declare it
56 * fix sortby logic, fix multiple sortby and other paging args per page.
57 * info=relation,linkto nopage=1
58 * use custom format method (RecentChanges, rss, ...)
61 * fix memory exhaustion on large pagelists with old --memory-limit php's only.
62 * Status: improved 2004-06-25 16:19:36 rurban
64 class _PageList_Column_base {
65 var $_tdattr = array();
67 function _PageList_Column_base ($default_heading, $align = false) {
68 $this->_heading = $default_heading;
71 // align="char" isn't supported by any browsers yet :(
72 //if (is_array($align))
73 // $this->_tdattr = $align;
75 $this->_tdattr['align'] = $align;
79 function format ($pagelist, $page_handle, &$revision_handle) {
80 $nbsp = HTML::raw(' ');
81 return HTML::td($this->_tdattr,
83 $this->_getValue($page_handle, $revision_handle),
87 function getHeading () {
88 return $this->_heading;
91 function setHeading ($heading) {
92 $this->_heading = $heading;
98 $nbsp = HTML::raw(' ');
100 if (1 /* or in_array($this->_field, PageList::sortable_columns())*/) {
101 // multiple comma-delimited sortby args: "+hits,+pagename"
102 // asc or desc: +pagename, -pagename
103 $sortby = PageList::sortby($this->_field, 'flip_order');
104 //Fixme: pass all also other GET args along. (limit, p[])
105 //TODO: support GET and POST
106 $s = HTML::a(array('href' =>
107 $request->GetURLtoSelf(array('sortby' => $sortby)),
108 'class' => 'pagetitle',
109 'title' => sprintf(_("Sort by %s"), $this->_field)),
110 $nbsp, HTML::u($this->_heading), $nbsp);
112 $s = HTML($nbsp, HTML::u($this->_heading), $nbsp);
114 return HTML::th(array('align' => 'center'),$s);
117 // new grid-style sortable heading
118 // TODO: via activeui.js ? (fast dhtml sorting)
119 function button_heading (&$pagelist, $colNum) {
120 global $WikiTheme, $request;
122 $nbsp = HTML::raw(' ');
123 if (!$WikiTheme->DUMP_MODE /* or in_array($this->_field, PageList::sortable_columns()) */) {
124 // TODO: add to multiple comma-delimited sortby args: "+hits,+pagename"
126 $noimg_src = $WikiTheme->getButtonURL('no_order');
128 $noimg = HTML::img(array('src' => $noimg_src,
133 if ($pagelist->sortby($colNum, 'check')) { // show icon? request or plugin arg
134 $sortby = $pagelist->sortby($colNum, 'flip_order');
135 $desc = (substr($sortby,0,1) == '-'); // +pagename or -pagename
136 $src = $WikiTheme->getButtonURL($desc ? 'asc_order' : 'desc_order');
137 $reverse = $desc ? _("reverse")." " : "";
139 // initially unsorted
140 $sortby = $pagelist->sortby($colNum, 'get');
145 $img->setAttr('alt', ".");
147 $img = HTML::img(array('src' => $src,
149 'alt' => _("Click to reverse sort order")));
151 $s = HTML::a(array('href' =>
152 //Fixme: pass all also other GET args along. (limit is ok, p[])
153 $request->GetURLtoSelf(array('sortby' => $sortby,
154 'id' => $pagelist->id)),
155 'class' => 'gridbutton',
156 'title' => sprintf(_("Click to sort by %s"), $reverse . $this->_field)),
158 $nbsp, $this->_heading,
162 $s = HTML($nbsp, $this->_heading, $nbsp);
164 return HTML::th(array('align' => 'center', 'valign' => 'middle',
165 'class' => 'gridbutton'), $s);
169 * Take two columns of this type and compare them.
170 * An undefined value is defined to be < than the smallest defined value.
171 * This base class _compare only works if the value is simple (e.g., a number).
173 * @param $colvala $this->_getValue() of column a
174 * @param $colvalb $this->_getValue() of column b
176 * @return -1 if $a < $b, 1 if $a > $b, 0 otherwise.
178 function _compare($colvala, $colvalb) {
179 if (is_string($colvala))
180 return strcmp($colvala,$colvalb);
182 if (($colvala === $colvalb) || (!isset($colvala) && !isset($colvalb))) {
185 $ret = (!isset($colvala) || ($colvala < $colvalb)) ? -1 : 1;
191 class _PageList_Column extends _PageList_Column_base {
192 function _PageList_Column ($field, $default_heading, $align = false) {
193 $this->_PageList_Column_base($default_heading, $align);
195 $this->_need_rev = substr($field, 0, 4) == 'rev:';
196 $this->_iscustom = substr($field, 0, 7) == 'custom:';
197 if ($this->_iscustom) {
198 $this->_field = substr($field, 7);
200 elseif ($this->_need_rev)
201 $this->_field = substr($field, 4);
203 $this->_field = $field;
206 function _getValue ($page_handle, &$revision_handle) {
207 if ($this->_need_rev) {
208 if (!$revision_handle)
209 // columns which need the %content should override this. (size, hi_content)
210 $revision_handle = $page_handle->getCurrentRevision(false);
211 return $revision_handle->get($this->_field);
214 return $page_handle->get($this->_field);
218 function _getSortableValue ($page_handle, &$revision_handle) {
219 $val = $this->_getValue($page_handle, $revision_handle);
220 if ($this->_field == 'hits')
222 elseif (is_object($val) && method_exists($val, 'asString'))
223 return $val->asString();
225 return (string) $val;
229 /* overcome a call_user_func limitation by not being able to do:
230 * call_user_func_array(array(&$class, $class_name), $params);
231 * So we need $class = new $classname($params);
232 * And we add a 4th param to get at the parent $pagelist object
234 class _PageList_Column_custom extends _PageList_Column {
235 function _PageList_Column_custom($params) {
236 $this->_pagelist =& $params[3];
237 $this->_PageList_Column($params[0], $params[1], $params[2]);
241 class _PageList_Column_size extends _PageList_Column {
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(' '));
249 function _getValue (&$pagelist, $page_handle, &$revision_handle) {
250 if (!$revision_handle or (!$revision_handle->_data['%content']
251 or $revision_handle->_data['%content'] === true)) {
252 $revision_handle = $page_handle->getCurrentRevision(true);
253 unset($revision_handle->_data['%pagedata']['_cached_html']);
255 $size = $this->_getSize($revision_handle);
256 // we can safely purge the content when it is not sortable
257 if (empty($pagelist->_sortby[$this->_field]))
258 unset($revision_handle->_data['%content']);
262 function _getSortableValue ($page_handle, &$revision_handle) {
263 if (!$revision_handle)
264 $revision_handle = $page_handle->getCurrentRevision(true);
265 return (empty($revision_handle->_data['%content']))
266 ? 0 : strlen($revision_handle->_data['%content']);
269 function _getSize($revision_handle) {
270 $bytes = @strlen($revision_handle->_data['%content']);
271 return ByteFormatter($bytes);
276 class _PageList_Column_bool extends _PageList_Column {
277 function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
278 $this->_PageList_Column($field, $default_heading, 'center');
279 $this->_textIfTrue = $text;
280 $this->_textIfFalse = new RawXml('—'); //mdash
283 function _getValue ($page_handle, &$revision_handle) {
284 //FIXME: check if $this is available in the parent (->need_rev)
285 $val = _PageList_Column::_getValue($page_handle, $revision_handle);
286 return $val ? $this->_textIfTrue : $this->_textIfFalse;
290 class _PageList_Column_checkbox extends _PageList_Column {
291 function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
292 $this->_name = $name;
293 $heading = HTML::input(array('type' => 'button',
294 'title' => _("Click to de-/select all pages"),
296 'name' => $default_heading,
297 'value' => $default_heading,
298 'onclick' => "flipAll(this.form)"
300 $this->_PageList_Column($field, $heading, 'center');
302 function _getValue ($pagelist, $page_handle, &$revision_handle) {
303 $pagename = $page_handle->getName();
304 $selected = !empty($pagelist->_selected[$pagename]);
305 if (strstr($pagename,'[') or strstr($pagename,']')) {
306 $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
309 return HTML::input(array('type' => 'checkbox',
310 'name' => $this->_name . "[$pagename]",
312 'checked' => 'checked'));
314 return HTML::input(array('type' => 'checkbox',
315 'name' => $this->_name . "[$pagename]",
319 function format ($pagelist, $page_handle, &$revision_handle) {
320 return HTML::td($this->_tdattr,
322 $this->_getValue($pagelist, $page_handle, $revision_handle),
323 HTML::raw(' '));
325 // don't sort this javascript button
326 function button_heading ($pagelist, $colNum) {
327 $s = HTML(HTML::raw(' '), $this->_heading, HTML::raw(' '));
328 return HTML::th(array('align' => 'center', 'valign' => 'middle',
329 'class' => 'gridbutton'), $s);
333 class _PageList_Column_time extends _PageList_Column {
334 function _PageList_Column_time ($field, $default_heading) {
335 $this->_PageList_Column($field, $default_heading, 'right');
337 $this->WikiTheme = &$WikiTheme;
340 function _getValue ($page_handle, &$revision_handle) {
341 $time = _PageList_Column::_getValue($page_handle, $revision_handle);
342 return $this->WikiTheme->formatDateTime($time);
345 function _getSortableValue ($page_handle, &$revision_handle) {
346 return _PageList_Column::_getValue($page_handle, $revision_handle);
350 class _PageList_Column_version extends _PageList_Column {
351 function _getValue ($page_handle, &$revision_handle) {
352 if (!$revision_handle)
353 $revision_handle = $page_handle->getCurrentRevision();
354 return $revision_handle->getVersion();
358 // Output is hardcoded to limit of first 50 bytes. Otherwise
359 // on very large Wikis this will fail if used with AllPages
360 // (PHP memory limit exceeded)
361 class _PageList_Column_content extends _PageList_Column {
362 function _PageList_Column_content ($field, $default_heading, $align = false, $search = false) {
363 $this->_PageList_Column($field, $default_heading, $align);
365 $this->search = $search;
366 if ($field == 'content') {
367 $this->_heading .= sprintf(_(" ... first %d bytes"),
369 } elseif ($field == 'rev:hi_content') {
370 global $HTTP_POST_VARS;
371 if (!$this->search and !empty($HTTP_POST_VARS['admin_replace'])) {
372 $this->search = $HTTP_POST_VARS['admin_replace']['from'];
374 $this->_heading .= sprintf(_(" ... around %s"),
375 '»'.$this->search.'«');
379 function _getValue ($page_handle, &$revision_handle) {
380 if (!$revision_handle or (!$revision_handle->_data['%content']
381 or $revision_handle->_data['%content'] === true)) {
382 $revision_handle = $page_handle->getCurrentRevision(true);
384 // Not sure why implode is needed here, I thought
385 // getContent() already did this, but it seems necessary.
386 $c = implode("\n", $revision_handle->getContent());
387 if (empty($pagelist->_sortby[$this->_field]))
388 unset($revision_handle->_data['%content']);
389 if ($this->_field == 'hi_content') {
390 if (!empty($revision_handle->_data['%pagedata']))
391 unset($revision_handle->_data['%pagedata']['_cached_html']);
392 $search = $this->search;
394 if (!empty($page_handle->score))
395 $score = $page_handle->score;
396 elseif (!empty($page_handle['score']))
397 $score = $page_handle['score'];
398 if ($search and ($i = strpos(strtolower($c), strtolower($search)))) {
399 $l = strlen($search);
400 $j = max(0, $i - ($this->bytes / 2));
401 return HTML::div(array('style' => 'font-size:x-small'),
402 HTML::div(array('class' => 'transclusion'),
403 HTML::span("...".substr($c, $j, ($this->bytes / 2))),
404 HTML::span(array("style"=>"background:yellow"),substr($c, $i, $l)),
405 HTML::span(substr($c, $i+$l, ($this->bytes / 2))."..."." ".($score ? sprintf("[%0.1f]",$score):""))));
410 $c = sprintf(_("%s not found"), '»'.$search.'«');
411 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
412 $c." ".($score ? sprintf("[%0.1f]",$score):""));
414 } elseif (($len = strlen($c)) > $this->bytes) {
415 $c = substr($c, 0, $this->bytes);
417 include_once('lib/BlockParser.php');
418 // false --> don't bother processing hrefs for embedded WikiLinks
419 $ct = TransformText($c, $revision_handle->get('markup'), false);
420 if (empty($pagelist->_sortby[$this->_field]))
421 unset($revision_handle->_data['%pagedata']['_cached_html']);
422 return HTML::div(array('style' => 'font-size:x-small'),
423 HTML::div(array('class' => 'transclusion'), $ct),
424 // Don't show bytes here if size column present too
425 ($this->parent->_columns_seen['size'] or !$len) ? "" :
426 ByteFormatter($len, /*$longformat = */true));
428 function _getSortableValue ($page_handle, &$revision_handle) {
429 if (!empty($page_handle->score))
430 return $page_handle->score;
431 elseif (!empty($page_handle['score']))
432 return $page_handle['score'];
434 return substr(_PageList_Column::_getValue($page_handle, $revision_handle),0,50);
438 class _PageList_Column_author extends _PageList_Column {
439 function _PageList_Column_author ($field, $default_heading, $align = false) {
440 _PageList_Column::_PageList_Column($field, $default_heading, $align);
441 $this->dbi =& $GLOBALS['request']->getDbh();
444 function _getValue ($page_handle, &$revision_handle) {
445 $author = _PageList_Column::_getValue($page_handle, $revision_handle);
446 if ($this->dbi->isWikiPage($author))
447 return WikiLink($author);
452 function _getSortableValue ($page_handle, &$revision_handle) {
453 return _PageList_Column::_getValue($page_handle, $revision_handle);
457 class _PageList_Column_owner extends _PageList_Column_author {
458 function _getValue ($page_handle, &$revision_handle) {
459 $author = $page_handle->getOwner();
460 if ($this->dbi->isWikiPage($author))
461 return WikiLink($author);
465 function _getSortableValue ($page_handle, &$revision_handle) {
466 return _PageList_Column::_getValue($page_handle, $revision_handle);
470 class _PageList_Column_creator extends _PageList_Column_author {
471 function _getValue ($page_handle, &$revision_handle) {
472 $author = $page_handle->getCreator();
473 if ($this->dbi->isWikiPage($author))
474 return WikiLink($author);
478 function _getSortableValue ($page_handle, &$revision_handle) {
479 return _PageList_Column::_getValue($page_handle, $revision_handle);
483 class _PageList_Column_pagename extends _PageList_Column_base {
484 var $_field = 'pagename';
486 function _PageList_Column_pagename () {
487 $this->_PageList_Column_base(_("Page Name"));
489 $this->dbi = &$request->getDbh();
492 function _getValue ($page_handle, &$revision_handle) {
493 if ($this->dbi->isWikiPage($page_handle->getName()))
494 return WikiLink($page_handle, 'known');
496 return WikiLink($page_handle, 'unknown');
499 function _getSortableValue ($page_handle, &$revision_handle) {
500 return $page_handle->getName();
504 * Compare two pagenames for sorting. See _PageList_Column::_compare.
506 function _compare($colvala, $colvalb) {
507 return strcmp($colvala, $colvalb);
512 var $_group_rows = 3;
513 var $_columns = array();
514 var $_columnsMap = array(); // Maps column name to column number.
515 var $_excluded_pages = array();
516 var $_pages = array();
518 var $_pagename_seen = false;
519 var $_types = array();
520 var $_options = array();
521 var $_selected = array();
522 var $_sortby = array();
525 function PageList ($columns = false, $exclude = false, $options = false) {
526 // unique id per pagelist on each page.
527 if (!isset($GLOBALS['request']->_pagelist))
528 $GLOBALS['request']->_pagelist = 0;
530 $GLOBALS['request']->_pagelist++;
531 $this->id = $GLOBALS['request']->_pagelist;
532 if ($GLOBALS['request']->getArg('count'))
533 $options['count'] = $GLOBALS['request']->getArg('count');
535 $this->_options = $options;
537 $this->_initAvailableColumns();
538 // let plugins predefine only certain objects, such its own custom pagelist columns
541 'all' => array_diff(array_keys($this->_types), // all but...
542 array('checkbox','remove','renamed_pagename',
543 'content','hi_content','perm','acl')),
544 'most' => array('pagename','mtime','author','hits'),
545 'some' => array('pagename','mtime','author')
547 if (isset($this->_options['listtype'])
548 and $this->_options['listtype'] == 'dl')
549 $this->_options['nopage'] = 1;
551 if (!is_array($columns))
552 $columns = explode(',', $columns);
553 // expand symbolic columns:
554 foreach ($symbolic_columns as $symbol => $cols) {
555 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
556 $columns = array_diff(array_merge($columns,$cols),array($symbol));
560 if (empty($this->_options['nopage']) and !in_array('pagename',$columns))
561 $this->_addColumn('pagename');
562 foreach ($columns as $col) {
564 $this->_addColumn($col);
568 // If 'pagename' is already present, _addColumn() will not add it again
569 if (empty($this->_options['nopage']))
570 $this->_addColumn('pagename');
572 if (!empty($this->_options['types'])) {
573 foreach ($this->_options['types'] as $type) {
574 $this->_types[$type->_field] = $type;
575 $this->_addColumn($type->_field);
577 unset($this->_options['types']);
581 // explicit header options: ?id=x&sortby=... override options[]
582 // support multiple sorts. check multiple, no nested elseif
583 if (($this->id == $request->getArg("id"))
584 and $request->getArg('sortby'))
586 // add it to the front of the sortby array
587 $this->sortby($request->getArg('sortby'), 'init');
588 $this->_options['sortby'] = $request->getArg('sortby');
590 if (!empty($options['sortby'])) {
591 if (empty($this->_options['sortby']))
592 $this->_options['sortby'] = $options['sortby'];
593 $this->sortby($options['sortby'], 'init');
595 if (!isset($request->args["id"]) and $request->getArg('sortby')
596 and empty($this->_options['sortby']))
598 $this->_options['sortby'] = $request->getArg('sortby');
599 $this->sortby($this->_options['sortby'], 'init');
601 // same as above but without the special sortby push, and mutually exclusive (elseif)
602 foreach ($this->pagingArgs() as $key) {
603 if ($key == 'sortby') continue;
604 if (($this->id == $request->getArg("id"))
605 and $request->getArg($key))
607 $this->_options[$key] = $request->getArg($key);
609 elseif (!empty($options) and !empty($options[$key])) {
610 $this->_options[$key] = $options[$key];
612 elseif (!isset($request->args["id"]) and $request->getArg($key)) {
613 $this->_options[$key] = $request->getArg($key);
616 $this->_options[$key] = false;
619 if (is_string($exclude) and !is_array($exclude))
620 $exclude = $this->explodePageList($exclude, false,
621 $this->_options['sortby'],
622 $this->_options['limit']);
623 $this->_excluded_pages = $exclude;
625 $this->_messageIfEmpty = _("<no matches>");
628 // Currently PageList takes these arguments:
629 // 1: info, 2: exclude, 3: hash of options
630 // Here we declare which options are supported, so that
631 // the calling plugin may simply merge this with its own default arguments
632 function supportedArgs () {
633 // Todo: add all supported Columns, like locked, minor, ...
634 return array(// Currently supported options:
635 /* what columns, what pages */
636 'info' => 'pagename',
637 'exclude' => '', // also wildcards, comma-seperated lists
638 // and <!plugin-list !> arrays
639 /* select pages by meta-data: */
640 'author' => false, // current user by []
641 'owner' => false, // current user by []
642 'creator' => false, // current user by []
644 /* for the sort buttons in <th> */
645 'sortby' => '', // same as for WikiDB::getAllPages
646 // (unsorted is faster)
648 /* PageList pager options:
649 * These options may also be given to _generate(List|Table) later
650 * But limit and offset might help the query WikiDB::getAllPages()
652 'limit' => 50, // number of rows (pagesize)
653 'paging' => 'auto', // 'auto' top + bottom rows if applicable
654 // // 'top' top only if applicable
655 // // 'bottom' bottom only if applicable
656 // // 'none' don't page at all
657 // (TODO: clarify what if $paging==false ?)
659 /* list-style options (with single pagename column only so far) */
660 'cols' => 1, // side-by-side display of list (1-3)
661 'azhead' => 0, // 1: group by initials
662 // 2: provide shortcut links to initials also
663 'comma' => 0, // condensed comma-seperated list,
664 // 1 if without links, 2 if with
665 'commasep' => false, // Default: ', '
666 'listtype' => '', // ul (default), ol, dl, comma
667 'ordered' => false, // OL or just UL lists (ignored for comma)
668 'linkmore' => '', // If count>0 and limit>0 display a link with
669 // the number of all results, linked to the given pagename.
671 'nopage' => false, // for info=col omit the pagename column
672 // array_keys($this->_types). filter by columns: e.g. locked=1
673 'pagename' => null, // string regex
684 function pagingArgs() {
685 return array('sortby','limit','paging','count','dosort');
688 function setCaption ($caption_string) {
689 $this->_caption = $caption_string;
692 function addCaption ($caption_string) {
693 $this->_caption = HTML($this->_caption," ",$caption_string);
696 function getCaption () {
697 // put the total into the caption if needed
698 if (is_string($this->_caption) && strstr($this->_caption, '%d'))
699 return sprintf($this->_caption, $this->getTotal());
700 return $this->_caption;
703 function setMessageIfEmpty ($msg) {
704 $this->_messageIfEmpty = $msg;
708 function getTotal () {
709 return !empty($this->_options['count'])
710 ? (integer) $this->_options['count'] : count($this->_pages);
713 function isEmpty () {
714 return empty($this->_pages);
717 function addPage($page_handle) {
718 if (!empty($this->_excluded_pages)) {
719 if (!in_array((is_string($page_handle) ? $page_handle : $page_handle->getName()),
720 $this->_excluded_pages))
721 $this->_pages[] = $page_handle;
723 $this->_pages[] = $page_handle;
727 function pageNames() {
729 $limit = @$this->_options['limit'];
730 foreach ($this->_pages as $page_handle) {
731 $pages[] = $page_handle->getName();
732 if ($limit and count($pages) > $limit)
738 function _getPageFromHandle($page_handle) {
739 if (is_string($page_handle)) {
740 if (empty($page_handle)) return $page_handle;
741 //$dbi = $GLOBALS['request']->getDbh(); // no, safe some memory!
742 $page_handle = $GLOBALS['request']->_dbi->getPage($page_handle);
748 * Take a PageList_Page object, and return an HTML object to display
749 * it in a table or list row.
751 function _renderPageRow (&$page_handle, $i = 0) {
752 $page_handle = $this->_getPageFromHandle($page_handle);
753 //FIXME. only on sf.net
754 if (!is_object($page_handle)) {
755 trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
758 if (!isset($page_handle)
759 or empty($page_handle)
760 or (!empty($this->_excluded_pages)
761 and in_array($page_handle->getName(), $this->_excluded_pages)))
762 return; // exclude page.
764 // enforce view permission
765 if (!mayAccessPage('view', $page_handle->getName()))
768 $group = (int)($i / $this->_group_rows);
769 $class = ($group % 2) ? 'oddrow' : 'evenrow';
770 $revision_handle = false;
771 $this->_maxlen = max($this->_maxlen, strlen($page_handle->getName()));
773 if (count($this->_columns) > 1) {
774 $row = HTML::tr(array('class' => $class));
776 foreach ($this->_columns as $col) {
777 $col->current_row = $i;
778 $col->current_column = $j;
779 $row->pushContent($col->format($this, $page_handle, $revision_handle));
783 $col = $this->_columns[0];
784 $col->current_row = $i;
785 $col->current_column = 0;
786 $row = $col->_getValue($page_handle, $revision_handle);
792 /* ignore from, but honor limit */
793 function addPages ($page_iter) {
794 // TODO: if limit check max(strlen(pagename))
796 if (isset($this->_options['limit'])) { // extract from,count from limit
797 list($from, $limit) = WikiDB_backend::limit($this->_options['limit']);
802 while ($page = $page_iter->next()) {
804 if ($from and $i < $from)
806 if (!$limit or ($limit and $i < $limit))
807 $this->addPage($page);
809 if (empty($this->_options['count']))
810 $this->_options['count'] = $i;
813 function addPageList (&$list) {
814 if (empty($list)) return; // Protect reset from a null arg
815 if (isset($this->_options['limit'])) { // extract from,count from limit
816 list($from, $limit) = WikiDB_backend::limit($this->_options['limit']);
822 foreach ($list as $page) {
824 if ($from and $i < $from)
826 if (!$limit or ($limit and $i < $limit)) {
827 if (is_object($page)) $page = $page->_pagename;
828 $this->addPage((string)$page);
835 $dbi =& $request->getDbh();
836 if (isa($dbi,'WikiDB_SQL')) {
837 extract($dbi->_backend->_table_names);
838 $res = $dbi->_backend->_dbh->getOne("SELECT max(length(pagename)) FROM $page_tbl");
839 if (DB::isError($res) || empty($res)) return false;
841 } elseif (isa($dbi,'WikiDB_ADODB')) {
842 extract($dbi->_backend->_table_names);
843 $row = $dbi->_backend->_dbh->getRow("SELECT max(length(pagename)) FROM $page_tbl");
844 return $row ? $row[0] : false;
849 function getContent() {
850 // Note that the <caption> element wants inline content.
851 $caption = $this->getCaption();
853 if ($this->isEmpty())
854 return $this->_emptyList($caption);
855 elseif (isset($this->_options['listtype'])
856 and in_array($this->_options['listtype'],
857 array('ol','ul','comma','dl')))
858 return $this->_generateList($caption);
859 elseif (count($this->_columns) == 1)
860 return $this->_generateList($caption);
862 return $this->_generateTable($caption);
865 function printXML() {
866 PrintXML($this->getContent());
870 return AsXML($this->getContent());
874 * Handle sortby requests for the DB iterator and table header links.
875 * Prefix the column with + or - like "+pagename","-mtime", ...
878 * 'init' : unify with predefined order. "pagename" => "+pagename"
879 * 'flip_order' : "mtime" => "+mtime" => "-mtime" ...
880 * 'db' : "-pagename" => "pagename DESC"
883 * Now all columns are sortable. (patch by DanFr)
884 * Some columns have native DB backend methods, some not.
886 function sortby ($column, $action, $valid_fields=false) {
889 if (empty($column)) return '';
890 if (is_int($column)) {
891 $column = $this->_columns[$column - 1]->_field;
892 //$column = $col->_field;
894 //if (!is_string($column)) return '';
895 // support multiple comma-delimited sortby args: "+hits,+pagename"
897 if (strstr($column, ',')) {
898 $result = ($action == 'check') ? true : array();
899 foreach (explode(',', $column) as $col) {
900 if ($action == 'check')
901 $result = $result && $this->sortby($col, $action, $valid_fields);
903 $result[] = $this->sortby($col, $action, $valid_fields);
905 // 'check' returns true/false for every col. return true if all are true.
906 // i.e. the unsupported 'every' operator in functional languages.
907 if ($action == 'check')
910 return join(",", $result);
912 if (substr($column,0,1) == '+') {
913 $order = '+'; $column = substr($column,1);
914 } elseif (substr($column,0,1) == '-') {
915 $order = '-'; $column = substr($column,1);
917 // default initial order: +pagename, -mtime, -hits
919 if (!empty($this->_sortby[$column]))
920 $order = $this->_sortby[$column];
922 if (in_array($column, array('mtime','hits')))
928 if ($action == 'get') {
929 return $order . $column;
930 } elseif ($action == 'flip_order') {
932 trigger_error("flip $order $column ".$this->id, E_USER_NOTICE);
933 return ($order == '+' ? '-' : '+') . $column;
934 } elseif ($action == 'init') { // only allowed from PageList::PageList
935 if ($this->sortby($column, 'clicked')) {
937 trigger_error("clicked $order $column $this->id", E_USER_NOTICE);
938 //$order = ($order == '+' ? '-' : '+'); // $this->sortby($sortby, 'flip_order');
940 $this->_sortby[$column] = $order; // forces show icon
941 return $order . $column;
942 } elseif ($action == 'check') { // show icon?
943 //if specified via arg or if clicked
944 $show = (!empty($this->_sortby[$column]) or $this->sortby($column, 'clicked'));
945 if (0 and $show and DEBUG) {
946 trigger_error("show $order $column ".$this->id, E_USER_NOTICE);
949 } elseif ($action == 'clicked') { // flip sort order?
951 $arg = $request->getArg('sortby');
953 and strstr($arg, $column)
954 and (!isset($request->args['id'])
955 or $this->id == $request->getArg('id')));
956 } elseif ($action == 'db') {
957 // Performance enhancement: use native DB sort if possible.
958 if (($valid_fields and in_array($column, $valid_fields))
959 or (method_exists($request->_dbi->_backend, 'sortable_columns')
960 and (in_array($column, $request->_dbi->_backend->sortable_columns())))) {
961 // omit this sort method from the _sortPages call at rendering
962 // asc or desc: +pagename, -pagename
963 return $column . ($order == '+' ? ' ASC' : ' DESC');
971 /* Splits pagelist string into array.
972 * Test* or Test1,Test2
973 * Limitation: Doesn't split into comma-sep and then expand wildcards.
974 * "Test1*,Test2*" is expanded into TextSearch "Test1* Test2*"
976 * echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
978 function explodePageList($input, $include_empty=false, $sortby='',
979 $limit='', $exclude='')
981 if (empty($input)) return array();
982 if (is_array($input)) return $input;
983 // expand wildcards from list of all pages
984 if (preg_match('/[\?\*]/', $input) or substr($input,0,1) == "^") {
985 include_once("lib/TextSearchQuery.php");
986 $search = new TextSearchQuery(str_replace(",", " ", $input), true,
987 (substr($input,0,1) == "^") ? 'posix' : 'glob');
988 $dbi = $GLOBALS['request']->getDbh();
989 $iter = $dbi->titleSearch($search, $sortby, $limit, $exclude);
991 while ($pagehandle = $iter->next()) {
992 $pages[] = $pagehandle->getName();
996 //TODO: need an SQL optimization here
997 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit,
999 while ($pagehandle = $allPagehandles->next()) {
1000 $allPages[] = $pagehandle->getName();
1002 return explodeList($input, $allPages);
1005 //TODO: do the sorting, normally not needed if used for exclude only
1006 return explode(',', $input);
1010 // TODO: optimize getTotal => store in count
1011 function allPagesByAuthor($wildcard, $include_empty=false, $sortby='',
1012 $limit='', $exclude='')
1014 $dbi = $GLOBALS['request']->getDbh();
1015 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1016 $allPages = array();
1017 if ($wildcard === '[]') {
1018 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
1019 if (!$wildcard) return $allPages;
1021 $do_glob = preg_match('/[\?\*]/', $wildcard);
1022 while ($pagehandle = $allPagehandles->next()) {
1023 $name = $pagehandle->getName();
1024 $author = $pagehandle->getAuthor();
1027 if (glob_match($wildcard, $author))
1028 $allPages[] = $name;
1029 } elseif ($wildcard == $author) {
1030 $allPages[] = $name;
1033 // TODO: purge versiondata_cache
1038 function allPagesByOwner($wildcard, $include_empty=false, $sortby='',
1039 $limit='', $exclude='') {
1040 $dbi = $GLOBALS['request']->getDbh();
1041 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1042 $allPages = array();
1043 if ($wildcard === '[]') {
1044 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
1045 if (!$wildcard) return $allPages;
1047 $do_glob = preg_match('/[\?\*]/', $wildcard);
1048 while ($pagehandle = $allPagehandles->next()) {
1049 $name = $pagehandle->getName();
1050 $owner = $pagehandle->getOwner();
1053 if (glob_match($wildcard, $owner))
1054 $allPages[] = $name;
1055 } elseif ($wildcard == $owner) {
1056 $allPages[] = $name;
1063 function allPagesByCreator($wildcard, $include_empty=false, $sortby='',
1064 $limit='', $exclude='') {
1065 $dbi = $GLOBALS['request']->getDbh();
1066 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1067 $allPages = array();
1068 if ($wildcard === '[]') {
1069 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
1070 if (!$wildcard) return $allPages;
1072 $do_glob = preg_match('/[\?\*]/', $wildcard);
1073 while ($pagehandle = $allPagehandles->next()) {
1074 $name = $pagehandle->getName();
1075 $creator = $pagehandle->getCreator();
1078 if (glob_match($wildcard, $creator))
1079 $allPages[] = $name;
1080 } elseif ($wildcard == $creator) {
1081 $allPages[] = $name;
1088 // UserPages are pages NOT created by "The PhpWiki programming team"
1089 function allUserPages($include_empty=false, $sortby='',
1090 $limit='', $exclude='') {
1091 $dbi = $GLOBALS['request']->getDbh();
1092 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1093 $allPages = array();
1094 while ($pagehandle = $allPagehandles->next()) {
1095 $name = $pagehandle->getName();
1096 $creator = $pagehandle->getCreator();
1097 if ($creator !== _("The PhpWiki programming team")) {
1098 $allPages[] = $name;
1104 ////////////////////
1106 ////////////////////
1107 /** Plugin and theme hooks:
1108 * If the pageList is initialized with $options['types'] these types are also initialized,
1109 * overriding the standard types.
1111 function _initAvailableColumns() {
1112 global $customPageListColumns;
1116 => new _PageList_Column_content('rev:content', _("Content")),
1117 // new: plugin specific column types initialised by the relevant plugins
1119 'hi_content' // with highlighted search for SearchReplace
1120 => new _PageList_Column_content('rev:hi_content', _("Content")),
1122 => new _PageList_Column_remove('remove', _("Remove")),
1123 // initialised by the plugin
1125 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
1127 => new _PageList_Column_perm('perm', _("Permission")),
1129 => new _PageList_Column_acl('acl', _("ACL")),
1132 => new _PageList_Column_checkbox('p', _("All")),
1134 => new _PageList_Column_pagename,
1136 => new _PageList_Column_time('rev:mtime', _("Last Modified")),
1138 => new _PageList_Column('hits', _("Hits"), 'right'),
1140 => new _PageList_Column_size('rev:size', _("Size"), 'right'),
1141 /*array('align' => 'char', 'char' => ' ')*/
1143 => new _PageList_Column('rev:summary', _("Last Summary")),
1145 => new _PageList_Column_version('rev:version', _("Version"),
1148 => new _PageList_Column_author('rev:author', _("Last Author")),
1150 => new _PageList_Column_owner('author_id', _("Owner")),
1152 => new _PageList_Column_creator('author_id', _("Creator")),
1155 => new _PageList_Column_author('group', _("Group")),
1158 => new _PageList_Column_bool('locked', _("Locked"),
1161 => new _PageList_Column_bool('rev:is_minor_edit',
1162 _("Minor Edit"), _("minor")),
1164 => new _PageList_Column('rev:markup', _("Markup")),
1165 // 'rating' initialised by the wikilens theme hook: addPageListColumn
1168 => new _PageList_Column_rating('rating', _("Rate")),
1171 if (empty($this->_types))
1172 $this->_types = array();
1173 // add plugin specific pageList columns, initialized by $options['types']
1174 $this->_types = array_merge($standard_types, $this->_types);
1175 // add theme custom specific pageList columns:
1176 // set the 4th param as the current pagelist object.
1177 if (!empty($customPageListColumns)) {
1178 foreach ($customPageListColumns as $column => $params) {
1179 $class_name = array_shift($params);
1180 $params[3] =& $this;
1181 // ref to a class does not work with php-4
1182 $this->_types[$column] = new $class_name($params);
1187 function getOption($option) {
1188 if (array_key_exists($option, $this->_options)) {
1189 return $this->_options[$option];
1197 * Add a column to this PageList, given a column name.
1198 * The name is a type, and optionally has a : and a label. Examples:
1201 * pagename:This page
1203 * mtime:Last modified
1205 * If this function is called multiple times for the same type, the
1206 * column will only be added the first time, and ignored the succeeding times.
1207 * If you wish to add multiple columns of the same type, use addColumnObject().
1209 * @param column name
1210 * @return true if column is added, false otherwise
1212 function _addColumn ($column) {
1214 if (isset($this->_columns_seen[$column]))
1215 return false; // Already have this one.
1216 if (!isset($this->_types[$column]))
1217 $this->_initAvailableColumns();
1218 $this->_columns_seen[$column] = true;
1220 if (strstr($column, ':'))
1221 list ($column, $heading) = explode(':', $column, 2);
1223 // FIXME: these column types have hooks (objects) elsewhere
1224 // Omitting this warning should be overridable by the extension
1225 if (!isset($this->_types[$column])) {
1226 $silently_ignore = array('numbacklinks',
1227 'rating','ratingvalue',
1228 'coagreement', 'minmisery',
1230 'averagerating', 'top3recs',
1231 'relation', 'linkto');
1232 if (!in_array($column, $silently_ignore))
1233 trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
1236 // FIXME: anon users might rate and see ratings also.
1237 // Defer this logic to the plugin.
1238 if ($column == 'rating' and !$GLOBALS['request']->_user->isSignedIn())
1241 $this->addColumnObject($this->_types[$column]);
1247 * Add a column to this PageList, given a column object.
1249 * @param $col object An object derived from _PageList_Column.
1251 function addColumnObject($col) {
1252 if (is_array($col)) {// custom column object
1254 $class_name = array_shift($params);
1255 $params[3] =& $this;
1256 $col = new $class_name($params);
1258 $heading = $col->getHeading();
1259 if (!empty($heading))
1260 $col->setHeading($heading);
1262 $this->_columns[] = $col;
1263 $this->_columnsMap[$col->_field] = count($this->_columns); // start with 1
1267 * Compare _PageList_Page objects.
1269 function _pageCompare(&$a, &$b) {
1270 if (empty($this->_sortby) or count($this->_sortby) == 0) {
1271 // No columns to sort by
1275 $pagea = $this->_getPageFromHandle($a); // If a string, convert to page
1276 assert(isa($pagea, 'WikiDB_Page'));
1277 $pageb = $this->_getPageFromHandle($b); // If a string, convert to page
1278 assert(isa($pageb, 'WikiDB_Page'));
1279 foreach ($this->_sortby as $colNum => $direction) {
1280 // get column type object
1281 if (!is_int($colNum)) { // or column fieldname
1282 if (isset($this->_columnsMap[$colNum]))
1283 $col = $this->_columns[$this->_columnsMap[$colNum] - 1];
1284 elseif (isset($this->_types[$colNum]))
1285 $col = $this->_types[$colNum];
1288 assert(isset($col));
1289 $revision_handle = false;
1290 $aval = $col->_getSortableValue($pagea, $revision_handle);
1291 $revision_handle = false;
1292 $bval = $col->_getSortableValue($pageb, $revision_handle);
1294 $cmp = $col->_compare($aval, $bval);
1295 if ($direction === "-") // Reverse the sense of the comparison
1299 // This is the first comparison that is not equal-- go with it
1307 * Put pages in order according to the sortby arg, if given
1308 * If the sortby cols are already sorted by the DB call, don't do usort.
1309 * TODO: optimize for multiple sortable cols
1311 function _sortPages() {
1312 if (count($this->_sortby) > 0) {
1313 $need_sort = $this->_options['dosort'];
1315 foreach ($this->_sortby as $col => $dir) {
1316 if (! $this->sortby($col, 'db'))
1319 if ($need_sort) { // There are some columns to sort by
1320 // TODO: consider nopage
1321 usort($this->_pages, array($this, '_pageCompare'));
1324 //unset($GLOBALS['PhpWiki_pagelist']);
1327 function limit($limit) {
1328 if (is_array($limit)) return $limit;
1329 if (strstr($limit, ','))
1330 return split(',', $limit);
1332 return array(0, $limit);
1335 function pagingTokens($numrows = false, $ncolumns = false, $limit = false) {
1336 if ($numrows === false)
1337 $numrows = $this->getTotal();
1338 if ($limit === false)
1339 $limit = $this->_options['limit'];
1340 if ($ncolumns === false)
1341 $ncolumns = count($this->_columns);
1343 list($offset, $pagesize) = $this->limit($limit);
1345 (!$offset and $numrows < $pagesize) or
1346 (($offset + $pagesize) < 0))
1349 $request = &$GLOBALS['request'];
1350 $pagename = $request->getArg('pagename');
1351 $defargs = array_merge(array('id' => $this->id), $request->args);
1352 if (USE_PATH_INFO) unset($defargs['pagename']);
1353 if ($defargs['action'] == 'browse') unset($defargs['action']);
1357 $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
1358 $tokens['COLS'] = $ncolumns;
1359 $tokens['COUNT'] = $numrows;
1360 $tokens['OFFSET'] = $offset;
1361 $tokens['SIZE'] = $pagesize;
1362 $tokens['NUMPAGES'] = (int) ceil($numrows / $pagesize);
1363 $tokens['ACTPAGE'] = (int) ceil(($offset / $pagesize)+1);
1365 $prev['limit'] = max(0, $offset - $pagesize) . ",$pagesize";
1366 $prev['count'] = $numrows;
1367 $tokens['LIMIT'] = $prev['limit'];
1368 $tokens['PREV'] = true;
1369 $tokens['PREV_LINK'] = WikiURL($pagename, $prev);
1370 $prev['limit'] = "0,$pagesize";
1371 $tokens['FIRST_LINK'] = WikiURL($pagename, $prev);
1374 $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
1375 if (($offset + $pagesize) < $numrows) {
1376 $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) . ",$pagesize";
1377 $next['count'] = $numrows;
1378 $tokens['LIMIT'] = $next['limit'];
1379 $tokens['NEXT'] = true;
1380 $tokens['NEXT_LINK'] = WikiURL($pagename, $next);
1381 $next['limit'] = $numrows - $pagesize . ",$pagesize";
1382 $tokens['LAST_LINK'] = WikiURL($pagename, $next);
1387 // make a table given the caption
1388 function _generateTable($caption) {
1389 if (count($this->_sortby) > 0) $this->_sortPages();
1391 // wikiadminutils hack. that's a way to pagelist non-pages
1392 $rows = isset($this->_rows) ? $this->_rows : array(); $i = 0;
1393 $count = $this->getTotal();
1394 $do_paging = ( isset($this->_options['paging'])
1395 and !empty($this->_options['limit'])
1397 and $this->_options['paging'] != 'none' );
1399 $tokens = $this->pagingTokens($count,
1400 count($this->_columns),
1401 $this->_options['limit']);
1403 $this->_pages = array_slice($this->_pages, $tokens['OFFSET'], $tokens['COUNT']);
1405 foreach ($this->_pages as $pagenum => $page) {
1406 $rows[] = $this->_renderPageRow($page, $i++);
1408 $table = HTML::table(array('cellpadding' => 0,
1411 'class' => 'pagelist',
1414 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
1415 $table->setAttr('width', '100%');
1418 //Warning: This is quite fragile. It depends solely on a private variable
1419 // in ->_addColumn()
1420 if (!empty($this->_columns_seen['checkbox'])) {
1421 $table->pushContent($this->_jsFlipAll());
1425 $table_summary = array();
1426 $i = 1; // start with 1!
1427 foreach ($this->_columns as $col) {
1428 $heading = $col->button_heading($this, $i);
1430 and isset($col->_field)
1431 and $col->_field == 'pagename'
1432 and ($maxlen = $this->maxLen())) {
1433 // $heading->setAttr('width', $maxlen * 7);
1435 $row->pushContent($heading);
1436 if (is_string($col->getHeading()))
1437 $table_summary[] = $col->getHeading();
1440 // Table summary for non-visual browsers.
1441 $table->setAttr('summary', sprintf(_("Columns: %s."),
1442 join(", ", $table_summary)));
1443 $table->pushContent(HTML::colgroup(array('span' => count($this->_columns))));
1445 if ($tokens === false) {
1446 $table->pushContent(HTML::thead($row),
1447 HTML::tbody(false, $rows));
1451 $paging = Template("pagelink", $tokens);
1452 if ($this->_options['paging'] != 'bottom')
1453 $table->pushContent(HTML::thead($paging));
1454 if ($this->_options['paging'] != 'top')
1455 $table->pushContent(HTML::tfoot($paging));
1456 $table->pushContent(HTML::tbody(false, HTML($row, $rows)));
1459 $table->pushContent(HTML::thead($row),
1460 HTML::tbody(false, $rows));
1465 function _jsFlipAll() {
1467 function flipAll(formObj) {
1468 var isFirstSet = -1;
1469 for (var i=0; i < formObj.length; i++) {
1470 fldObj = formObj.elements[i];
1471 if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,2) == 'p[')) {
1472 if (isFirstSet == -1)
1473 isFirstSet = (fldObj.checked) ? true : false;
1474 fldObj.checked = (isFirstSet) ? false : true;
1480 /* recursive stack for private sublist options (azhead, cols) */
1481 function _saveOptions($opts) {
1482 $stack = array('pages' => $this->_pages);
1483 foreach ($opts as $k => $v) {
1484 $stack[$k] = $this->_options[$k];
1485 $this->_options[$k] = $v;
1487 if (empty($this->_stack))
1488 $this->_stack = new Stack();
1489 $this->_stack->push($stack);
1491 function _restoreOptions() {
1492 assert($this->_stack);
1493 $stack = $this->_stack->pop();
1494 $this->_pages = $stack['pages'];
1495 unset($stack['pages']);
1496 foreach ($stack as $k => $v) {
1497 $this->_options[$k] = $v;
1501 // 'cols' - split into several columns
1502 // 'azhead' - support <h3> grouping into initials
1503 // 'ordered' - OL or UL list (not yet inherited to all plugins)
1504 // 'comma' - condensed comma-list only, 1: no links, >1: with links
1505 // FIXME: only unique list entries, esp. with nopage
1506 function _generateList($caption='') {
1507 if (empty($this->_pages)) return; // stop recursion
1508 if (!isset($this->_options['listtype']))
1509 $this->_options['listtype'] = '';
1512 $out->pushContent(HTML::p($caption));
1513 // Semantic Search et al: only unique list entries, esp. with nopage
1514 if (!is_array($this->_pages[0]) and is_string($this->_pages[0])) {
1515 $this->_pages = array_unique($this->_pages);
1517 if (count($this->_sortby) > 0) $this->_sortPages();
1518 $count = $this->getTotal();
1519 $do_paging = ( isset($this->_options['paging'])
1520 and !empty($this->_options['limit'])
1522 and $this->_options['paging'] != 'none' );
1524 $tokens = $this->pagingTokens($count,
1525 count($this->_columns),
1526 $this->_options['limit']);
1528 $paging = Template("pagelink", $tokens);
1529 $out->pushContent(HTML::table(array('width'=>'50%'), $paging));
1533 // need a recursive switch here for the azhead and cols grouping.
1534 if (!empty($this->_options['cols']) and $this->_options['cols'] > 1) {
1535 $count = count($this->_pages);
1536 $length = $count / $this->_options['cols'];
1537 $width = sprintf("%d", 100 / $this->_options['cols']).'%';
1538 $cols = HTML::tr(array('valign' => 'top'));
1539 for ($i=0; $i < $count; $i += $length) {
1540 $this->_saveOptions(array('cols' => 0, 'paging' => 'none'));
1541 $this->_pages = array_slice($this->_pages, $i, $length);
1542 $cols->pushContent(HTML::td(/*array('width' => $width),*/
1543 $this->_generateList()));
1544 $this->_restoreOptions();
1546 // speed up table rendering by defining colgroups
1547 $out->pushContent(HTML::table(HTML::colgroup(array('span' => $this->_options['cols'],
1548 'width' => $width)),
1553 // Ignore azhead if not sorted by pagename
1554 if (!empty($this->_options['azhead'])
1555 and strstr($this->sortby($this->_options['sortby'], 'init'), "pagename")
1558 $cur_h = substr($this->_pages[0]->getName(), 0, 1);
1559 $out->pushContent(HTML::h3($cur_h));
1560 // group those pages together with same $h
1562 for ($i=0; $i < count($this->_pages); $i++) {
1563 $page =& $this->_pages[$i];
1564 $h = substr($page->getName(), 0, 1);
1565 if ($h != $cur_h and $i > $j) {
1566 $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
1567 $this->_pages = array_slice($this->_pages, $j, $i - $j);
1568 $out->pushContent($this->_generateList());
1569 $this->_restoreOptions();
1571 $out->pushContent(HTML::h3($h));
1575 if ($i > $j) { // flush the rest
1576 $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
1577 $this->_pages = array_slice($this->_pages, $j, $i - $j);
1578 $out->pushContent($this->_generateList());
1579 $this->_restoreOptions();
1584 if ($this->_options['listtype'] == 'comma')
1585 $this->_options['comma'] = 2;
1586 if (!empty($this->_options['comma'])) {
1587 if ($this->_options['comma'] == 1)
1588 $out->pushContent($this->_generateCommaListAsString());
1590 $out->pushContent($this->_generateCommaList($this->_options['comma']));
1594 if ($this->_options['listtype'] == 'ol')
1595 $this->_options['ordered'] = 1;
1596 elseif ($this->_options['listtype'] == 'ul')
1597 $this->_options['ordered'] = 0;
1598 if (!empty($this->_options['ordered']))
1599 $list = HTML::ol(array('class' => 'pagelist'));
1600 elseif ($this->_options['listtype'] == 'dl') {
1601 $list = HTML::dl(array('class' => 'pagelist'));
1603 $list = HTML::ul(array('class' => 'pagelist'));
1606 //TODO: currently we ignore limit here and hope that the backend didn't ignore it. (BackLinks)
1607 if (!empty($this->_options['limit']))
1608 list($offset, $pagesize) = $this->limit($this->_options['limit']);
1611 foreach ($this->_pages as $pagenum => $page) {
1612 $pagehtml = $this->_renderPageRow($page);
1613 if (!$pagehtml) continue;
1614 $group = ($i++ / $this->_group_rows);
1615 //TODO: here we switch every row, in tables every third.
1616 // unification or parametrized?
1617 $class = ($group % 2) ? 'oddrow' : 'evenrow';
1618 if ($this->_options['listtype'] == 'dl') {
1619 $header = WikiLink($page);
1620 //if ($this->_sortby['hi_content'])
1621 $list->pushContent(HTML::dt(array('class' => $class), $header),
1622 HTML::dd(array('class' => $class), $pagehtml));
1624 $list->pushContent(HTML::li(array('class' => $class), $pagehtml));
1625 if ($pagesize and $i > $pagesize) break;
1627 $out->pushContent($list);
1628 if ( $do_paging and $tokens ) {
1629 $out->pushContent(HTML::table($paging));
1635 // Condense list without a href links: "Page1, Page2, ..."
1636 // Alternative $seperator = HTML::Raw(' · ')
1637 // FIXME: only unique list entries, esp. with nopage
1638 function _generateCommaListAsString() {
1639 if (defined($this->_options['commasep']))
1640 $seperator = $this->_options['commasep'];
1644 foreach ($this->_pages as $pagenum => $page) {
1645 if ($s = $this->_renderPageRow($page)) // some pages are not viewable
1646 $pages[] = is_string($s) ? $s : $s->asString();
1648 return HTML(join($seperator, $pages));
1652 // Normal WikiLink list.
1653 // Future: 1 = reserved for plain string (see above)
1654 // 2 and more => HTML link specialization?
1655 // FIXME: only unique list entries, esp. with nopage
1656 function _generateCommaList($style = false) {
1657 if (defined($this->_options['commasep']))
1658 $seperator = HTLM::Raw($this->_options['commasep']);
1662 $html->pushContent($this->_renderPageRow($this->_pages[0]));
1663 next($this->_pages);
1664 foreach ($this->_pages as $pagenum => $page) {
1665 if ($s = $this->_renderPageRow($page)) // some pages are not viewable
1666 $html->pushContent($seperator, $s);
1671 function _emptyList($caption) {
1674 $html->pushContent(HTML::p($caption));
1675 if ($this->_messageIfEmpty)
1676 $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
1682 /* List pages with checkboxes to select from.
1683 * The [Select] button toggles via _jsFlipAll
1686 class PageList_Selectable
1689 function PageList_Selectable ($columns=false, $exclude='', $options = false) {
1691 if (!is_array($columns))
1692 $columns = explode(',', $columns);
1693 if (!in_array('checkbox',$columns))
1694 array_unshift($columns,'checkbox');
1696 $columns = array('checkbox','pagename');
1698 $this->PageList($columns, $exclude, $options);
1701 function addPageList ($array) {
1702 while (list($pagename,$selected) = each($array)) {
1703 if ($selected) $this->addPageSelected((string)$pagename);
1704 $this->addPage((string)$pagename);
1708 function addPageSelected ($pagename) {
1709 $this->_selected[$pagename] = 1;
1713 // (c-file-style: "gnu")
1717 // c-basic-offset: 4
1718 // c-hanging-comment-ender-p: nil
1719 // indent-tabs-mode: nil