1 <?php rcs_id('$Id: PageList.php,v 1.5 2002-01-21 16:28:28 carstenklapp Exp $');
3 // This will relieve some of the work of plugins like LikePages,
4 // MostPopular and allows dynamic expansion of those plugins do
5 // include more columns in their output.
7 // There are still a few rough edges.
10 function PageList ($pagelist_name = '') {
11 $this->name = $pagelist_name;
13 $this->_columns = array(_("Page Name"));
14 $this->_pages = array();
19 function setCaption ($caption_string) {
20 $this->_caption = $caption_string;
23 function getCaption () {
24 // put the total into the caption if needed
25 if (strstr($this->_caption, '%d')) {
26 $this->setCaption(sprintf($this->_caption, $this->getTotal()));
28 return $this->_caption;
31 function addColumn ($new_columnname) {
32 array_push($this->_columns, $new_columnname);
35 function insertColumn ($new_columnname) {
36 array_unshift($this->_columns, $new_columnname);
39 function addPage ($page_handle) {
40 array_push($this->_pages, &$page_handle);
41 $this->_total = $this->_total + 1;
44 function getTotal () {
45 if (! $this->_total) {
46 //this might not be necessary
47 $this->_total = count($this->_pages);
53 // TODO: Generate a list instead of a table when only one
54 // column (pagenames only).
56 $summary = "FIXME: add brief summary and column names";
58 $table = HTML::table(array('cellpadding' => 0,
61 'summary' => $summary)
64 $pad = new RawXml(' ');
67 foreach ($this->_columns as $column_name) {
68 if ($this->_column_align($column_name) == 'right') {
69 $head->pushContent(HTML::td(array('align' => 'right'), $pad, HTML::u($column_name)));
71 $head->pushContent(HTML::td($pad, HTML::u($column_name)));
74 $table->pushContent($head);
76 foreach ($this->_pages as $page_handle) {
78 foreach ($this->_columns as $column_name) {
80 $field = $this->_colname_to_dbfield($column_name);
81 if ($this->_does_require_rev($column_name)) {
82 $current = $page_handle->getCurrentRevision();
83 $value = $current->get($field);
84 if ($field=='mtime') {
86 $td = ($Theme->formatDateTime($value));
91 //TODO: make method to determine formatting
92 if ($field=='pagename') {
93 $td = (new RawXml (LinkExistingWikiWord($page_handle->getName())));
95 $td = ($page_handle->get($field));
99 if ($this->_column_align($column_name) == 'right') {
100 $row->pushContent (HTML::td(array('align' => 'right'), $pad, $td));
102 $row->pushContent (HTML::td($pad, $td));
105 $table->pushContent(HTML::tr($row));
107 return array(HTML::p($this->getCaption()), $table);
114 // lookup alignment from column name
115 function _column_align($column_name) {
117 _("Page Name") => 'left',
118 _("Last Modified") => 'left',
119 _("Hits") => 'right',
120 _("Date Created") => 'left',
121 _("# of revisions") => 'right',
122 _("Last Summary") => 'left',
123 _("Last Edited By") => 'left'
126 $key = $map[$column_name];
129 //FIXME: localise after wording has been finalized.
130 trigger_error("_column_align: key for '$column_name' not found",
137 // lookup database field from column name
138 function _colname_to_dbfield($column_name) {
140 _("Page Name") => 'pagename',
141 _("Last Modified") => 'mtime',
143 _("Date Created") => '',
144 _("# of revisions") => '',
145 _("Last Summary") => 'summary',
146 _("Last Edited By") => ''
148 $key = $map[$column_name];
150 //FIXME: localise after wording has been finalized.
151 trigger_error("_colname_to_dbfield: key for '$column_name' not found",
158 // lookup whether fieldname requires page revision
159 function _does_require_rev($column_name) {
161 _("Page Name") => false,
162 _("Last Modified") => true,
164 _("Date Created") => '',
165 _("# of revisions") => '',
166 _("Last Summary") => true,
167 _("Last Edited By") => true
169 $key = $map[$column_name];
176 // (c-file-style: "gnu")
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil