_heading = $default_heading; $this->_tdattr = array(); if ($align) $this->_tdattr['align'] = $align; } function format ($page_handle, &$revision_handle) { return HTML::td($this->_tdattr, NBSP, $this->_getValue($page_handle, &$revision_handle), NBSP); } function setHeading ($heading) { $this->_heading = $heading; } function heading () { return HTML::td(array('align' => 'center'), NBSP, HTML::u($this->_heading), NBSP); } }; class _PageList_Column extends _PageList_Column_base { function _PageList_Column ($field, $default_heading, $align = false) { $this->_PageList_Column_base($default_heading, $align); $this->_need_rev = substr($field, 0, 4) == 'rev:'; if ($this->_need_rev) $this->_field = substr($field, 4); else $this->_field = $field; } function _getValue ($page_handle, &$revision_handle) { if ($this->_need_rev) { if (!$revision_handle) $revision_handle = $page_handle->getCurrentRevision(); return $revision_handle->get($this->_field); } else { return $page_handle->get($this->_field); } } }; class _PageList_Column_bool extends _PageList_Column { function _PageList_Column_bool ($field, $default_heading, $text = 'yes') { $this->_PageList_Column($field, $default_heading, 'center'); $this->_textIfTrue = $text; $this->_textIfFalse = new RawXml('—'); } function _getValue ($page_handle, &$revision_handle) { $val = _PageList_Column::_getValue($page_handle, $revision_handle); return $val ? $this->_textIfTrue : $this->_textIfFalse; } }; class _PageList_Column_time extends _PageList_Column { function _PageList_Column_time ($field, $default_heading) { $this->_PageList_Column($field, $default_heading, 'right'); } function _getValue ($page_handle, &$revision_handle) { global $Theme; $time = _PageList_Column::_getValue($page_handle, $revision_handle); return $Theme->formatDateTime($time); } }; class _PageList_Column_pagename extends _PageList_Column_base { function _PageList_Column_pagename () { $this->_PageList_Column_base(_("Page Name")); } function _getValue ($page_handle, &$revision_handle) { return LinkExistingWikiWord($page_handle->getName()); } }; class PageList { function PageList () { $this->_caption = ""; $this->_columns = array(new _PageList_Column_pagename); $this->_pages = array(); $this->_messageIfEmpty = _(""); } function setCaption ($caption_string) { $this->_caption = $caption_string; } function getCaption () { // put the total into the caption if needed if (is_string($this->_caption) && strstr($this->_caption, '%d')) return sprintf($this->_caption, $this->getTotal()); return $this->_caption; } function setMessageIfEmpty ($msg) { $this->_messageIfEmpty = $msg; } /** * Add a column to the listing. * * @input $column string Which column to add. * $Column can be one of * * If you would like to specify an alternate heading for the * column, concatenate the desired adding to $column, after adding * a colon. E.g. 'hits:Page Views'. */ function addColumn ($column) { if (($col = $this->_getColumn($new_columnname))) array_push($this->_columns, $col); } function insertColumn ($new_columnname) { if (($col = $this->_getColumn($new_columnname))) array_unshift($this->_columns, $col); } function addPage ($page_handle) { array_push($this->_pages, &$page_handle); } function getTotal () { return count($this->_pages); } function isEmpty () { return empty($this->_pages); } function getContent() { // Note that the element wants inline content. $caption = $this->getCaption(); if ($this->isEmpty()) return $this->_emptyList($caption); elseif (count($this->_columns) == 1) return $this->_generateList($caption); else return $this->_generateTable($caption); } function printXML() { PrintXML($this->getContent()); } function asXML() { return AsXML($this->getContent()); } //////////////////// // private //////////////////// function _getColumn ($column) { static $types; if (empty($types)) { $types = array( 'mtime' => new _PageList_Column_time('rev:mtime', _("Last Modified")), 'hits' => new _PageList_Column('hits', _("Hits"), 'right'), 'summary' => new _PageList_Column('rev:summary', _("Last Summary")), 'author' => new _PageList_Column('rev:author', _("Last Author")), 'locked' => new _PageList_Column_bool('locked', _("Locked"), _("locked")), 'minor' => new _PageList_Column_bool('rev:is_minor_edit', _("Minor Edit"), _("minor")) ); } if (strstr($column, ':')) list ($column, $heading) = explode(':', $column, 2); if (!isset($types[$column])) { trigger_error(sprintf("%s: Bad column", $column), E_USER_NOTICE); return false; } $col = $types[$column]; if (!empty($heading)) $col->setHeading($heading); return $col; } // make a table given the caption function _generateTable($caption) { $table = HTML::table(array('cellpadding' => 0, 'cellspacing' => 1, 'border' => 0)); $table->setAttr('summary', "FIXME: add brief summary and column names"); if ($caption) $table->pushContent(HTML::caption(array('align'=>'top'), $caption)); $row = HTML::tr(); foreach ($this->_columns as $col) $row->pushContent($col->heading()); $table->pushContent(HTML::thead($row)); $tbody = HTML::tbody(); foreach ($this->_pages as $page_handle) { $row = HTML::tr(); $revision_handle = false; foreach ($this->_columns as $col) $row->pushContent($col->format($page_handle, $revision_handle)); $tbody->pushContent($row); } $table->pushContent($tbody); return $table; } function _generateList($caption) { $list = HTML::ul(); foreach ($this->_pages as $page_handle) { $list->pushContent(HTML::li(LinkWikiWord($page_handle->getName()))); } if ($caption) $html[] = HTML::p($caption); $html[] = $list; return $html; } function _emptyList($caption) { $html = array(); if ($caption) $html[] = HTML::p($caption); if ($this->_messageIfEmpty) $html[] = HTML::blockquote(HTML::p($this->_messageIfEmpty)); return $html; } }; // (c-file-style: "gnu") // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>