1 <?php rcs_id('$Id: PageList.php,v 1.11 2002-01-21 21:06:13 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 include more
8 // columns in their output.
10 // There are still a few rough edges.
12 // FIXME: Make caption work properly with new HtmlElement
14 // FIXME: Add error recovery! If the column title isn't found due to a
15 // typo, the wiki craps out, you will not even be able to edit the
16 // page again to fix the typo in the column name!
19 function PageList ($pagelist_name = '') {
20 $this->name = $pagelist_name;
22 $this->_columns = array(_("Page Name"));
23 $this->_pages = array();
28 function setCaption ($caption_string) {
29 $this->_caption = $caption_string;
32 function getCaption () {
33 // put the total into the caption if needed
34 if (strstr($this->_caption, '%d')) {
35 $this->setCaption(sprintf($this->_caption, $this->getTotal()));
37 return $this->_caption;
40 //FIXME: yuck, get rid of ucfirst
41 function addColumn ($new_columnname) {
42 array_push($this->_columns, ucfirst($new_columnname));
45 function insertColumn ($new_columnname) {
46 array_unshift($this->_columns, ucfirst($new_columnname));
49 function addPage ($page_handle) {
50 array_push($this->_pages, &$page_handle);
51 $this->_total = $this->_total + 1;
54 function getTotal () {
55 if (! $this->_total) {
56 //this might not be necessary
57 $this->_total = count($this->_pages);
62 function getContent() {
63 $caption = HTML::div(array('align' => 'left'), $this->getCaption());
65 if (count($this->_columns) == 1) {
66 return array($caption, $this->_generateList());
68 return $this->_generateTable($caption);
76 // Some of these column_name aliases could probably be eliminated
77 // once standard titles have been agreed upon
79 // lookup alignment from column name
80 function _column_align($column_name) {
82 _("Page Name") => 'left',
85 _("Last Modified") => 'left',
87 _("Visitors") => 'right',
88 _("Date Created") => 'left',
89 _("Creation Date") => 'left',
90 _("# Of Revisions") => 'right', //FIXME: count revisions in db
91 _("Last Summary") => 'left',
92 _("Last Author") => 'left',
93 _("Last Edited By") => 'left',
94 _("Author") => 'left',
95 _("Original Author") => 'left',
96 _("Created By") => 'left',
97 _("Locked") => 'left',
98 _("Minor Edit") => 'left',
102 $key = $map[$column_name];
105 //FIXME: localise after wording has been finalized.
106 trigger_error("_column_align: key for '$column_name' not found",
113 // lookup database field from column name
114 function _colname_to_dbfield($column_name) {
116 _("Page Name") => 'pagename',
117 _("Page") => 'pagename',
118 _("Name") => 'pagename',
119 _("Last Modified") => 'mtime',
121 _("Visitors") => 'hits',
122 _("Date Created") => '_ctime',
123 _("Creation Date") => '_ctime',
124 _("# Of Revisions") => '', //FIXME: count revisions in db
125 _("Last Summary") => 'summary',
126 _("Last Author") => 'author',
127 _("Last Edited By") => 'author',
128 _("Author") => '_cauthor',
129 _("Original Author") => '_cauthor',
130 _("Created By") => '_cauthor',
131 _("Locked") => 'locked',
132 _("Minor Edit") => 'is_minor_edit',
133 _("Minor") => 'is_minor_edit',
135 $key = $map[$column_name];
137 //FIXME: localise after wording has been finalized.
138 trigger_error("_colname_to_dbfield: key for '$column_name' not found",
145 // lookup whether fieldname requires page revision
146 function _does_require_rev($column_name) {
148 _("Page Name") => false,
151 _("Last Modified") => true,
153 _("Visitors") => false,
154 _("Date Created") => false,
155 _("Creation Date") => false,
156 _("# Of Revisions") => '', //FIXME: count revisions in db
157 _("Last Summary") => true,
158 _("Last Author") => true,
159 _("Last Edited By") => true,
161 _("Original Author") => false,
162 _("Created By") => false,
163 _("Locked") => false,
164 _("Minor Edit") => true,
167 $key = $map[$column_name];
171 // make a table given the caption
172 function _generateTable($caption) {
173 $pad = new RawXml(' ');
174 $emdash = new RawXml('—');
176 $thead = HTML::thead();
177 foreach ($this->_columns as $column_name) {
178 if ($this->_column_align($column_name) == 'right') {
179 $thead->pushContent(HTML::td(array('align' => 'right'), $pad, HTML::u($column_name)));
181 $thead->pushContent(HTML::td($pad, HTML::u($column_name)));
185 $tbody = HTML::tbody();
186 foreach ($this->_pages as $page_handle) {
190 foreach ($this->_columns as $column_name) {
192 $field = $this->_colname_to_dbfield($column_name);
194 if ($this->_does_require_rev($column_name)) {
195 $current = $page_handle->getCurrentRevision();
196 $value = $current->get($field);
198 //TODO: make method to determine formatting
202 $td = ($Theme->formatDateTime($value));
204 case 'is_minor_edit' :
205 $td = ($value) ? _("minor") : $emdash;
208 // does not need current rev
210 $td = new RawXml (LinkExistingWikiWord($page_handle->getName()));
213 $td = ($page_handle->get($field)) ? _("locked") : $emdash;
216 $revision = $page_handle->getRevision(1);
217 $td = $Theme->formatDateTime($revision->get('mtime'));
220 $revision = $page_handle->getRevision(1);
221 $td = new RawXml (LinkExistingWikiWord($revision->get('author')));
225 if ($this->_does_require_rev($column_name)) {
228 $td = ($page_handle->get($field));
232 if ($this->_column_align($column_name) == 'right') {
233 $row->pushContent (HTML::td(array('align' => 'right'), $pad, $td));
235 $row->pushContent (HTML::td($pad, $td));
238 $tbody->pushContent($row);
241 $summary = "FIXME: add brief summary and column names";
243 // Final table assembly
244 $table = HTML::table(array('summary' => $summary,
250 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
251 $table->pushContent($thead);
252 $table->pushContent($tbody);
256 function _generateList() {
258 foreach ($this->_pages as $page_handle) {
259 $list->pushContent(HTML::li(_LinkWikiWord($page_handle->getName())));
267 // (c-file-style: "gnu")
272 // c-hanging-comment-ender-p: nil
273 // indent-tabs-mode: nil