1 <?php rcs_id('$Id: PageList.php,v 1.94 2004-06-27 10:26:02 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).
54 * rows arguments for multiple pages/multiple rows.
56 * ->supportedArgs() which arguments are supported, so that the plugin
57 * doesn't explictly need to declare it
58 * Status: already merged in some plugins calls
61 * list not as <ul> or table, but as simple comma-seperated list
63 * fix memory exhaustion on large pagelists.
64 * Status: fixed 2004-06-25 16:19:36 rurban but needs further testing.
66 class _PageList_Column_base {
67 var $_tdattr = array();
69 function _PageList_Column_base ($default_heading, $align = false) {
70 $this->_heading = $default_heading;
73 // align="char" isn't supported by any browsers yet :(
74 //if (is_array($align))
75 // $this->_tdattr = $align;
77 $this->_tdattr['align'] = $align;
81 function format ($pagelist, $page_handle, &$revision_handle) {
82 return HTML::td($this->_tdattr,
84 $this->_getValue($page_handle, $revision_handle),
88 function getHeading () {
89 return $this->_heading;
92 function setHeading ($heading) {
93 $this->_heading = $heading;
99 if (1 or in_array($this->_field, PageList::sortable_columns())) {
100 // multiple comma-delimited sortby args: "+hits,+pagename"
101 // asc or desc: +pagename, -pagename
102 $sortby = PageList::sortby($this->_field, 'flip_order');
103 //Fixme: pass all also other GET args along. (limit, p[])
104 //TODO: support GET and POST
105 $s = HTML::a(array('href' =>
106 $GLOBALS['request']->GetURLtoSelf(array('sortby' => $sortby,
108 'class' => 'pagetitle',
109 'title' => sprintf(_("Sort by %s"), $this->_field)),
110 HTML::raw(' '), HTML::u($this->_heading), HTML::raw(' '));
112 $s = HTML(HTML::raw(' '), HTML::u($this->_heading), HTML::raw(' '));
114 return HTML::th(array('align' => 'center'),$s);
119 function button_heading ($pagelist, $colNum) {
120 global $WikiTheme, $request;
122 if (1 or in_array($this->_field, PageList::sortable_columns())) {
123 // multiple comma-delimited sortby args: "+hits,+pagename"
125 $noimg_src = $WikiTheme->getButtonURL('no_order');
127 $noimg = HTML::img(array('src' => $noimg_src,
133 $noimg = HTML::raw(' ');
134 if ($request->getArg('sortby')) {
135 if ($pagelist->sortby($colNum, 'check')) { // show icon?
136 $sortby = $pagelist->sortby($request->getArg('sortby'), 'flip_order');
137 $request->setArg('sortby', $sortby);
138 $desc = (substr($sortby,0,1) == '-'); // asc or desc? (+pagename, -pagename)
139 $src = $WikiTheme->getButtonURL($desc ? 'asc_order' : 'desc_order');
141 $sortby = $pagelist->sortby($colNum, 'init');
144 $sortby = $pagelist->sortby($colNum, 'init');
148 //$img->setAttr('alt', _("Click to sort"));
150 $img = HTML::img(array('src' => $src,
154 'alt' => _("Click to reverse sort order")));
156 $s = HTML::a(array('href' =>
157 //Fixme: pass all also other GET args along. (limit, p[])
158 //Fixme: convert to POST submit[sortby]
159 $request->GetURLtoSelf(array('sortby' => $sortby,
161 'class' => 'gridbutton',
162 'title' => sprintf(_("Click to sort by %s"), $this->_field)),
169 HTML::raw(' '));
171 $s = HTML(HTML::raw(' '), $this->_heading, HTML::raw(' '));
173 return HTML::th(array('align' => 'center', 'valign' => 'middle',
174 'class' => 'gridbutton'), $s);
178 * Take two columns of this type and compare them.
179 * An undefined value is defined to be < than the smallest defined value.
180 * This base class _compare only works if the value is simple (e.g., a number).
182 * @param $colvala $this->_getValue() of column a
183 * @param $colvalb $this->_getValue() of column b
185 * @return -1 if $a < $b, 1 if $a > $b, 0 otherwise.
187 function _compare($colvala, $colvalb) {
188 if (is_string($colvala))
189 return strcmp($colvala,$colvalb);
191 if (($colvala === $colvalb) || (!isset($colvala) && !isset($colvalb))) {
194 $ret = (!isset($colvala) || ($colvala < $colvalb)) ? -1 : 1;
200 class _PageList_Column extends _PageList_Column_base {
201 function _PageList_Column ($field, $default_heading, $align = false) {
202 $this->_PageList_Column_base($default_heading, $align);
204 $this->_need_rev = substr($field, 0, 4) == 'rev:';
205 $this->_iscustom = substr($field, 0, 7) == 'custom:';
206 if ($this->_iscustom) {
207 $this->_field = substr($field, 7);
209 elseif ($this->_need_rev)
210 $this->_field = substr($field, 4);
212 $this->_field = $field;
215 function _getValue ($page_handle, &$revision_handle) {
216 if ($this->_need_rev) {
217 if (!$revision_handle)
218 $revision_handle = $page_handle->getCurrentRevision();
219 return $revision_handle->get($this->_field);
222 return $page_handle->get($this->_field);
226 function _getSortableValue ($page_handle, &$revision_handle) {
227 return _PageList_Column::_getValue($page_handle, $revision_handle);
231 /* overcome a call_user_func limitation by not being able to do:
232 * call_user_func_array(array(&$class, $class_name), $params);
233 * So we need $class = new $classname($params);
234 * And we add a 4th param for the parent $pagelist object
236 class _PageList_Column_custom extends _PageList_Column {
237 function _PageList_Column_custom($params) {
238 $this->_pagelist =& $params[3];
239 $this->_PageList_Column($params[0], $params[1], $params[2]);
243 class _PageList_Column_size extends _PageList_Column {
244 function _getValue ($page_handle, &$revision_handle) {
245 if (!$revision_handle)
246 $revision_handle = $page_handle->getCurrentRevision();
247 return $this->_getSize($revision_handle);
250 function _getSortableValue ($page_handle, &$revision_handle) {
251 if (!$revision_handle)
252 $revision_handle = $page_handle->getCurrentRevision();
253 return (empty($revision_handle->_data['%content']))
254 ? 0 : strlen($revision_handle->_data['%content']);
257 function _getSize($revision_handle) {
258 $bytes = @strlen($revision_handle->_data['%content']);
259 return ByteFormatter($bytes);
264 class _PageList_Column_bool extends _PageList_Column {
265 function _PageList_Column_bool ($field, $default_heading, $text = 'yes') {
266 $this->_PageList_Column($field, $default_heading, 'center');
267 $this->_textIfTrue = $text;
268 $this->_textIfFalse = new RawXml('—'); //mdash
271 function _getValue ($page_handle, &$revision_handle) {
272 //FIXME: check if $this is available in the parent (->need_rev)
273 $val = _PageList_Column::_getValue($page_handle, $revision_handle);
274 return $val ? $this->_textIfTrue : $this->_textIfFalse;
278 class _PageList_Column_checkbox extends _PageList_Column {
279 function _PageList_Column_checkbox ($field, $default_heading, $name='p') {
280 $this->_name = $name;
281 $heading = HTML::input(array('type' => 'button',
282 'title' => _("Click to de-/select all pages"),
284 'name' => $default_heading,
285 'value' => $default_heading,
286 'onclick' => "flipAll(this.form)"
288 $this->_PageList_Column($field, $heading, 'center');
290 function _getValue ($pagelist, $page_handle, &$revision_handle) {
291 $pagename = $page_handle->getName();
292 $selected = !empty($pagelist->_selected[$pagename]);
293 if (strstr($pagename,'[') or strstr($pagename,']')) {
294 $pagename = str_replace(array('[',']'),array('%5B','%5D'),$pagename);
297 return HTML::input(array('type' => 'checkbox',
298 'name' => $this->_name . "[$pagename]",
300 'checked' => 'CHECKED'));
302 return HTML::input(array('type' => 'checkbox',
303 'name' => $this->_name . "[$pagename]",
307 function format ($pagelist, $page_handle, &$revision_handle) {
308 return HTML::td($this->_tdattr,
310 $this->_getValue($pagelist, $page_handle, $revision_handle),
311 HTML::raw(' '));
315 class _PageList_Column_time extends _PageList_Column {
316 function _PageList_Column_time ($field, $default_heading) {
317 $this->_PageList_Column($field, $default_heading, 'right');
319 $this->Theme = &$WikiTheme;
322 function _getValue ($page_handle, &$revision_handle) {
323 $time = _PageList_Column::_getValue($page_handle, $revision_handle);
324 return $this->Theme->formatDateTime($time);
328 class _PageList_Column_version extends _PageList_Column {
329 function _getValue ($page_handle, &$revision_handle) {
330 if (!$revision_handle)
331 $revision_handle = $page_handle->getCurrentRevision();
332 return $revision_handle->getVersion();
336 // Output is hardcoded to limit of first 50 bytes. Otherwise
337 // on very large Wikis this will fail if used with AllPages
338 // (PHP memory limit exceeded)
339 // FIXME: old PHP without superglobals
340 class _PageList_Column_content extends _PageList_Column {
341 function _PageList_Column_content ($field, $default_heading, $align = false) {
342 $this->_PageList_Column($field, $default_heading, $align);
344 if ($field == 'content') {
345 $this->_heading .= sprintf(_(" ... first %d bytes"),
347 } elseif ($field == 'hi_content') {
348 if (!empty($_POST['admin_replace'])) {
349 $search = $_POST['admin_replace']['from'];
350 $this->_heading .= sprintf(_(" ... around %s"),
355 function _getValue ($page_handle, &$revision_handle) {
356 if (!$revision_handle)
357 $revision_handle = $page_handle->getCurrentRevision();
358 // Not sure why implode is needed here, I thought
359 // getContent() already did this, but it seems necessary.
360 $c = implode("\n", $revision_handle->getContent());
361 if ($this->_field == 'hi_content') {
362 $search = $_POST['admin_replace']['from'];
363 if ($search and ($i = strpos($c,$search))) {
364 $l = strlen($search);
365 $j = max(0,$i - ($this->bytes / 2));
366 return HTML::div(array('style' => 'font-size:x-small'),
367 HTML::div(array('class' => 'transclusion'),
368 HTML::span(substr($c, $j, ($this->bytes / 2))),
369 HTML::span(array("style"=>"background:yellow"),$search),
370 HTML::span(substr($c, $i+$l, ($this->bytes / 2))))
373 $c = sprintf(_("%s not found"),
375 return HTML::div(array('style' => 'font-size:x-small','align'=>'center'),
378 } elseif (($len = strlen($c)) > $this->bytes) {
379 $c = substr($c, 0, $this->bytes);
381 include_once('lib/BlockParser.php');
382 // false --> don't bother processing hrefs for embedded WikiLinks
383 $ct = TransformText($c, $revision_handle->get('markup'), false);
384 return HTML::div(array('style' => 'font-size:x-small'),
385 HTML::div(array('class' => 'transclusion'), $ct),
386 // Don't show bytes here if size column present too
387 ($this->parent->_columns_seen['size'] or !$len) ? "" :
388 ByteFormatter($len, /*$longformat = */true));
391 function _getSortableValue ($page_handle, &$revision_handle) {
392 return substr(_PageList_Column::_getValue($page_handle, $revision_handle),0,50);
396 class _PageList_Column_author extends _PageList_Column {
397 function _PageList_Column_author ($field, $default_heading, $align = false) {
398 _PageList_Column::_PageList_Column($field, $default_heading, $align);
399 $this->dbi =& $GLOBALS['request']->getDbh();
402 function _getValue ($page_handle, &$revision_handle) {
403 $author = _PageList_Column::_getValue($page_handle, $revision_handle);
404 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
405 return WikiLink($author);
411 class _PageList_Column_owner extends _PageList_Column_author {
412 function _getValue ($page_handle, &$revision_handle) {
413 $author = $page_handle->getOwner();
414 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
415 return WikiLink($author);
421 class _PageList_Column_creator extends _PageList_Column_author {
422 function _getValue ($page_handle, &$revision_handle) {
423 $author = $page_handle->getCreator();
424 if (isWikiWord($author) && $this->dbi->isWikiPage($author))
425 return WikiLink($author);
431 class _PageList_Column_pagename extends _PageList_Column_base {
432 var $_field = 'pagename';
434 function _PageList_Column_pagename () {
435 $this->_PageList_Column_base(_("Page Name"));
437 $this->dbi = &$request->getDbh();
440 function _getValue ($page_handle, &$revision_handle) {
441 if ($this->dbi->isWikiPage($page_handle->getName()))
442 return WikiLink($page_handle);
444 return WikiLink($page_handle, 'unknown');
447 function _getSortableValue ($page_handle, &$revision_handle) {
448 return $page_handle->getName();
452 * Compare two pagenames for sorting. See _PageList_Column::_compare.
454 function _compare($colvala, $colvalb) {
455 return strcmp($colvala, $colvalb);
460 * A class to bundle up a page with a reference to PageList, so that
461 * the compare function for usort() has access to it all.
462 * This is a hack necessitated by the interface to usort()-- comparators
463 * can't get information upon construction; you get a comparator by class
464 * name, not by instance.
465 * @author: Dan Frankowski
467 class _PageList_Page {
471 function _PageList_Page($pagelist, $page_handle) {
472 $this->_pagelist = $pagelist;
473 $this->_page = $page_handle;
476 function getPageList() {
477 return $this->_pagelist;
486 var $_group_rows = 3;
487 var $_columns = array();
488 var $_columnsMap = array(); // Maps column name to column number.
489 var $_excluded_pages = array();
490 var $_pages = array();
492 var $_pagename_seen = false;
493 var $_types = array();
494 var $_options = array();
495 var $_selected = array();
496 var $_sortby = array();
499 function PageList ($columns = false, $exclude = false, $options = false) {
501 $this->_options = $options;
503 // let plugins predefine only certain objects, such its own custom pagelist columns
504 if (!empty($this->_options['types'])) {
505 $this->_types = $this->_options['types'];
506 unset($this->_options['types']);
508 $this->_initAvailableColumns();
511 'all' => array_diff(array_keys($this->_types), // all but...
512 array('checkbox','remove','renamed_pagename',
513 'content','hi_content','perm','acl')),
514 'most' => array('pagename','mtime','author','size','hits'),
515 'some' => array('pagename','mtime','author')
518 if (!is_array($columns))
519 $columns = explode(',', $columns);
520 // expand symbolic columns:
521 foreach ($symbolic_columns as $symbol => $cols) {
522 if (in_array($symbol,$columns)) { // e.g. 'checkbox,all'
523 $columns = array_diff(array_merge($columns,$cols),array($symbol));
526 if (!in_array('pagename',$columns))
527 $this->_addColumn('pagename');
528 foreach ($columns as $col) {
529 $this->_addColumn($col);
532 // If 'pagename' is already present, _addColumn() will not add it again
533 $this->_addColumn('pagename');
535 foreach (array('sortby','limit','paging','count') as $key) {
536 if (!empty($options) and !empty($options[$key])) {
537 $this->_options[$key] = $options[$key];
539 $this->_options[$key] = $GLOBALS['request']->getArg($key);
542 $this->_options['sortby'] = $this->sortby($this->_options['sortby'], 'init');
544 if (!is_array($exclude))
545 $exclude = $this->explodePageList($exclude,false,
546 $this->_options['sortby'],
547 $this->_options['limit']);
548 $this->_excluded_pages = $exclude;
550 $this->_messageIfEmpty = _("<no matches>");
553 // Currently PageList takes these arguments:
554 // 1: info, 2: exclude, 3: hash of options
555 // Here we declare which options are supported, so that
556 // the calling plugin may simply merge this with its own default arguments
557 function supportedArgs () {
558 return array(//Currently supported options:
559 'info' => 'pagename',
560 'exclude' => '', // also wildcards and comma-seperated lists
562 /* select pages by meta-data: */
563 'author' => false, // current user by []
564 'owner' => false, // current user by []
565 'creator' => false, // current user by []
567 // for the sort buttons in <th>
568 'sortby' => 'pagename', // same as for WikiDB::getAllPages
570 //PageList pager options:
571 // These options may also be given to _generate(List|Table) later
572 // But limit and offset might help the query WikiDB::getAllPages()
573 'cols' => 1, // side-by-side display of list (1-3)
574 'limit' => 0, // number of rows (pagesize)
575 'paging' => 'auto', // 'auto' normal paging mode
576 // // 'smart' drop 'info' columns and enhance rows
577 // // when the list becomes large
578 // // 'none' don't page at all
579 //'azhead' => 0 // provide shortcut links to pages starting with different letters
583 function setCaption ($caption_string) {
584 $this->_caption = $caption_string;
587 function getCaption () {
588 // put the total into the caption if needed
589 if (is_string($this->_caption) && strstr($this->_caption, '%d'))
590 return sprintf($this->_caption, $this->getTotal());
591 return $this->_caption;
594 function setMessageIfEmpty ($msg) {
595 $this->_messageIfEmpty = $msg;
599 function getTotal () {
600 return !empty($this->_options['count'])
601 ? (integer) $this->_options['count'] : count($this->_pages);
604 function isEmpty () {
605 return empty($this->_pages);
608 function addPage($page_handle) {
609 $this->_pages[] = new _PageList_Page($this, $page_handle);
612 function _getPageFromHandle($ph) {
614 if (is_string($page_handle)) {
615 if (empty($page_handle)) return $page_handle;
616 $dbi = $GLOBALS['request']->getDbh();
617 $page_handle = $dbi->getPage($page_handle);
623 * Take a PageList_Page object, and return an HTML object to display
624 * it in a table or list row.
626 function _renderPageRow ($pagelist_page) {
627 $page_handle = $pagelist_page->getPage();
629 $page_handle = $this->_getPageFromHandle($page_handle);
630 if (!isset($page_handle) || empty($page_handle)
631 || in_array($page_handle->getName(), $this->_excluded_pages))
632 return; // exclude page.
634 //FIXME. only on sf.net
635 if (!is_object($page_handle)) {
636 trigger_error("PageList: Invalid page_handle $page_handle", E_USER_WARNING);
639 // enforce view permission
640 if (!mayAccessPage('view',$page_handle->getName()))
643 $group = (int)($this->getTotal() / $this->_group_rows);
644 $class = ($group % 2) ? 'oddrow' : 'evenrow';
645 $revision_handle = false;
646 $this->_maxlen = max($this->_maxlen, strlen($page_handle->getName()));
648 if (count($this->_columns) > 1) {
649 $row = HTML::tr(array('class' => $class));
650 foreach ($this->_columns as $col)
651 $row->pushContent($col->format($this, $page_handle, $revision_handle));
654 $col = $this->_columns[0];
655 $row = $col->_getValue($page_handle, $revision_handle);
661 function addPages ($page_iter) {
662 //Todo: if limit check max(strlen(pagename))
663 while ($page = $page_iter->next())
664 $this->addPage($page);
667 function addPageList (&$list) {
669 while ($page = next($list))
670 $this->addPage((string)$page);
674 global $DBParams, $request;
675 if ($DBParams['dbtype'] == 'SQL' or $DBParams['dbtype'] == 'ADODB') {
676 $dbi =& $request->getDbh();
677 extract($dbi->_backend->_table_names);
678 if ($DBParams['dbtype'] == 'SQL') {
679 //FIXME: LIMIT not portable
680 $res = $dbi->_backend->_dbh->getOne("SELECT max(length(pagename)) FROM $page_tbl LIMIT 1");
681 if (DB::isError($res) || empty($res)) return false;
683 } elseif ($DBParams['dbtype'] == 'ADODB') {
684 //FIXME: LIMIT not portable
685 $row = $dbi->_backend->_dbh->getRow("SELECT max(length(pagename)) FROM $page_tbl LIMIT 1");
686 return $row ? $row[0] : false;
692 function getContent() {
693 // Note that the <caption> element wants inline content.
694 $caption = $this->getCaption();
696 if ($this->isEmpty())
697 return $this->_emptyList($caption);
698 elseif (count($this->_columns) == 1)
699 return $this->_generateList($caption);
701 return $this->_generateTable($caption);
704 function printXML() {
705 PrintXML($this->getContent());
709 return AsXML($this->getContent());
712 /** Now all columns are sortable.
713 * These are the colums which have native WikiDB backend methods.
715 function sortable_columns() {
716 return array('pagename','mtime','hits');
720 * Handle sortby requests for the DB iterator and table header links.
721 * Prefix the column with + or - like "+pagename","-mtime", ...
722 * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
723 * 'db' "-pagename" => "pagename DESC"
724 * Now all columns are sortable. (patch by DanFr)
726 function sortby ($column, $action) {
727 if (empty($column)) return;
728 //support multiple comma-delimited sortby args: "+hits,+pagename"
729 if (strstr($column,',')) {
731 foreach (explode(',',$column) as $col) {
732 $result[] = $this->sortby($col,$action);
734 return join(",",$result);
736 if (substr($column,0,1) == '+') {
737 $order = '+'; $column = substr($column,1);
738 } elseif (substr($column,0,1) == '-') {
739 $order = '-'; $column = substr($column,1);
741 // default order: +pagename, -mtime, -hits
743 if (in_array($column,array('mtime','hits')))
747 if ($action == 'flip_order') {
748 return ($order == '+' ? '-' : '+') . $column;
749 } elseif ($action == 'init') {
750 $this->_sortby[$column] = $order;
751 return $order . $column;
752 } elseif ($action == 'check') {
753 return (!empty($this->_sortby[$column]) or
754 ($GLOBALS['request']->getArg('sortby') and
755 strstr($GLOBALS['request']->getArg('sortby'),$column)));
756 } elseif ($action == 'db') {
757 // asc or desc: +pagename, -pagename
758 return $column . ($order == '+' ? ' ASC' : ' DESC');
763 // echo implode(":",explodeList("Test*",array("xx","Test1","Test2")));
764 function explodePageList($input, $perm = false, $sortby=false, $limit=false) {
765 // expand wildcards from list of all pages
766 if (preg_match('/[\?\*]/',$input)) {
767 $dbi = $GLOBALS['request']->getDbh();
768 $allPagehandles = $dbi->getAllPages($perm,$sortby,$limit);
769 while ($pagehandle = $allPagehandles->next()) {
770 $allPages[] = $pagehandle->getName();
772 return explodeList($input, $allPages);
774 //TODO: do the sorting, normally not needed if used for exclude only
775 return explode(',',$input);
779 function allPagesByAuthor($wildcard, $perm=false, $sortby=false, $limit=false) {
780 $dbi = $GLOBALS['request']->getDbh();
781 $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit);
783 if ($wildcard === '[]') {
784 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
785 if (!$wildcard) return $allPages;
787 while ($pagehandle = $allPagehandles->next()) {
788 $name = $pagehandle->getName();
789 $author = $pagehandle->getAuthor();
791 if (preg_match('/[\?\*]/', $wildcard)) {
792 if (glob_match($wildcard, $author))
794 } elseif ($wildcard == $author) {
802 function allPagesByOwner($wildcard, $perm=false, $sortby=false, $limit=false) {
803 $dbi = $GLOBALS['request']->getDbh();
804 $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit);
806 if ($wildcard === '[]') {
807 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
808 if (!$wildcard) return $allPages;
810 while ($pagehandle = $allPagehandles->next()) {
811 $name = $pagehandle->getName();
812 $owner = $pagehandle->getOwner();
814 if (preg_match('/[\?\*]/', $wildcard)) {
815 if (glob_match($wildcard, $owner))
817 } elseif ($wildcard == $owner) {
825 function allPagesByCreator($wildcard, $perm=false, $sortby=false, $limit=false) {
826 $dbi = $GLOBALS['request']->getDbh();
827 $allPagehandles = $dbi->getAllPages($perm, $sortby, $limit);
829 if ($wildcard === '[]') {
830 $wildcard = $GLOBALS['request']->_user->getAuthenticatedId();
831 if (!$wildcard) return $allPages;
833 while ($pagehandle = $allPagehandles->next()) {
834 $name = $pagehandle->getName();
835 $creator = $pagehandle->getCreator();
837 if (preg_match('/[\?\*]/', $wildcard)) {
838 if (glob_match($wildcard, $creator))
840 } elseif ($wildcard == $creator) {
851 /** Plugin and theme hooks:
852 * If the pageList is initialized with $options['types'] these types are also initialized,
853 * overriding the standard types.
855 function _initAvailableColumns() {
856 global $customPageListColumns;
860 => new _PageList_Column_content('rev:content', _("Content")),
861 // new: plugin specific column types initialised by the relevant plugins
863 'hi_content' // with highlighted search for SearchReplace
864 => new _PageList_Column_content('rev:hi_content', _("Content")),
866 => new _PageList_Column_remove('remove', _("Remove")),
867 // initialised by the plugin
869 => new _PageList_Column_renamed_pagename('rename', _("Rename to")),
871 => new _PageList_Column_perm('perm', _("Permission")),
873 => new _PageList_Column_acl('acl', _("ACL")),
876 => new _PageList_Column_checkbox('p', _("Select")),
878 => new _PageList_Column_pagename,
880 => new _PageList_Column_time('rev:mtime', _("Last Modified")),
882 => new _PageList_Column('hits', _("Hits"), 'right'),
884 => new _PageList_Column_size('rev:size', _("Size"), 'right'),
885 /*array('align' => 'char', 'char' => ' ')*/
887 => new _PageList_Column('rev:summary', _("Last Summary")),
889 => new _PageList_Column_version('rev:version', _("Version"),
892 => new _PageList_Column_author('rev:author', _("Last Author")),
894 => new _PageList_Column_owner('author_id', _("Owner")),
896 => new _PageList_Column_creator('author_id', _("Creator")),
899 => new _PageList_Column_author('group', _("Group")),
902 => new _PageList_Column_bool('locked', _("Locked"),
905 => new _PageList_Column_bool('rev:is_minor_edit',
906 _("Minor Edit"), _("minor")),
908 => new _PageList_Column('rev:markup', _("Markup")),
909 // 'rating' initialised by the wikilens theme hook: addPageListColumn
912 => new _PageList_Column_rating('rating', _("Rate")),
915 if (empty($this->_types))
916 $this->_types = array();
917 // add plugin specific pageList columns, initialized by $options['types']
918 $this->_types = array_merge($standard_types, $this->_types);
919 // add theme custom specific pageList columns:
920 // set the 4th param as the current pagelist object.
921 if (!empty($customPageListColumns)) {
922 foreach ($customPageListColumns as $column => $params) {
923 $class_name = array_shift($params);
925 $class = new $class_name($params);
927 $this->_types = array_merge($this->_types, $customPageListColumns);
931 function getOption($option) {
932 if (array_key_exists($option, $this->_options)) {
933 return $this->_options[$option];
941 * Add a column to this PageList, given a column name.
942 * The name is a type, and optionally has a : and a label. Examples:
947 * mtime:Last modified
949 * If this function is called multiple times for the same type, the
950 * column will only be added the first time, and ignored the succeeding times.
951 * If you wish to add multiple columns of the same type, use addColumnObject().
954 * @return true if column is added, false otherwise
956 function _addColumn ($column) {
958 if (isset($this->_columns_seen[$column]))
959 return false; // Already have this one.
960 if (!isset($this->_types[$column]))
961 $this->_initAvailableColumns();
962 $this->_columns_seen[$column] = true;
964 if (strstr($column, ':'))
965 list ($column, $heading) = explode(':', $column, 2);
967 if (!isset($this->_types[$column])) {
968 $silently_ignore = array('numbacklinks','rating','coagreement','minmisery',
969 'averagerating','top3recs');
970 if (!in_array($column,$silently_ignore))
971 trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE);
974 if ($column == 'ratingwidget' and !$GLOBALS['request']->_user->isSignedIn())
977 $this->addColumnObject($this->_types[$column]);
983 * Add a column to this PageList, given a column object.
985 * @param $col object An object derived from _PageList_Column.
987 function addColumnObject($col) {
988 if (is_array($col)) {// custom column object
990 $class_name = array_shift($params);
992 $col = new $class_name($params);
994 $heading = $col->getHeading();
995 if (!empty($heading))
996 $col->setHeading($heading);
998 $this->_columns[] = $col;
999 $this->_columnsMap[$col->_field] = count($this->_columns)-1;
1003 * Compare _PageList_Page objects.
1005 function _pageCompare($a, $b) {
1006 $pagelist = $a->getPageList();
1007 $pagea = $a->getPage();
1008 $pageb = $b->getPage();
1009 if (count($pagelist->_sortby) == 0) {
1010 // No columns to sort by
1014 foreach ($pagelist->_sortby as $colNum => $direction) {
1015 if (!isset($pagelist->_columns_seen[$colNum])) return 0;
1017 if (!is_int($colkey)) { // or column fieldname
1018 $colkey = $pagelist->_columnsMap[$colNum];
1020 $col = $pagelist->_columns[$colkey];
1022 $revision_handle = false;
1023 $pagea = PageList::_getPageFromHandle($pagea); // If a string, convert to page
1024 assert(isa($pagea, 'WikiDB_Page'));
1025 assert(isset($col));
1026 $aval = $col->_getSortableValue($pagea, $revision_handle);
1027 $pageb = PageList::_getPageFromHandle($pageb); // If a string, convert to page
1029 $revision_handle = false;
1030 assert(isa($pageb, 'WikiDB_Page'));
1031 $bval = $col->_getSortableValue($pageb, $revision_handle);
1033 $cmp = $col->_compare($aval, $bval);
1034 if ($direction === "-") {
1035 // Reverse the sense of the comparison
1040 // This is the first comparison that is not equal-- go with it
1049 * Put pages in order according to the sortby arg, if given
1051 function _sortPages() {
1052 if (count($this->_sortby) > 0) {
1053 // There are columns to sort by
1054 usort($this->_pages, array('PageList', '_pageCompare'));
1058 function limit($limit) {
1059 if (strstr($limit,','))
1060 return split(',',$limit);
1062 return array(0,$limit);
1065 // make a table given the caption
1066 function _generateTable($caption) {
1067 $this->_sortPages();
1070 foreach ($this->_pages as $pagenum => $page) {
1071 $rows[] = $this->_renderPageRow($page);
1074 $table = HTML::table(array('cellpadding' => 0,
1077 'class' => 'pagelist'));
1079 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
1081 //Warning: This is quite fragile. It depends solely on a private variable
1082 // in ->_addColumn()
1083 if (!empty($this->_columns_seen['checkbox'])) {
1084 $table->pushContent($this->_jsFlipAll());
1086 $do_paging = ( isset($this->_options['paging']) and
1087 !empty($this->_options['limit']) and $this->getTotal() and
1088 $this->_options['paging'] != 'none' );
1090 $table_summary = array();
1092 foreach ($this->_columns as $col) {
1093 $heading = $col->button_heading($this, $i);
1095 isset($col->_field) and $col->_field == 'pagename' and
1096 ($maxlen = $this->maxLen()))
1097 $heading->setAttr('width',$maxlen * 7);
1098 $row->pushContent($heading);
1099 if (is_string($col->getHeading()))
1100 $table_summary[] = $col->getHeading();
1103 // Table summary for non-visual browsers.
1104 $table->setAttr('summary', sprintf(_("Columns: %s."),
1105 implode(", ", $table_summary)));
1108 // if there are more pages than the limit, show a table-header, -footer
1109 list($offset,$pagesize) = $this->limit($this->_options['limit']);
1110 $numrows = $this->getTotal();
1112 (!$offset and $numrows <= $pagesize) or
1113 ($offset + $pagesize < 0))
1115 $table->pushContent(HTML::thead($row),
1116 HTML::tbody(false, $rows));
1120 include_once('lib/Template.php');
1123 $pagename = $request->getArg('pagename');
1124 $defargs = $request->args;
1125 unset($defargs['pagename']); unset($defargs['action']);
1126 //$defargs['nocache'] = 1;
1128 $tokens['PREV'] = false; $tokens['PREV_LINK'] = "";
1129 $tokens['COLS'] = count($this->_columns);
1130 $tokens['COUNT'] = $numrows;
1131 $tokens['OFFSET'] = $offset;
1132 $tokens['SIZE'] = $pagesize;
1133 $tokens['NUMPAGES'] = (int)($numrows / $pagesize)+1;
1134 $tokens['ACTPAGE'] = (int) (($offset+1) / $pagesize)+1;
1136 $prev['limit'] = min(0,$offset - $pagesize) . ",$pagesize";
1137 $prev['count'] = $numrows;
1138 $tokens['LIMIT'] = $prev['limit'];
1139 $tokens['PREV'] = true;
1140 $tokens['PREV_LINK'] = WikiURL($pagename,$prev);
1141 $prev['limit'] = "0,$pagesize";
1142 $tokens['FIRST_LINK'] = WikiURL($pagename,$prev);
1145 $tokens['NEXT'] = false; $tokens['NEXT_LINK'] = "";
1146 if ($offset + $pagesize < $numrows) {
1147 $next['limit'] = min($offset + $pagesize,$numrows - $pagesize) . ",$pagesize";
1148 $next['count'] = $numrows;
1149 $tokens['LIMIT'] = $next['limit'];
1150 $tokens['NEXT'] = true;
1151 $tokens['NEXT_LINK'] = WikiURL($pagename,$next);
1152 $next['limit'] = $numrows - $pagesize . ",$pagesize";
1153 $tokens['LAST_LINK'] = WikiURL($pagename,$next);
1155 $paging = new Template("pagelink", $request, $tokens);
1156 $table->pushContent(HTML::thead($paging),
1157 HTML::tbody(false, HTML($row, $rows)),
1158 HTML::tfoot($paging));
1161 $table->pushContent(HTML::thead($row),
1162 HTML::tbody(false, $rows));
1166 function _jsFlipAll() {
1168 function flipAll(formObj) {
1169 var isFirstSet = -1;
1170 for (var i=0;i < formObj.length;i++) {
1171 fldObj = formObj.elements[i];
1172 if (fldObj.type == 'checkbox') {
1173 if (isFirstSet == -1)
1174 isFirstSet = (fldObj.checked) ? true : false;
1175 fldObj.checked = (isFirstSet) ? false : true;
1181 function _generateList($caption) {
1182 $list = HTML::ul(array('class' => 'pagelist'));
1184 foreach ($this->_pages as $pagenum => $page) {
1185 $pagehtml = $this->_renderPageRow($page);
1186 $group = ($i++ / $this->_group_rows);
1187 $class = ($group % 2) ? 'oddrow' : 'evenrow';
1188 $list->pushContent(HTML::li(array('class' => $class),$pagehtml));
1191 //Warning: This is quite fragile. It depends solely on a private variable
1192 // in ->_addColumn()
1193 // Questionable if its of use here anyway. This is a one-col pagename list only.
1194 //if (!empty($this->_columns_seen['checkbox'])) $out->pushContent($this->_jsFlipAll());
1196 $out->pushContent(HTML::p($caption));
1197 $out->pushContent($list);
1201 function _emptyList($caption) {
1204 $html->pushContent(HTML::p($caption));
1205 if ($this->_messageIfEmpty)
1206 $html->pushContent(HTML::blockquote(HTML::p($this->_messageIfEmpty)));
1210 // Condense list: "Page1, Page2, ..."
1211 // Alternative $seperator = HTML::Raw(' · ')
1212 function _generateCommaList($seperator = ', ') {
1213 return HTML(join($seperator, $list));
1218 /* List pages with checkboxes to select from.
1219 * The [Select] button toggles via _jsFlipAll
1222 class PageList_Selectable
1225 function PageList_Selectable ($columns=false, $exclude=false, $options = false) {
1227 if (!is_array($columns))
1228 $columns = explode(',', $columns);
1229 if (!in_array('checkbox',$columns))
1230 array_unshift($columns,'checkbox');
1232 $columns = array('checkbox','pagename');
1234 PageList::PageList($columns, $exclude, $options);
1237 function addPageList ($array) {
1238 while (list($pagename,$selected) = each($array)) {
1239 if ($selected) $this->addPageSelected((string)$pagename);
1240 $this->addPage((string)$pagename);
1244 function addPageSelected ($pagename) {
1245 $this->_selected[$pagename] = 1;
1249 // $Log: not supported by cvs2svn $
1250 // Revision 1.93 2004/06/25 14:29:17 rurban
1251 // WikiGroup refactoring:
1252 // global group attached to user, code for not_current user.
1253 // improved helpers for special groups (avoid double invocations)
1254 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
1255 // fixed a XHTML validation error on userprefs.tmpl
1257 // Revision 1.92 2004/06/21 17:01:39 rurban
1258 // fix typo and rating method call
1260 // Revision 1.91 2004/06/21 16:22:29 rurban
1261 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
1262 // fixed dumping buttons locally (images/buttons/),
1263 // support pages arg for dumphtml,
1264 // optional directory arg for dumpserial + dumphtml,
1265 // fix a AllPages warning,
1266 // show dump warnings/errors on DEBUG,
1267 // don't warn just ignore on wikilens pagelist columns, if not loaded.
1268 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
1270 // Revision 1.90 2004/06/18 14:38:21 rurban
1271 // adopt new PageList style
1273 // Revision 1.89 2004/06/17 13:16:08 rurban
1274 // apply wikilens work to PageList: all columns are sortable (slightly fixed)
1276 // Revision 1.88 2004/06/14 11:31:35 rurban
1277 // renamed global $Theme to $WikiTheme (gforge nameclash)
1278 // inherit PageList default options from PageList
1279 // default sortby=pagename
1280 // use options in PageList_Selectable (limit, sortby, ...)
1281 // added action revert, with button at action=diff
1282 // added option regex to WikiAdminSearchReplace
1284 // Revision 1.87 2004/06/13 16:02:12 rurban
1285 // empty list of pages if user=[] and not authenticated.
1287 // Revision 1.86 2004/06/13 15:51:37 rurban
1288 // Support pagelist filter for current author,owner,creator by []
1290 // Revision 1.85 2004/06/13 15:33:19 rurban
1291 // new support for arguments owner, author, creator in most relevant
1292 // PageList plugins. in WikiAdmin* via preSelectS()
1294 // Revision 1.84 2004/06/08 13:51:56 rurban
1295 // some comments only
1297 // Revision 1.83 2004/05/18 13:35:39 rurban
1298 // improve Pagelist layout by equal pagename width for limited lists
1300 // Revision 1.82 2004/05/16 22:07:35 rurban
1301 // check more config-default and predefined constants
1302 // various PagePerm fixes:
1303 // fix default PagePerms, esp. edit and view for Bogo and Password users
1304 // implemented Creator and Owner
1305 // BOGOUSERS renamed to BOGOUSER
1306 // fixed syntax errors in signin.tmpl
1308 // Revision 1.81 2004/05/13 12:30:35 rurban
1309 // fix for MacOSX border CSS attr, and if sort buttons are not found
1311 // Revision 1.80 2004/04/20 00:56:00 rurban
1312 // more paging support and paging fix for shorter lists
1314 // Revision 1.79 2004/04/20 00:34:16 rurban
1315 // more paging support
1317 // Revision 1.78 2004/04/20 00:06:03 rurban
1318 // themable paging support
1320 // Revision 1.77 2004/04/18 01:11:51 rurban
1321 // more numeric pagename fixes.
1322 // fixed action=upload with merge conflict warnings.
1323 // charset changed from constant to global (dynamic utf-8 switching)
1326 // (c-file-style: "gnu")
1330 // c-basic-offset: 4
1331 // c-hanging-comment-ender-p: nil
1332 // indent-tabs-mode: nil