1 <?php rcs_id('$Id: PageList.php,v 1.144 2007-07-21 19:33:43 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, 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 (1 /* 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,
135 if ($pagelist->sortby($colNum, 'check')) { // show icon? request or plugin arg
136 $sortby = $pagelist->sortby($colNum, 'flip_order');
137 $desc = (substr($sortby,0,1) == '-'); // +pagename or -pagename
138 $src = $WikiTheme->getButtonURL($desc ? 'asc_order' : 'desc_order');
139 $reverse = $desc ? _("reverse")." " : "";
141 // initially unsorted
142 $sortby = $pagelist->sortby($colNum, 'get');
147 $img->setAttr('alt', ".");
149 $img = HTML::img(array('src' => $src,
153 'alt' => _("Click to reverse sort order")));
155 $s = HTML::a(array('href' =>
156 //Fixme: pass all also other GET args along. (limit is ok, p[])
157 $request->GetURLtoSelf(array('sortby' => $sortby,
158 'id' => $pagelist->id)),
159 'class' => 'gridbutton',
160 'title' => sprintf(_("Click to sort by %s"), $reverse . $this->_field)),
162 $nbsp, $this->_heading,
166 $s = HTML($nbsp, $this->_heading, $nbsp);
168 return HTML::th(array('align' => 'center', 'valign' => 'middle',
169 'class' => 'gridbutton'), $s);
173 * Take two columns of this type and compare them.
174 * An undefined value is defined to be < than the smallest defined value.
175 * This base class _compare only works if the value is simple (e.g., a number).
177 * @param $colvala $this->_getValue() of column a
178 * @param $colvalb $this->_getValue() of column b
180 * @return -1 if $a < $b, 1 if $a > $b, 0 otherwise.
182 function _compare($colvala, $colvalb) {
183 if (is_string($colvala))
184 return strcmp($colvala,$colvalb);
186 if (($colvala === $colvalb) || (!isset($colvala) && !isset($colvalb))) {
189 $ret = (!isset($colvala) || ($colvala < $colvalb)) ? -1 : 1;
195 class _PageList_Column extends _PageList_Column_base {
196 function _PageList_Column ($field, $default_heading, $align = false) {
197 $this->_PageList_Column_base($default_heading, $align);
199 $this->_need_rev = substr($field, 0, 4) == 'rev:';
200 $this->_iscustom = substr($field, 0, 7) == 'custom:';
201 if ($this->_iscustom) {
202 $this->_field = substr($field, 7);
204 elseif ($this->_need_rev)
205 $this->_field = substr($field, 4);
207 $this->_field = $field;
210 function _getValue ($page_handle, &$revision_handle) {
211 if ($this->_need_rev) {
212 if (!$revision_handle)
213 // columns which need the %content should override this. (size, hi_content)
214 $revision_handle = $page_handle->getCurrentRevision(false);
215 return $revision_handle->get($this->_field);
218 return $page_handle->get($this->_field);
222 function _getSortableValue ($page_handle, &$revision_handle) {
223 $val = $this->_getValue($page_handle, $revision_handle);
224 if ($this->_field == 'hits')
226 elseif (is_object($val))
227 return $val->asString();
229 return (string) $val;
233 /* overcome a call_user_func limitation by not being able to do:
234 * call_user_func_array(array(&$class, $class_name), $params);
235 * So we need $class = new $classname($params);
236 * And we add a 4th param to get at the parent $pagelist object
238 class _PageList_Column_custom extends _PageList_Column {
239 function _PageList_Column_custom($params) {
240 $this->_pagelist =& $params[3];
241 $this->_PageList_Column($params[0], $params[1], $params[2]);
245 class _PageList_Column_size extends _PageList_Column {
246 function format (&$pagelist, $page_handle, &$revision_handle) {
247 return HTML::td($this->_tdattr,
249 $this->_getValue($pagelist, $page_handle, $revision_handle),
250 HTML::raw(' '));
253 function _getValue (&$pagelist, $page_handle, &$revision_handle) {
254 if (!$revision_handle or (!$revision_handle->_data['%content']
255 or $revision_handle->_data['%content'] === true)) {
256 $revision_handle = $page_handle->getCurrentRevision(true);
257 unset($revision_handle->_data['%pagedata']['_cached_html']);
259 $size = $this->_getSize($revision_handle);
260 // we can safely purge the content when it is not sortable
261 if (empty($pagelist->_sortby[$this->_field]))
262 unset($revision_handle->_data['%content']);
266 function _getSortableValue ($page_handle, &$revision_handle) {
267 if (!$revision_handle)
268 $revision_handle = $page_handle->getCurrentRevision(true);
269 return (empty($revision_handle->_data['%content']))
270 ? 0 : strlen($revision_handle->_data['%content']);
273 function _getSize($revision_handle) {
274 $bytes = @strlen($revision_handle->_data['%content']);
275 return ByteFormatter($bytes);
280 class _PageList_Column_bool extends _PageList_Column {
281 function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
282 $this->_PageList_Column($field, $default_heading, 'center');
283 $this->_textIfTrue = $text;
284 $this->_textIfFalse = new RawXml('—'); //mdash
287 function _getValue ($page_handle, &$revision_handle) {
288 //FIXME: check if $this is available in the parent (->need_rev)
289 $val = _PageList_Column::_getValue($page_handle, $revision_handle);
290 return $val ? $this->_textIfTrue : $this->_textIfFalse;
294 class _PageList_Column_checkbox extends _PageList_Column {
295 function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
296 $this->_name = $name;
297 $heading = HTML::input(array('type' => 'button',
298 'title' => _("Click to de-/select all pages"),
300 'name' => $default_heading,
301 'value' => $default_heading,
302 'onclick' => "flipAll(this.form)"
304 $this->_PageList_Column($field, $heading, 'center');
306 function _getValue ($pagelist, $page_handle, &$revision_handle) {
307 $pagename = $page_handle->getName();
308 $selected = !empty($pagelist->_selected[$pagename]);
309 if (strstr($pagename,'[') or strstr($pagename,']')) {
310 $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
313 return HTML::input(array('type' => 'checkbox',
314 'name' => $this->_name . "[$pagename]",
316 'checked' => 'CHECKED'));
318 return HTML::input(array('type' => 'checkbox',
319 'name' => $this->_name . "[$pagename]",
323 function format ($pagelist, $page_handle, &$revision_handle) {
324 return HTML::td($this->_tdattr,
326 $this->_getValue($pagelist, $page_handle, $revision_handle),
327 HTML::raw(' '));
329 // don't sort this javascript button
330 function button_heading ($pagelist, $colNum) {
331 $s = HTML(HTML::raw(' '), $this->_heading, HTML::raw(' '));
332 return HTML::th(array('align' => 'center', 'valign' => 'middle',
333 'class' => 'gridbutton'), $s);
337 class _PageList_Column_time extends _PageList_Column {
338 function _PageList_Column_time ($field, $default_heading) {
339 $this->_PageList_Column($field, $default_heading, 'right');
341 $this->Theme = &$WikiTheme;
344 function _getValue ($page_handle, &$revision_handle) {
345 $time = _PageList_Column::_getValue($page_handle, $revision_handle);
346 return $this->Theme->formatDateTime($time);
349 function _getSortableValue ($page_handle, &$revision_handle) {
350 return _PageList_Column::_getValue($page_handle, $revision_handle);
354 class _PageList_Column_version extends _PageList_Column {
355 function _getValue ($page_handle, &$revision_handle) {
356 if (!$revision_handle)
357 $revision_handle = $page_handle->getCurrentRevision();
358 return $revision_handle->getVersion();
362 // Output is hardcoded to limit of first 50 bytes. Otherwise
363 // on very large Wikis this will fail if used with AllPages
364 // (PHP memory limit exceeded)
365 class _PageList_Column_content extends _PageList_Column {
366 function _PageList_Column_content ($field, $default_heading, $align = false, $search = false) {
367 $this->_PageList_Column($field, $default_heading, $align);
369 $this->search = $search;
370 if ($field == 'content') {
371 $this->_heading .= sprintf(_(" ... first %d bytes"),
373 } elseif ($field == 'rev:hi_content') {
374 global $HTTP_POST_VARS;
375 if (!$this->search and !empty($HTTP_POST_VARS['admin_replace'])) {
376 $this->search = $HTTP_POST_VARS['admin_replace']['from'];
378 $this->_heading .= sprintf(_(" ... around %s"),
379 '»'.$this->search.'«');
383 function _getValue ($page_handle, &$revision_handle) {
384 if (!$revision_handle or (!$revision_handle->_data['%content']
385 or $revision_handle->_data['%content'] === true)) {
386 $revision_handle = $page_handle->getCurrentRevision(true);
388 // Not sure why implode is needed here, I thought
389 // getContent() already did this, but it seems necessary.
390 $c = implode("\n", $revision_handle->getContent());
391 if (empty($pagelist->_sortby[$this->_field]))
392 unset($revision_handle->_data['%content']);
393 if ($this->_field == 'hi_content') {
394 if (!empty($revision_handle->_data['%pagedata']))
395 unset($revision_handle->_data['%pagedata']['_cached_html']);
396 $search = $this->search;
398 if (!empty($page_handle->score))
399 $score = $page_handle->score;
400 elseif (!empty($page_handle['score']))
401 $score = $page_handle['score'];
402 if ($search and ($i = strpos(strtolower($c), strtolower($search)))) {
403 $l = strlen($search);
404 $j = max(0, $i - ($this->bytes / 2));
405 return HTML::div(array('style' => 'font-size:x-small'),
406 HTML::div(array('class' => 'transclusion'),
407 HTML::span("...".substr($c, $j, ($this->bytes / 2))),
408 HTML::span(array("style"=>"background:yellow"),substr($c, $i, $l)),
409 HTML::span(substr($c, $i+$l, ($this->bytes / 2))."..."." ".($score ? sprintf("[%0.1f]",$score):""))));
414 $c = sprintf(_("%s not found"), '»'.$search.'«');
415 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
416 $c." ".($score ? sprintf("[%0.1f]",$score):""));
418 } elseif (($len = strlen($c)) > $this->bytes) {
419 $c = substr($c, 0, $this->bytes);
421 include_once('lib/BlockParser.php');
422 // false --> don't bother processing hrefs for embedded WikiLinks
423 $ct = TransformText($c, $revision_handle->get('markup'), false);
424 if (empty($pagelist->_sortby[$this->_field]))
425 unset($revision_handle->_data['%pagedata']['_cached_html']);
426 return HTML::div(array('style' => 'font-size:x-small'),
427 HTML::div(array('class' => 'transclusion'), $ct),
428 // Don't show bytes here if size column present too
429 ($this->parent->_columns_seen['size'] or !$len) ? "" :
430 ByteFormatter($len, /*$longformat = */true));
432 function _getSortableValue ($page_handle, &$revision_handle) {
433 if (!empty($page_handle->score))
434 return $page_handle->score;
435 elseif (!empty($page_handle['score']))
436 return $page_handle['score'];
438 return substr(_PageList_Column::_getValue($page_handle, $revision_handle),0,50);
442 class _PageList_Column_author extends _PageList_Column {
443 function _PageList_Column_author ($field, $default_heading, $align = false) {
444 _PageList_Column::_PageList_Column($field, $default_heading, $align);
445 $this->dbi =& $GLOBALS['request']->getDbh();
448 function _getValue ($page_handle, &$revision_handle) {
449 $author = _PageList_Column::_getValue($page_handle, $revision_handle);
450 if ($this->dbi->isWikiPage($author))
451 return WikiLink($author);
456 function _getSortableValue ($page_handle, &$revision_handle) {
457 return _PageList_Column::_getValue($page_handle, $revision_handle);
461 class _PageList_Column_owner extends _PageList_Column_author {
462 function _getValue ($page_handle, &$revision_handle) {
463 $author = $page_handle->getOwner();
464 if ($this->dbi->isWikiPage($author))
465 return WikiLink($author);
469 function _getSortableValue ($page_handle, &$revision_handle) {
470 return _PageList_Column::_getValue($page_handle, $revision_handle);
474 class _PageList_Column_creator extends _PageList_Column_author {
475 function _getValue ($page_handle, &$revision_handle) {
476 $author = $page_handle->getCreator();
477 if ($this->dbi->isWikiPage($author))
478 return WikiLink($author);
482 function _getSortableValue ($page_handle, &$revision_handle) {
483 return _PageList_Column::_getValue($page_handle, $revision_handle);
487 class _PageList_Column_pagename extends _PageList_Column_base {
488 var $_field = 'pagename';
490 function _PageList_Column_pagename () {
491 $this->_PageList_Column_base(_("Page Name"));
493 $this->dbi = &$request->getDbh();
496 function _getValue ($page_handle, &$revision_handle) {
497 if ($this->dbi->isWikiPage($page_handle->getName()))
498 return WikiLink($page_handle, 'known');
500 return WikiLink($page_handle, 'unknown');
503 function _getSortableValue ($page_handle, &$revision_handle) {
504 return $page_handle->getName();
508 * Compare two pagenames for sorting. See _PageList_Column::_compare.
510 function _compare($colvala, $colvalb) {
511 return strcmp($colvala, $colvalb);
516 var $_group_rows = 3;
517 var $_columns = array();
518 var $_columnsMap = array(); // Maps column name to column number.
519 var $_excluded_pages = array();
520 var $_pages = array();
522 var $_pagename_seen = false;
523 var $_types = array();
524 var $_options = array();
525 var $_selected = array();
526 var $_sortby = array();
529 function PageList ($columns = false, $exclude = false, $options = false) {
530 // unique id per pagelist on each page.
531 if (!isset($GLOBALS['request']->_pagelist))
532 $GLOBALS['request']->_pagelist = 0;
534 $GLOBALS['request']->_pagelist++;
535 $this->id = $GLOBALS['request']->_pagelist;
537 $this->_options = $options;
539 $this->_initAvailableColumns();
540 // let plugins predefine only certain objects, such its own custom pagelist columns
543 'all' => array_diff(array_keys($this->_types), // all but...
544 array('checkbox','remove','renamed_pagename',
545 'content','hi_content','perm','acl')),
546 'most' => array('pagename','mtime','author','hits'),
547 'some' => array('pagename','mtime','author')
549 if (isset($this->_options['listtype'])
550 and $this->_options['listtype'] == 'dl')
551 $this->_options['nopage'] = 1;
553 if (!is_array($columns))
554 $columns = explode(',', $columns);
555 // expand symbolic columns:
556 foreach ($symbolic_columns as $symbol => $cols) {
557 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
558 $columns = array_diff(array_merge($columns,$cols),array($symbol));
562 if (empty($this->_options['nopage']) and !in_array('pagename',$columns))
563 $this->_addColumn('pagename');
564 foreach ($columns as $col) {
566 $this->_addColumn($col);
570 // If 'pagename' is already present, _addColumn() will not add it again
571 if (empty($this->_options['nopage']))
572 $this->_addColumn('pagename');
574 if (!empty($this->_options['types'])) {
575 foreach ($this->_options['types'] as $type) {
576 $this->_types[$type->_field] = $type;
577 $this->_addColumn($type->_field);
579 unset($this->_options['types']);
583 // explicit header options: ?id=x&sortby=... override options[]
584 // support multiple sorts. check multiple, no nested elseif
585 if (($this->id == $request->getArg("id"))
586 and $request->getArg('sortby'))
588 // add it to the front of the sortby array
589 $this->sortby($request->getArg('sortby'), 'init');
590 $this->_options['sortby'] = $request->getArg('sortby');
592 if (!empty($options['sortby'])) {
593 if (empty($this->_options['sortby']))
594 $this->_options['sortby'] = $options['sortby'];
595 $this->sortby($options['sortby'], 'init');
597 if (!isset($request->args["id"]) and $request->getArg('sortby')
598 and empty($this->_options['sortby']))
600 $this->_options['sortby'] = $request->getArg('sortby');
601 $this->sortby($this->_options['sortby'], 'init');
603 // same as above but without the special sortby push, and mutually exclusive (elseif)
604 foreach ($this->pagingArgs() as $key) {
605 if ($key == 'sortby') continue;
606 if (($this->id == $request->getArg("id"))
607 and $request->getArg($key))
609 $this->_options[$key] = $request->getArg($key);
611 elseif (!empty($options) and !empty($options[$key])) {
612 $this->_options[$key] = $options[$key];
614 elseif (!isset($request->args["id"]) and $request->getArg($key)) {
615 $this->_options[$key] = $request->getArg($key);
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 return array(// Currently supported options:
634 /* what columns, what pages */
635 'info' => 'pagename',
636 'exclude' => '', // also wildcards, comma-seperated lists
637 // and <!plugin-list !> arrays
638 /* select pages by meta-data: */
639 'author' => false, // current user by []
640 'owner' => false, // current user by []
641 'creator' => false, // current user by []
643 /* for the sort buttons in <th> */
644 'sortby' => '', // same as for WikiDB::getAllPages
645 // (unsorted is faster)
647 /* PageList pager options:
648 * These options may also be given to _generate(List|Table) later
649 * But limit and offset might help the query WikiDB::getAllPages()
651 'limit' => 50, // number of rows (pagesize)
652 'paging' => 'auto', // 'auto' top + bottom rows if applicable
653 // // 'top' top only if applicable
654 // // 'bottom' bottom only if applicable
655 // // 'none' don't page at all
656 // (TODO: clarify what if $paging==false ?)
658 /* list-style options (with single pagename column only so far) */
659 'cols' => 1, // side-by-side display of list (1-3)
660 'azhead' => 0, // 1: group by initials
661 // 2: provide shortcut links to initials also
662 'comma' => 0, // condensed comma-seperated list,
663 // 1 if without links, 2 if with
664 'commasep' => false, // Default: ', '
665 'listtype' => '', // ul (default), ol, dl, comma
666 'ordered' => false, // OL or just UL lists (ignored for comma)
667 'linkmore' => '', // If count>0 and limit>0 display a link with
668 // the number of all results, linked to the given pagename.
670 'nopage' => false, // for info=col omit the pagename column
674 function pagingArgs() {
675 return array('sortby','limit','paging','count','dosort');
678 function setCaption ($caption_string) {
679 $this->_caption = $caption_string;
682 function addCaption ($caption_string) {
683 $this->_caption = HTML($this->_caption," ",$caption_string);
686 function getCaption () {
687 // put the total into the caption if needed
688 if (is_string($this->_caption) && strstr($this->_caption, '%d'))
689 return sprintf($this->_caption, $this->getTotal());
690 return $this->_caption;
693 function setMessageIfEmpty ($msg) {
694 $this->_messageIfEmpty = $msg;
698 function getTotal () {
699 return !empty($this->_options['count'])
700 ? (integer) $this->_options['count'] : count($this->_pages);
703 function isEmpty () {
704 return empty($this->_pages);
707 function addPage($page_handle) {
708 if (!empty($this->_excluded_pages)) {
709 if (!in_array((is_string($page_handle) ? $page_handle : $page_handle->getName()),
710 $this->_excluded_pages))
711 $this->_pages[] = $page_handle;
713 $this->_pages[] = $page_handle;
717 function pageNames() {
719 $limit = @$this->_options['limit'];
720 foreach ($this->_pages as $page_handle) {
721 $pages[] = $page_handle->getName();
722 if ($limit and count($pages) > $limit)
728 function _getPageFromHandle($page_handle) {
729 if (is_string($page_handle)) {
730 if (empty($page_handle)) return $page_handle;
731 //$dbi = $GLOBALS['request']->getDbh(); // no, safe some memory!
732 $page_handle = $GLOBALS['request']->_dbi->getPage($page_handle);
738 * Take a PageList_Page object, and return an HTML object to display
739 * it in a table or list row.
741 function _renderPageRow (&$page_handle, $i = 0) {
742 $page_handle = $this->_getPageFromHandle($page_handle);
743 //FIXME. only on sf.net
744 if (!is_object($page_handle)) {
745 trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
748 if (!isset($page_handle)
749 or empty($page_handle)
750 or (!empty($this->_excluded_pages)
751 and in_array($page_handle->getName(), $this->_excluded_pages)))
752 return; // exclude page.
754 // enforce view permission
755 if (!mayAccessPage('view', $page_handle->getName()))
758 $group = (int)($i / $this->_group_rows);
759 $class = ($group % 2) ? 'oddrow' : 'evenrow';
760 $revision_handle = false;
761 $this->_maxlen = max($this->_maxlen, strlen($page_handle->getName()));
763 if (count($this->_columns) > 1) {
764 $row = HTML::tr(array('class' => $class));
766 foreach ($this->_columns as $col) {
767 $col->current_row = $i;
768 $col->current_column = $j;
769 $row->pushContent($col->format($this, $page_handle, $revision_handle));
773 $col = $this->_columns[0];
774 $col->current_row = $i;
775 $col->current_column = 0;
776 $row = $col->_getValue($page_handle, $revision_handle);
782 function addPages ($page_iter) {
783 //Todo: if limit check max(strlen(pagename))
784 while ($page = $page_iter->next()) {
785 $this->addPage($page);
789 function addPageList (&$list) {
790 if (empty($list)) return; // Protect reset from a null arg
791 foreach ($list as $page) {
792 if (is_object($page))
793 $page = $page->_pagename;
794 $this->addPage((string)$page);
800 $dbi =& $request->getDbh();
801 if (isa($dbi,'WikiDB_SQL')) {
802 extract($dbi->_backend->_table_names);
803 $res = $dbi->_backend->_dbh->getOne("SELECT max(length(pagename)) FROM $page_tbl");
804 if (DB::isError($res) || empty($res)) return false;
806 } elseif (isa($dbi,'WikiDB_ADODB')) {
807 extract($dbi->_backend->_table_names);
808 $row = $dbi->_backend->_dbh->getRow("SELECT max(length(pagename)) FROM $page_tbl");
809 return $row ? $row[0] : false;
814 function getContent() {
815 // Note that the <caption> element wants inline content.
816 $caption = $this->getCaption();
818 if ($this->isEmpty())
819 return $this->_emptyList($caption);
820 elseif (isset($this->_options['listtype'])
821 and in_array($this->_options['listtype'],
822 array('ol','ul','comma','dl')))
823 return $this->_generateList($caption);
824 elseif (count($this->_columns) == 1)
825 return $this->_generateList($caption);
827 return $this->_generateTable($caption);
830 function printXML() {
831 PrintXML($this->getContent());
835 return AsXML($this->getContent());
839 * Handle sortby requests for the DB iterator and table header links.
840 * Prefix the column with + or - like "+pagename","-mtime", ...
843 * 'init' : unify with predefined order. "pagename" => "+pagename"
844 * 'flip_order' : "mtime" => "+mtime" => "-mtime" ...
845 * 'db' : "-pagename" => "pagename DESC"
848 * Now all columns are sortable. (patch by DanFr)
849 * Some columns have native DB backend methods, some not.
851 function sortby ($column, $action, $valid_fields=false) {
854 if (empty($column)) return '';
855 if (is_int($column)) {
856 $column = $this->_columns[$column - 1]->_field;
857 //$column = $col->_field;
859 //if (!is_string($column)) return '';
860 // support multiple comma-delimited sortby args: "+hits,+pagename"
862 if (strstr($column, ',')) {
863 $result = ($action == 'check') ? true : array();
864 foreach (explode(',', $column) as $col) {
865 if ($action == 'check')
866 $result = $result && $this->sortby($col, $action, $valid_fields);
868 $result[] = $this->sortby($col, $action, $valid_fields);
870 // 'check' returns true/false for every col. return true if all are true.
871 // i.e. the unsupported 'every' operator in functional languages.
872 if ($action == 'check')
875 return join(",", $result);
877 if (substr($column,0,1) == '+') {
878 $order = '+'; $column = substr($column,1);
879 } elseif (substr($column,0,1) == '-') {
880 $order = '-'; $column = substr($column,1);
882 // default initial order: +pagename, -mtime, -hits
884 if (!empty($this->_sortby[$column]))
885 $order = $this->_sortby[$column];
887 if (in_array($column, array('mtime','hits')))
893 if ($action == 'get') {
894 return $order . $column;
895 } elseif ($action == 'flip_order') {
897 trigger_error("flip $order $column ".$this->id, E_USER_NOTICE);
898 return ($order == '+' ? '-' : '+') . $column;
899 } elseif ($action == 'init') { // only allowed from PageList::PageList
900 if ($this->sortby($column, 'clicked')) {
902 trigger_error("clicked $order $column $this->id", E_USER_NOTICE);
903 //$order = ($order == '+' ? '-' : '+'); // $this->sortby($sortby, 'flip_order');
905 $this->_sortby[$column] = $order; // forces show icon
906 return $order . $column;
907 } elseif ($action == 'check') { // show icon?
908 //if specified via arg or if clicked
909 $show = (!empty($this->_sortby[$column]) or $this->sortby($column, 'clicked'));
910 if (0 and $show and DEBUG) {
911 trigger_error("show $order $column ".$this->id, E_USER_NOTICE);
914 } elseif ($action == 'clicked') { // flip sort order?
916 $arg = $request->getArg('sortby');
918 and strstr($arg, $column)
919 and (!isset($request->args['id'])
920 or $this->id == $request->getArg('id')));
921 } elseif ($action == 'db') {
922 // Performance enhancement: use native DB sort if possible.
923 if (($valid_fields and in_array($column, $valid_fields))
924 or (method_exists($request->_dbi->_backend, 'sortable_columns')
925 and (in_array($column, $request->_dbi->_backend->sortable_columns())))) {
926 // omit this sort method from the _sortPages call at rendering
927 // asc or desc: +pagename, -pagename
928 return $column . ($order == '+' ? ' ASC' : ' DESC');
936 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
937 function explodePageList($input, $include_empty=false, $sortby='',
938 $limit='', $exclude='')
940 if (empty($input)) return array();
941 // expand wildcards from list of all pages
942 if (preg_match('/[\?\*]/', $input)) {
943 include_once("lib/TextSearchQuery.php");
944 $search = new TextSearchQuery(str_replace(",", " ", $input), true, 'glob');
945 $dbi = $GLOBALS['request']->getDbh();
946 $iter = $dbi->titleSearch($search, $sortby, $limit, $exclude);
948 while ($pagehandle = $iter->next()) {
949 $pages[] = $pagehandle->getName();
953 //TODO: need an SQL optimization here
954 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit,
956 while ($pagehandle = $allPagehandles->next()) {
957 $allPages[] = $pagehandle->getName();
959 return explodeList($input, $allPages);
962 //TODO: do the sorting, normally not needed if used for exclude only
963 return explode(',', $input);
967 // TODO: optimize getTotal => store in count
968 function allPagesByAuthor($wildcard, $include_empty=false, $sortby='',
969 $limit='', $exclude='')
971 $dbi = $GLOBALS['request']->getDbh();
972 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
974 if ($wildcard === '[]') {
975 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
976 if (!$wildcard) return $allPages;
978 $do_glob = preg_match('/[\?\*]/', $wildcard);
979 while ($pagehandle = $allPagehandles->next()) {
980 $name = $pagehandle->getName();
981 $author = $pagehandle->getAuthor();
984 if (glob_match($wildcard, $author))
986 } elseif ($wildcard == $author) {
990 // TODO: purge versiondata_cache
995 function allPagesByOwner($wildcard, $include_empty=false, $sortby='',
996 $limit='', $exclude='') {
997 $dbi = $GLOBALS['request']->getDbh();
998 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1000 if ($wildcard === '[]') {
1001 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
1002 if (!$wildcard) return $allPages;
1004 $do_glob = preg_match('/[\?\*]/', $wildcard);
1005 while ($pagehandle = $allPagehandles->next()) {
1006 $name = $pagehandle->getName();
1007 $owner = $pagehandle->getOwner();
1010 if (glob_match($wildcard, $owner))
1011 $allPages[] = $name;
1012 } elseif ($wildcard == $owner) {
1013 $allPages[] = $name;
1020 function allPagesByCreator($wildcard, $include_empty=false, $sortby='',
1021 $limit='', $exclude='') {
1022 $dbi = $GLOBALS['request']->getDbh();
1023 $allPagehandles = $dbi->getAllPages($include_empty, $sortby, $limit, $exclude);
1024 $allPages = array();
1025 if ($wildcard === '[]') {
1026 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
1027 if (!$wildcard) return $allPages;
1029 $do_glob = preg_match('/[\?\*]/', $wildcard);
1030 while ($pagehandle = $allPagehandles->next()) {
1031 $name = $pagehandle->getName();
1032 $creator = $pagehandle->getCreator();
1035 if (glob_match($wildcard, $creator))
1036 $allPages[] = $name;
1037 } elseif ($wildcard == $creator) {
1038 $allPages[] = $name;
1045 ////////////////////
1047 ////////////////////
1048 /** Plugin and theme hooks:
1049 * If the pageList is initialized with $options['types'] these types are also initialized,
1050 * overriding the standard types.
1052 function _initAvailableColumns() {
1053 global $customPageListColumns;
1057 => new _PageList_Column_content('rev:content', _("Content")),
1058 // new: plugin specific column types initialised by the relevant plugins
1060 'hi_content' // with highlighted search for SearchReplace
1061 => new _PageList_Column_content('rev:hi_content', _("Content")),
1063 => new _PageList_Column_remove('remove', _("Remove")),
1064 // initialised by the plugin
1066 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
1068 => new _PageList_Column_perm('perm', _("Permission")),
1070 => new _PageList_Column_acl('acl', _("ACL")),
1073 => new _PageList_Column_checkbox('p', _("Select")),
1075 => new _PageList_Column_pagename,
1077 => new _PageList_Column_time('rev:mtime', _("Last Modified")),
1079 => new _PageList_Column('hits', _("Hits"), 'right'),
1081 => new _PageList_Column_size('rev:size', _("Size"), 'right'),
1082 /*array('align' => 'char', 'char' => ' ')*/
1084 => new _PageList_Column('rev:summary', _("Last Summary")),
1086 => new _PageList_Column_version('rev:version', _("Version"),
1089 => new _PageList_Column_author('rev:author', _("Last Author")),
1091 => new _PageList_Column_owner('author_id', _("Owner")),
1093 => new _PageList_Column_creator('author_id', _("Creator")),
1096 => new _PageList_Column_author('group', _("Group")),
1099 => new _PageList_Column_bool('locked', _("Locked"),
1102 => new _PageList_Column_bool('rev:is_minor_edit',
1103 _("Minor Edit"), _("minor")),
1105 => new _PageList_Column('rev:markup', _("Markup")),
1106 // 'rating' initialised by the wikilens theme hook: addPageListColumn
1109 => new _PageList_Column_rating('rating', _("Rate")),
1112 if (empty($this->_types))
1113 $this->_types = array();
1114 // add plugin specific pageList columns, initialized by $options['types']
1115 $this->_types = array_merge($standard_types, $this->_types);
1116 // add theme custom specific pageList columns:
1117 // set the 4th param as the current pagelist object.
1118 if (!empty($customPageListColumns)) {
1119 foreach ($customPageListColumns as $column => $params) {
1120 $class_name = array_shift($params);
1121 $params[3] =& $this;
1122 $class = new $class_name($params);
1123 $this->_types[$column] =& $class;
1128 function getOption($option) {
1129 if (array_key_exists($option, $this->_options)) {
1130 return $this->_options[$option];
1138 * Add a column to this PageList, given a column name.
1139 * The name is a type, and optionally has a : and a label. Examples:
1142 * pagename:This page
1144 * mtime:Last modified
1146 * If this function is called multiple times for the same type, the
1147 * column will only be added the first time, and ignored the succeeding times.
1148 * If you wish to add multiple columns of the same type, use addColumnObject().
1150 * @param column name
1151 * @return true if column is added, false otherwise
1153 function _addColumn ($column) {
1155 if (isset($this->_columns_seen[$column]))
1156 return false; // Already have this one.
1157 if (!isset($this->_types[$column]))
1158 $this->_initAvailableColumns();
1159 $this->_columns_seen[$column] = true;
1161 if (strstr($column, ':'))
1162 list ($column, $heading) = explode(':', $column, 2);
1164 // FIXME: these column types have hooks (objects) elsewhere
1165 // Omitting this warning should be overridable by the extension
1166 if (!isset($this->_types[$column])) {
1167 $silently_ignore = array('numbacklinks',
1168 'rating',/*'ratingwidget',*/
1169 'coagreement', 'minmisery',
1171 'averagerating', 'top3recs',
1172 'relation', 'linkto');
1173 if (!in_array($column, $silently_ignore))
1174 trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
1177 // FIXME: anon users might rate and see ratings also.
1178 // Defer this logic to the plugin.
1179 if ($column == 'rating' and !$GLOBALS['request']->_user->isSignedIn())
1182 $this->addColumnObject($this->_types[$column]);
1188 * Add a column to this PageList, given a column object.
1190 * @param $col object An object derived from _PageList_Column.
1192 function addColumnObject($col) {
1193 if (is_array($col)) {// custom column object
1195 $class_name = array_shift($params);
1196 $params[3] =& $this;
1197 $col = new $class_name($params);
1199 $heading = $col->getHeading();
1200 if (!empty($heading))
1201 $col->setHeading($heading);
1203 $this->_columns[] = $col;
1204 $this->_columnsMap[$col->_field] = count($this->_columns); // start with 1
1208 * Compare _PageList_Page objects.
1210 function _pageCompare(&$a, &$b) {
1211 if (empty($this->_sortby) or count($this->_sortby) == 0) {
1212 // No columns to sort by
1216 $pagea = $this->_getPageFromHandle($a); // If a string, convert to page
1217 assert(isa($pagea, 'WikiDB_Page'));
1218 $pageb = $this->_getPageFromHandle($b); // If a string, convert to page
1219 assert(isa($pageb, 'WikiDB_Page'));
1220 foreach ($this->_sortby as $colNum => $direction) {
1221 // get column type object
1222 if (!is_int($colNum)) { // or column fieldname
1223 if (isset($this->_columnsMap[$colNum]))
1224 $col = $this->_columns[$this->_columnsMap[$colNum] - 1];
1225 elseif (isset($this->_types[$colNum]))
1226 $col = $this->_types[$colNum];
1229 assert(isset($col));
1230 $revision_handle = false;
1231 $aval = $col->_getSortableValue($pagea, $revision_handle);
1232 $revision_handle = false;
1233 $bval = $col->_getSortableValue($pageb, $revision_handle);
1235 $cmp = $col->_compare($aval, $bval);
1236 if ($direction === "-") // Reverse the sense of the comparison
1240 // This is the first comparison that is not equal-- go with it
1248 * Put pages in order according to the sortby arg, if given
1249 * If the sortby cols are already sorted by the DB call, don't do usort.
1250 * TODO: optimize for multiple sortable cols
1252 function _sortPages() {
1253 if (count($this->_sortby) > 0) {
1254 $need_sort = $this->_options['dosort'];
1256 foreach ($this->_sortby as $col => $dir) {
1257 if (! $this->sortby($col, 'db'))
1260 if ($need_sort) { // There are some columns to sort by
1261 // TODO: consider nopage
1262 usort($this->_pages, array($this, '_pageCompare'));
1265 //unset($GLOBALS['PhpWiki_pagelist']);
1268 function limit($limit) {
1269 if (is_array($limit)) return $limit;
1270 if (strstr($limit, ','))
1271 return split(',', $limit);
1273 return array(0, $limit);
1276 function pagingTokens($numrows = false, $ncolumns = false, $limit = false) {
1277 if ($numrows === false)
1278 $numrows = $this->getTotal();
1279 if ($limit === false)
1280 $limit = $this->_options['limit'];
1281 if ($ncolumns === false)
1282 $ncolumns = count($this->_columns);
1284 list($offset, $pagesize) = $this->limit($limit);
1286 (!$offset and $numrows <= $pagesize) or
1287 ($offset + $pagesize < 0))
1290 $request = &$GLOBALS['request'];
1291 $pagename = $request->getArg('pagename');
1292 $defargs = $request->args;
1293 if (USE_PATH_INFO) unset($defargs['pagename']);
1294 if ($defargs['action'] == 'browse') unset($defargs['action']);
1298 $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
1299 $tokens['COLS'] = count($this->_columns);
1300 $tokens['COUNT'] = $numrows;
1301 $tokens['OFFSET'] = $offset;
1302 $tokens['SIZE'] = $pagesize;
1303 $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
1304 $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
1306 $prev['limit'] = max(0, $offset - $pagesize) . ",$pagesize";
1307 $prev['count'] = $numrows;
1308 $tokens['LIMIT'] = $prev['limit'];
1309 $tokens['PREV'] = true;
1310 $tokens['PREV_LINK'] = WikiURL($pagename, $prev);
1311 $prev['limit'] = "0,$pagesize";
1312 $tokens['FIRST_LINK'] = WikiURL($pagename, $prev);
1315 $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
1316 if ($offset + $pagesize < $numrows) {
1317 $next['limit'] = min($offset + $pagesize, $numrows - $pagesize) . ",$pagesize";
1318 $next['count'] = $numrows;
1319 $tokens['LIMIT'] = $next['limit'];
1320 $tokens['NEXT'] = true;
1321 $tokens['NEXT_LINK'] = WikiURL($pagename, $next);
1322 $next['limit'] = $numrows - $pagesize . ",$pagesize";
1323 $tokens['LAST_LINK'] = WikiURL($pagename, $next);
1328 // make a table given the caption
1329 function _generateTable($caption) {
1330 if (count($this->_sortby) > 0) $this->_sortPages();
1332 // wikiadminutils hack. that's a way to pagelist non-pages
1333 $rows = isset($this->_rows) ? $this->_rows : array(); $i = 0;
1334 $count = $this->getTotal();
1335 $do_paging = ( isset($this->_options['paging'])
1336 and !empty($this->_options['limit'])
1338 and $this->_options['paging'] != 'none' );
1340 $tokens = $this->pagingTokens($count,
1341 count($this->_columns),
1342 $this->_options['limit']);
1344 $this->_pages = array_slice($this->_pages, $tokens['OFFSET'], $tokens['NUMPAGES']);
1346 foreach ($this->_pages as $pagenum => $page) {
1347 $rows[] = $this->_renderPageRow($page, $i++);
1349 $table = HTML::table(array('cellpadding' => 0,
1352 'class' => 'pagelist',
1355 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
1356 $table->setAttr('width', '100%');
1359 //Warning: This is quite fragile. It depends solely on a private variable
1360 // in ->_addColumn()
1361 if (!empty($this->_columns_seen['checkbox'])) {
1362 $table->pushContent($this->_jsFlipAll());
1366 $table_summary = array();
1367 $i = 1; // start with 1!
1368 foreach ($this->_columns as $col) {
1369 $heading = $col->button_heading($this, $i);
1371 and isset($col->_field)
1372 and $col->_field == 'pagename'
1373 and ($maxlen = $this->maxLen())) {
1374 $heading->setAttr('width', $maxlen * 7);
1376 $row->pushContent($heading);
1377 if (is_string($col->getHeading()))
1378 $table_summary[] = $col->getHeading();
1381 // Table summary for non-visual browsers.
1382 $table->setAttr('summary', sprintf(_("Columns: %s."),
1383 join(", ", $table_summary)));
1384 $table->pushContent(HTML::colgroup(array('span' => count($this->_columns))));
1386 if ($tokens === false) {
1387 $table->pushContent(HTML::thead($row),
1388 HTML::tbody(false, $rows));
1392 $paging = Template("pagelink", $tokens);
1393 if ($this->_options['paging'] != 'bottom')
1394 $table->pushContent(HTML::thead($paging));
1395 $table->pushContent(HTML::tbody(false, HTML($row, $rows)));
1396 if ($this->_options['paging'] != 'top')
1397 $table->pushContent(HTML::tfoot($paging));
1400 $table->pushContent(HTML::thead($row),
1401 HTML::tbody(false, $rows));
1406 function _jsFlipAll() {
1408 function flipAll(formObj) {
1409 var isFirstSet = -1;
1410 for (var i=0; i < formObj.length; i++) {
1411 fldObj = formObj.elements[i];
1412 if ((fldObj.type == 'checkbox') && (fldObj.name.substring(0,2) == 'p[')) {
1413 if (isFirstSet == -1)
1414 isFirstSet = (fldObj.checked) ? true : false;
1415 fldObj.checked = (isFirstSet) ? false : true;
1421 /* recursive stack for private sublist options (azhead, cols) */
1422 function _saveOptions($opts) {
1423 $stack = array('pages' => $this->_pages);
1424 foreach ($opts as $k => $v) {
1425 $stack[$k] = $this->_options[$k];
1426 $this->_options[$k] = $v;
1428 if (empty($this->_stack))
1429 $this->_stack = new Stack();
1430 $this->_stack->push($stack);
1432 function _restoreOptions() {
1433 assert($this->_stack);
1434 $stack = $this->_stack->pop();
1435 $this->_pages = $stack['pages'];
1436 unset($stack['pages']);
1437 foreach ($stack as $k => $v) {
1438 $this->_options[$k] = $v;
1442 // 'cols' - split into several columns
1443 // 'azhead' - support <h3> grouping into initials
1444 // 'ordered' - OL or UL list (not yet inherited to all plugins)
1445 // 'comma' - condensed comma-list only, 1: no links, >1: with links
1446 // FIXME: only unique list entries, esp. with nopage
1447 function _generateList($caption='') {
1448 if (empty($this->_pages)) return; // stop recursion
1449 if (!isset($this->_options['listtype']))
1450 $this->_options['listtype'] = '';
1453 $out->pushContent(HTML::p($caption));
1454 // Semantic Search et al: only unique list entries, esp. with nopage
1455 if (!is_array($this->_pages[0]) and is_string($this->_pages[0])) {
1456 $this->_pages = array_unique($this->_pages);
1458 if (count($this->_sortby) > 0) $this->_sortPages();
1460 // need a recursive switch here for the azhead and cols grouping.
1461 if (!empty($this->_options['cols']) and $this->_options['cols'] > 1) {
1462 $count = count($this->_pages);
1463 $length = $count / $this->_options['cols'];
1464 $width = sprintf("%d", 100 / $this->_options['cols']).'%';
1465 $cols = HTML::tr(array('valign' => 'top'));
1466 for ($i=0; $i < $count; $i += $length) {
1467 $this->_saveOptions(array('cols' => 0));
1468 $this->_pages = array_slice($this->_pages, $i, $length);
1469 $cols->pushContent(HTML::td(/*array('width' => $width),*/
1470 $this->_generateList()));
1471 $this->_restoreOptions();
1473 // speed up table rendering by defining colgroups
1474 $out->pushContent(HTML::table(HTML::colgroup(array('span' => $this->_options['cols'],
1475 'width' => $width)),
1480 // Ignore azhead if not sorted by pagename
1481 if (!empty($this->_options['azhead'])
1482 and strstr($this->sortby($this->_options['sortby'], 'init'), "pagename")
1485 $cur_h = substr($this->_pages[0]->getName(), 0, 1);
1486 $out->pushContent(HTML::h3($cur_h));
1487 // group those pages together with same $h
1489 for ($i=0; $i < count($this->_pages); $i++) {
1490 $page =& $this->_pages[$i];
1491 $h = substr($page->getName(), 0, 1);
1492 if ($h != $cur_h and $i > $j) {
1493 $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
1494 $this->_pages = array_slice($this->_pages, $j, $i - $j);
1495 $out->pushContent($this->_generateList());
1496 $this->_restoreOptions();
1498 $out->pushContent(HTML::h3($h));
1502 if ($i > $j) { // flush the rest
1503 $this->_saveOptions(array('cols' => 0, 'azhead' => 0));
1504 $this->_pages = array_slice($this->_pages, $j, $i - $j);
1505 $out->pushContent($this->_generateList());
1506 $this->_restoreOptions();
1511 if ($this->_options['listtype'] == 'comma')
1512 $this->_options['comma'] = 2;
1513 if (!empty($this->_options['comma'])) {
1514 if ($this->_options['comma'] == 1)
1515 $out->pushContent($this->_generateCommaListAsString());
1517 $out->pushContent($this->_generateCommaList($this->_options['comma']));
1521 $do_paging = ( isset($this->_options['paging'])
1522 and !empty($this->_options['limit'])
1523 and $this->getTotal()
1524 and $this->_options['paging'] != 'none' );
1526 $tokens = $this->pagingTokens($this->getTotal(),
1527 count($this->_columns),
1528 $this->_options['limit']);
1530 $paging = Template("pagelink", $tokens);
1531 $out->pushContent(HTML::table($paging));
1534 if ($this->_options['listtype'] == 'ol')
1535 $this->_options['ordered'] = 1;
1536 elseif ($this->_options['listtype'] == 'ul')
1537 $this->_options['ordered'] = 0;
1538 if (!empty($this->_options['ordered']))
1539 $list = HTML::ol(array('class' => 'pagelist'));
1540 elseif ($this->_options['listtype'] == 'dl') {
1541 $list = HTML::dl(array('class' => 'pagelist'));
1543 $list = HTML::ul(array('class' => 'pagelist'));
1546 //TODO: currently we ignore limit here and hope that the backend didn't ignore it. (BackLinks)
1547 if (!empty($this->_options['limit']))
1548 list($offset, $pagesize) = $this->limit($this->_options['limit']);
1551 foreach ($this->_pages as $pagenum => $page) {
1552 $pagehtml = $this->_renderPageRow($page);
1553 if (!$pagehtml) continue;
1554 $group = ($i++ / $this->_group_rows);
1555 //TODO: here we switch every row, in tables every third.
1556 // unification or parametrized?
1557 $class = ($group % 2) ? 'oddrow' : 'evenrow';
1558 if ($this->_options['listtype'] == 'dl') {
1559 $header = WikiLink($page);
1560 //if ($this->_sortby['hi_content'])
1561 $list->pushContent(HTML::dt(array('class' => $class), $header),
1562 HTML::dd(array('class' => $class), $pagehtml));
1564 $list->pushContent(HTML::li(array('class' => $class), $pagehtml));
1565 if ($pagesize and $i > $pagesize) break;
1567 $out->pushContent($list);
1568 if ( $do_paging and $tokens ) {
1569 $out->pushContent(HTML::table($paging));
1575 // Condense list without a href links: "Page1, Page2, ..."
1576 // Alternative $seperator = HTML::Raw(' · ')
1577 // FIXME: only unique list entries, esp. with nopage
1578 function _generateCommaListAsString() {
1579 if (defined($this->_options['commasep']))
1580 $seperator = $this->_options['commasep'];
1584 foreach ($this->_pages as $pagenum => $page) {
1585 if ($s = $this->_renderPageRow($page)) // some pages are not viewable
1586 $pages[] = is_string($s) ? $s : $s->asString();
1588 return HTML(join($seperator, $pages));
1592 // Normal WikiLink list.
1593 // Future: 1 = reserved for plain string (see above)
1594 // 2 and more => HTML link specialization?
1595 // FIXME: only unique list entries, esp. with nopage
1596 function _generateCommaList($style = false) {
1597 if (defined($this->_options['commasep']))
1598 $seperator = HTLM::Raw($this->_options['commasep']);
1602 $html->pushContent($this->_renderPageRow($this->_pages[0]));
1603 next($this->_pages);
1604 foreach ($this->_pages as $pagenum => $page) {
1605 if ($s = $this->_renderPageRow($page)) // some pages are not viewable
1606 $html->pushContent($seperator, $s);
1611 function _emptyList($caption) {
1614 $html->pushContent(HTML::p($caption));
1615 if ($this->_messageIfEmpty)
1616 $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
1622 /* List pages with checkboxes to select from.
1623 * The [Select] button toggles via _jsFlipAll
1626 class PageList_Selectable
1629 function PageList_Selectable ($columns=false, $exclude='', $options = false) {
1631 if (!is_array($columns))
1632 $columns = explode(',', $columns);
1633 if (!in_array('checkbox',$columns))
1634 array_unshift($columns,'checkbox');
1636 $columns = array('checkbox','pagename');
1638 $this->PageList($columns, $exclude, $options);
1641 function addPageList ($array) {
1642 while (list($pagename,$selected) = each($array)) {
1643 if ($selected) $this->addPageSelected((string)$pagename);
1644 $this->addPage((string)$pagename);
1648 function addPageSelected ($pagename) {
1649 $this->_selected[$pagename] = 1;
1653 // $Log: not supported by cvs2svn $
1654 // Revision 1.143 2007/07/14 12:03:19 rurban
1655 // support listtype=dl and ranked search
1657 // Revision 1.142 2007/07/01 09:09:19 rurban
1658 // fix PageList with multiple lists: added id, fixed sortby REQUEST logic
1660 // Revision 1.141 2007/05/24 18:40:55 rurban
1661 // display list with tokens problem
1663 // Revision 1.140 2007/05/13 18:12:55 rurban
1664 // force adding a options[type] column: fixes LinkDatabase
1666 // Revision 1.139 2007/01/25 07:42:01 rurban
1669 // Revision 1.138 2007/01/20 11:24:15 rurban
1670 // Support paging limit if ->_pages is not yet limited by the backend (AllPagesByMe)
1672 // Revision 1.137 2007/01/07 18:43:08 rurban
1673 // Honor predefined ->_rows: hack to (re-)allow non-pagenames, used by WikiAdminUtils
1675 // Revision 1.136 2007/01/02 13:18:46 rurban
1676 // filter pageNames through limit, needed for xmlrpc. publish col->current_row and col->current_column counters during iteration. use table width=100% with captions. Clarify API: sortby,limit and exclude are strings.
1678 // Revision 1.135 2005/09/14 05:59:03 rurban
1679 // optimized explodePageList to use SQL when available
1680 // (titleSearch instead of getAllPages)
1682 // Revision 1.134 2005/09/11 14:55:05 rurban
1683 // implement fulltext stoplist
1685 // Revision 1.133 2005/08/27 09:41:37 rurban
1686 // new helper method
1688 // Revision 1.132 2005/04/09 09:16:15 rurban
1689 // fix recursive PageList azhead+cols listing
1691 // Revision 1.131 2005/02/04 10:48:06 rurban
1692 // fix usort ref warning. Thanks to Charles Corrigan
1694 // Revision 1.130 2005/01/28 12:07:36 rurban
1697 // Revision 1.129 2005/01/25 06:58:21 rurban
1700 // Revision 1.128 2004/12/26 17:31:35 rurban
1701 // fixed prev link logic
1703 // Revision 1.127 2004/12/26 17:19:28 rurban
1704 // dont break sideeffecting sortby flips on paging urls (MostPopular)
1706 // Revision 1.126 2004/12/16 18:26:57 rurban
1707 // Avoid double calculation
1709 // Revision 1.125 2004/11/25 17:20:49 rurban
1710 // and again a couple of more native db args: backlinks
1712 // Revision 1.124 2004/11/23 15:17:14 rurban
1713 // better support for case_exact search (not caseexact for consistency),
1714 // plugin args simplification:
1715 // handle and explode exclude and pages argument in WikiPlugin::getArgs
1716 // and exclude in advance (at the sql level if possible)
1717 // handle sortby and limit from request override in WikiPlugin::getArgs
1718 // ListSubpages: renamed pages to maxpages
1720 // Revision 1.123 2004/11/23 13:35:31 rurban
1721 // add case_exact search
1723 // Revision 1.122 2004/11/21 11:59:15 rurban
1724 // remove final \n to be ob_cache independent
1726 // Revision 1.121 2004/11/20 17:35:47 rurban
1727 // improved WantedPages SQL backends
1728 // PageList::sortby new 3rd arg valid_fields (override db fields)
1729 // WantedPages sql pager inexact for performance reasons:
1730 // assume 3 wantedfrom per page, to be correct, no getTotal()
1731 // support exclude argument for get_all_pages, new _sql_set()
1733 // Revision 1.120 2004/11/20 11:28:49 rurban
1734 // fix a yet unused PageList customPageListColumns bug (merge class not decl to _types)
1735 // change WantedPages to use PageList
1736 // change WantedPages to print the list of referenced pages, not just the count.
1737 // the old version was renamed to WantedPagesOld
1738 // fix and add handling of most standard PageList arguments (limit, exclude, ...)
1739 // TODO: pagename sorting, dumb/WantedPagesIter and SQL optimization
1741 // Revision 1.119 2004/11/11 14:34:11 rurban
1742 // minor clarifications
1744 // Revision 1.118 2004/11/01 10:43:55 rurban
1745 // seperate PassUser methods into seperate dir (memory usage)
1746 // fix WikiUser (old) overlarge data session
1747 // remove wikidb arg from various page class methods, use global ->_dbi instead
1750 // Revision 1.117 2004/10/14 21:06:01 rurban
1751 // fix dumphtml with USE_PATH_INFO (again). fix some PageList refs
1753 // Revision 1.116 2004/10/14 19:19:33 rurban
1754 // loadsave: check if the dumped file will be accessible from outside.
1755 // and some other minor fixes. (cvsclient native not yet ready)
1757 // Revision 1.115 2004/10/14 17:15:05 rurban
1758 // remove class _PageList_Page, fix sortby=0 (start with 1, use strings), fix _PageList_Column_content for old phps, hits as int
1760 // Revision 1.114 2004/10/12 13:13:19 rurban
1761 // php5 compatibility (5.0.1 ok)
1763 // Revision 1.113 2004/10/05 17:00:03 rurban
1764 // support paging for simple lists
1765 // fix RatingDb sql backend.
1766 // remove pages from AllPages (this is ListPages then)
1768 // Revision 1.112 2004/10/04 23:39:58 rurban
1769 // list of page objects
1771 // Revision 1.111 2004/09/24 18:50:45 rurban
1772 // fix paging of SqlResult
1774 // Revision 1.110 2004/09/17 14:43:31 rurban
1777 // Revision 1.109 2004/09/17 14:22:10 rurban
1780 // Revision 1.108 2004/09/17 12:46:22 rurban
1781 // seperate pagingTokens()
1782 // support new default args: comma (1 and 2), commasep, ordered, cols,
1785 // Revision 1.107 2004/09/14 10:29:08 rurban
1786 // exclude pages already in addPages to simplify plugins
1788 // Revision 1.106 2004/09/06 10:22:14 rurban
1789 // oops, forgot global request
1791 // Revision 1.105 2004/09/06 08:38:30 rurban
1792 // modularize paging helper (for SqlResult)
1794 // Revision 1.104 2004/08/18 11:01:55 rurban
1795 // fixed checkbox list Select button:
1796 // no GET request on click,
1797 // only select the list checkbox entries, no other options.
1799 // Revision 1.103 2004/07/09 10:06:49 rurban
1800 // Use backend specific sortby and sortable_columns method, to be able to
1801 // select between native (Db backend) and custom (PageList) sorting.
1802 // Fixed PageList::AddPageList (missed the first)
1803 // Added the author/creator.. name to AllPagesBy...
1804 // display no pages if none matched.
1805 // Improved dba and file sortby().
1806 // Use &$request reference
1808 // Revision 1.102 2004/07/08 21:32:35 rurban
1809 // Prevent from more warnings, minor db and sort optimizations
1811 // Revision 1.101 2004/07/08 19:04:41 rurban
1812 // more unittest fixes (file backend, metadata RatingsDb)
1814 // Revision 1.100 2004/07/07 15:02:26 dfrankow
1815 // Take out if that prevents column sorting
1817 // Revision 1.99 2004/07/02 18:49:02 dfrankow
1818 // Change one line so that if addPageList() is passed null, it is still
1819 // okay. The unit tests do this (ask to list AllUsers where there are no
1820 // users, or something like that).
1822 // Revision 1.98 2004/07/01 08:51:22 rurban
1823 // dumphtml: added exclude, print pagename before processing
1825 // Revision 1.97 2004/06/29 09:11:10 rurban
1826 // More memory optimization:
1827 // don't cache unneeded _cached_html and %content for content and size columns
1828 // (only if sortable, which will fail for too many pages)
1830 // Revision 1.96 2004/06/29 08:47:42 rurban
1831 // Memory optimization (reference to parent, smart bool %content)
1832 // Fixed class grouping in table
1834 // Revision 1.95 2004/06/28 19:00:01 rurban
1835 // removed non-portable LIMIT 1 (it's getOne anyway)
1836 // removed size from info=most: needs to much memory
1838 // Revision 1.94 2004/06/27 10:26:02 rurban
1839 // oci8 patch by Philippe Vanhaesendonck + some ADODB notes+fixes
1841 // Revision 1.93 2004/06/25 14:29:17 rurban
1842 // WikiGroup refactoring:
1843 // global group attached to user, code for not_current user.
1844 // improved helpers for special groups (avoid double invocations)
1845 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1846 // fixed a XHTML validation error on userprefs.tmpl
1848 // Revision 1.92 2004/06/21 17:01:39 rurban
1849 // fix typo and rating method call
1851 // Revision 1.91 2004/06/21 16:22:29 rurban
1852 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1853 // fixed dumping buttons locally (images/buttons/),
1854 // support pages arg for dumphtml,
1855 // optional directory arg for dumpserial + dumphtml,
1856 // fix a AllPages warning,
1857 // show dump warnings/errors on DEBUG,
1858 // don't warn just ignore on wikilens pagelist columns, if not loaded.
1859 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1861 // Revision 1.90 2004/06/18 14:38:21 rurban
1862 // adopt new PageList style
1864 // Revision 1.89 2004/06/17 13:16:08 rurban
1865 // apply wikilens work to PageList: all columns are sortable (slightly fixed)
1867 // Revision 1.88 2004/06/14 11:31:35 rurban
1868 // renamed global $Theme to $WikiTheme (gforge nameclash)
1869 // inherit PageList default options from PageList
1870 // default sortby=pagename
1871 // use options in PageList_Selectable (limit, sortby, ...)
1872 // added action revert, with button at action=diff
1873 // added option regex to WikiAdminSearchReplace
1875 // Revision 1.87 2004/06/13 16:02:12 rurban
1876 // empty list of pages if user=[] and not authenticated.
1878 // Revision 1.86 2004/06/13 15:51:37 rurban
1879 // Support pagelist filter for current author,owner,creator by []
1881 // Revision 1.85 2004/06/13 15:33:19 rurban
1882 // new support for arguments owner, author, creator in most relevant
1883 // PageList plugins. in WikiAdmin* via preSelectS()
1885 // Revision 1.84 2004/06/08 13:51:56 rurban
1886 // some comments only
1888 // Revision 1.83 2004/05/18 13:35:39 rurban
1889 // improve Pagelist layout by equal pagename width for limited lists
1891 // Revision 1.82 2004/05/16 22:07:35 rurban
1892 // check more config-default and predefined constants
1893 // various PagePerm fixes:
1894 // fix default PagePerms, esp. edit and view for Bogo and Password users
1895 // implemented Creator and Owner
1896 // BOGOUSERS renamed to BOGOUSER
1897 // fixed syntax errors in signin.tmpl
1899 // Revision 1.81 2004/05/13 12:30:35 rurban
1900 // fix for MacOSX border CSS attr, and if sort buttons are not found
1902 // Revision 1.80 2004/04/20 00:56:00 rurban
1903 // more paging support and paging fix for shorter lists
1905 // Revision 1.79 2004/04/20 00:34:16 rurban
1906 // more paging support
1908 // Revision 1.78 2004/04/20 00:06:03 rurban
1909 // themable paging support
1911 // Revision 1.77 2004/04/18 01:11:51 rurban
1912 // more numeric pagename fixes.
1913 // fixed action=upload with merge conflict warnings.
1914 // charset changed from constant to global (dynamic utf-8 switching)
1917 // (c-file-style: "gnu")
1921 // c-basic-offset: 4
1922 // c-hanging-comment-ender-p: nil
1923 // indent-tabs-mode: nil