1 <?php rcs_id('$Id: PageList.php,v 1.9 2002-01-21 19:18:16 carstenklapp Exp $');
3 // This relieves some work for these plugins:
5 // BackLinks, LikePages, Mostpopular, TitleSearch
7 // It also allows dynamic expansion of those plugins to
8 // include more columns in their output.
10 // There are still a few rough edges.
13 function PageList ($pagelist_name = '') {
14 $this->name = $pagelist_name;
16 $this->_columns = array(_("Page Name"));
17 $this->_pages = array();
22 function setCaption ($caption_string) {
23 $this->_caption = $caption_string;
26 function getCaption () {
27 // put the total into the caption if needed
28 if (strstr($this->_caption, '%d')) {
29 $this->setCaption(sprintf($this->_caption, $this->getTotal()));
31 return $this->_caption;
34 //FIXME: yuck, get rid of ucfirst
35 function addColumn ($new_columnname) {
36 array_push($this->_columns, ucfirst($new_columnname));
39 function insertColumn ($new_columnname) {
40 array_unshift($this->_columns, ucfirst($new_columnname));
43 function addPage ($page_handle) {
44 array_push($this->_pages, &$page_handle);
45 $this->_total = $this->_total + 1;
48 function getTotal () {
49 if (! $this->_total) {
50 //this might not be necessary
51 $this->_total = count($this->_pages);
56 function getContent() {
57 $caption = HTML::div(array('align' => 'left'), $this->getCaption());
59 if (count($this->_columns) == 1) {
60 return array($caption, $this->_generateList());
62 return $this->_generateTable($caption);
70 // lookup alignment from column name
71 function _column_align($column_name) {
73 _("Page Name") => 'left',
74 _("Last Modified") => 'left',
76 _("Date Created") => 'left',
77 _("# Of Revisions") => 'right',
78 _("Last Summary") => 'left',
79 _("Last Edited By") => 'left'
82 $key = $map[$column_name];
85 //FIXME: localise after wording has been finalized.
86 trigger_error("_column_align: key for '$column_name' not found",
93 // lookup database field from column name
94 function _colname_to_dbfield($column_name) {
96 _("Page Name") => 'pagename',
97 _("Last Modified") => 'mtime',
99 _("Date Created") => '',
100 _("# of revisions") => '',
101 _("Last Summary") => 'summary',
102 _("Last Edited By") => ''
104 $key = $map[$column_name];
106 //FIXME: localise after wording has been finalized.
107 trigger_error("_colname_to_dbfield: key for '$column_name' not found",
114 // lookup whether fieldname requires page revision
115 function _does_require_rev($column_name) {
117 _("Page Name") => false,
118 _("Last Modified") => true,
120 _("Date Created") => '',
121 _("# Of Revisions") => '',
122 _("Last Summary") => true,
123 _("Last Edited By") => true
125 $key = $map[$column_name];
129 // make a table given the caption
130 function _generateTable($caption) {
131 $pad = new RawXml(' ');
133 $thead = HTML::thead();
134 foreach ($this->_columns as $column_name) {
135 if ($this->_column_align($column_name) == 'right') {
136 $thead->pushContent(HTML::td(array('align' => 'right'), $pad, HTML::u($column_name)));
138 $thead->pushContent(HTML::td($pad, HTML::u($column_name)));
142 $tbody = HTML::tbody();
143 foreach ($this->_pages as $page_handle) {
145 foreach ($this->_columns as $column_name) {
147 $field = $this->_colname_to_dbfield($column_name);
148 if ($this->_does_require_rev($column_name)) {
149 $current = $page_handle->getCurrentRevision();
150 $value = $current->get($field);
151 if ($field=='mtime') {
153 $td = ($Theme->formatDateTime($value));
158 //TODO: make method to determine formatting
159 if ($field=='pagename') {
160 $td = (new RawXml (LinkExistingWikiWord($page_handle->getName())));
162 $td = ($page_handle->get($field));
166 if ($this->_column_align($column_name) == 'right') {
167 $row->pushContent (HTML::td(array('align' => 'right'), $pad, $td));
169 $row->pushContent (HTML::td($pad, $td));
172 $tbody->pushContent($row);
175 $summary = "FIXME: add brief summary and column names";
177 // Final table assembly
178 $table = HTML::table(array('cellpadding' => 0,
181 'summary' => $summary,
185 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
186 $table->pushContent($thead);
187 $table->pushContent($tbody);
191 function _generateList() {
193 foreach ($this->_pages as $page_handle) {
194 $list->pushContent(HTML::li(_LinkWikiWord($page_handle->getName())));
202 // (c-file-style: "gnu")
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil