Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php |
— | — | @@ -1,86 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Print query results using templates. |
5 | | - * @author Markus Krötzsch |
6 | | - * @file |
7 | | - * @ingroup SMWQuery |
8 | | - */ |
9 | | - |
10 | | -/** |
11 | | - * Printer for template data. Passes a result row as anonymous parameters to |
12 | | - * a given template (which might ignore them or not) and prints the result. |
13 | | - * |
14 | | - * @ingroup SMWQuery |
15 | | - */ |
16 | | -class SMWTemplateResultPrinter extends SMWResultPrinter { |
17 | | - |
18 | | - protected $m_template; |
19 | | - protected $m_userparam; |
20 | | - |
21 | | - protected function readParameters($params,$outputmode) { |
22 | | - SMWResultPrinter::readParameters($params,$outputmode); |
23 | | - |
24 | | - if (array_key_exists('template', $params)) { |
25 | | - $this->m_template = trim($params['template']); |
26 | | - } else { |
27 | | - $this->m_template = false; |
28 | | - } |
29 | | - |
30 | | - if (array_key_exists('userparam', $params)) { |
31 | | - $this->m_userparam = trim($params['userparam']); |
32 | | - } else { |
33 | | - $this->m_userparam = false; |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - public function getName() { |
38 | | - wfLoadExtensionMessages('SemanticMediaWiki'); |
39 | | - return wfMsg('smw_printername_template'); |
40 | | - } |
41 | | - |
42 | | - protected function getResultText($res, $outputmode) { |
43 | | - // print all result rows |
44 | | - if ($this->m_template == false) { |
45 | | - wfLoadExtensionMessages('SemanticMediaWiki'); |
46 | | - $res->addErrors(array(wfMsgForContent('smw_notemplategiven'))); |
47 | | - return ''; |
48 | | - } |
49 | | - $this->hasTemplates = true; |
50 | | - |
51 | | - $result = ''; |
52 | | - while ( $row = $res->getNext() ) { |
53 | | - $i = 1; // explicitly number parameters for more robust parsing (values may contain "=") |
54 | | - $wikitext = ($this->m_userparam)?"|userparam=$this->m_userparam":''; |
55 | | - $firstcol = true; |
56 | | - foreach ($row as $field) { |
57 | | - $wikitext .= '|' . $i++ . '='; |
58 | | - $first = true; |
59 | | - while ( ($text = $field->getNextText(SMW_OUTPUT_WIKI, $this->getLinker($firstcol))) !== false ) { |
60 | | - if ($first) { |
61 | | - $first = false; |
62 | | - } else { |
63 | | - $wikitext .= ', '; |
64 | | - } |
65 | | - $wikitext .= $text; //str_replace('|', '|',$text); // encode '|' for use in templates (templates fail otherwise) -- this is not the place for doing this, since even DV-Wikitexts contain proper "|"! |
66 | | - } |
67 | | - $firstcol = false; |
68 | | - } |
69 | | - $result .= '{{' . $this->m_template . $wikitext . '}}'; |
70 | | - } |
71 | | - |
72 | | - // show link to more results |
73 | | - if ( $this->linkFurtherResults($res) ) { |
74 | | - $link = $res->getQueryLink(); |
75 | | - if ($this->getSearchLabel($outputmode)) { |
76 | | - $link->setCaption($this->getSearchLabel($outputmode)); |
77 | | - } |
78 | | - $link->setParameter('template','format'); |
79 | | - $link->setParameter($this->m_template,'template'); |
80 | | - if (array_key_exists('link', $this->m_params)) { // linking may interfere with templates |
81 | | - $link->setParameter($this->m_params['link'],'link'); |
82 | | - } |
83 | | - $result .= $link->getText(SMW_OUTPUT_WIKI,$this->mLinker); |
84 | | - } |
85 | | - return $result; |
86 | | - } |
87 | | -} |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -129,7 +129,6 @@ |
130 | 130 | $wgAutoloadClasses['SMWListResultPrinter'] = $smwgIP . '/includes/SMW_QP_List.php'; |
131 | 131 | $wgAutoloadClasses['SMWCategoryResultPrinter'] = $smwgIP . '/includes/SMW_QP_Category.php'; |
132 | 132 | $wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $smwgIP . '/includes/SMW_QP_Embedded.php'; |
133 | | - $wgAutoloadClasses['SMWTemplateResultPrinter'] = $smwgIP . '/includes/SMW_QP_Template.php'; |
134 | 133 | $wgAutoloadClasses['SMWRSSResultPrinter'] = $smwgIP . '/includes/SMW_QP_RSSlink.php'; |
135 | 134 | $wgAutoloadClasses['SMWCsvResultPrinter'] = $smwgIP . '/includes/SMW_QP_CSV.php'; |
136 | 135 | $wgAutoloadClasses['SMWJSONResultPrinter'] = $smwgIP . '/includes/SMW_QP_JSONlink.php'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php |
— | — | @@ -250,7 +250,7 @@ |
251 | 251 | 'broadtable' => 'SMWTableResultPrinter', |
252 | 252 | 'category' => 'SMWCategoryResultPrinter', |
253 | 253 | 'embedded' => 'SMWEmbeddedResultPrinter', |
254 | | - 'template' => 'SMWTemplateResultPrinter', |
| 254 | + 'template' => 'SMWListResultPrinter', |
255 | 255 | 'count' => 'SMWListResultPrinter', |
256 | 256 | 'debug' => 'SMWListResultPrinter', |
257 | 257 | 'rss' => 'SMWRSSResultPrinter', |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php |
— | — | @@ -51,6 +51,11 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | protected function getResultText($res,$outputmode) { |
| 55 | + if ( ('template' == $this->mFormat) && ($this->mTemplate == false) ) { |
| 56 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 57 | + $res->addErrors(array(wfMsgForContent('smw_notemplategiven'))); |
| 58 | + return ''; |
| 59 | + } |
55 | 60 | // Determine mark-up strings used around list items: |
56 | 61 | if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) { |
57 | 62 | $header = '<' . $this->mFormat . '>'; |
— | — | @@ -58,31 +63,34 @@ |
59 | 64 | $rowstart = '<li>'; |
60 | 65 | $rowend = '</li>'; |
61 | 66 | $plainlist = false; |
62 | | - } else { |
63 | | - if ($this->mSep != '') { |
| 67 | + } else { // "list" and "tempalte" format |
| 68 | + $header = ''; |
| 69 | + $footer = ''; |
| 70 | + $rowstart = ''; |
| 71 | + $rowend = ''; |
| 72 | + $plainlist = true; |
| 73 | + if ($this->mSep != '') { // always respect custom separator |
64 | 74 | $listsep = $this->mSep; |
65 | 75 | $finallistsep = $listsep; |
66 | | - } else { // default list ", , , and " |
| 76 | + } elseif ('list' == $this->mFormat) { // make default list ", , , and " |
67 | 77 | wfLoadExtensionMessages('SemanticMediaWiki'); |
68 | 78 | $listsep = ', '; |
69 | 79 | $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' '; |
| 80 | + } else { // no default separators for format "template" |
| 81 | + $listsep = ''; |
| 82 | + $finallistsep = ''; |
70 | 83 | } |
71 | | - $header = ''; |
72 | | - $footer = ''; |
73 | | - $rowstart = ''; |
74 | | - $rowend = ''; |
75 | | - $plainlist = true; |
76 | 84 | } |
77 | 85 | // Print header |
78 | 86 | $result = $header; |
79 | 87 | |
80 | | - // put all result rows into an array, for easier handling |
| 88 | + // Put all result rows into an array, for easier handling |
81 | 89 | $rows = array(); |
82 | 90 | while ($row = $res->getNext()) { |
83 | 91 | $rows[] = $row; |
84 | 92 | } |
85 | 93 | |
86 | | - // set up floating divs, if there's more than one column |
| 94 | + // Set up floating divs, if there's more than one column |
87 | 95 | if ($this->mColumns > 1) { |
88 | 96 | $column_width = floor(100 / $this->mColumns); |
89 | 97 | $result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n"; |
— | — | @@ -90,7 +98,7 @@ |
91 | 99 | $rows_in_cur_column = 0; |
92 | 100 | } |
93 | 101 | |
94 | | - // now print each row |
| 102 | + // Now print each row |
95 | 103 | foreach ($rows as $i => $row) { |
96 | 104 | if ($this->mColumns > 1) { |
97 | 105 | if ($rows_in_cur_column == $rows_per_column) { |
— | — | @@ -132,7 +140,7 @@ |
133 | 141 | $result .= ' ('; |
134 | 142 | $found_values = true; |
135 | 143 | } elseif ($found_values || !$first_value) { |
136 | | - // any value after '(' or non-first values on first column |
| 144 | + // any value after '(' or non-first values on first column |
137 | 145 | $result .= ', '; |
138 | 146 | } |
139 | 147 | if ($first_value) { // first value in any column, print header |
— | — | @@ -157,9 +165,10 @@ |
158 | 166 | if ($this->getSearchLabel(SMW_OUTPUT_WIKI)) { |
159 | 167 | $link->setCaption($this->getSearchLabel(SMW_OUTPUT_WIKI)); |
160 | 168 | } |
161 | | - /// NOTE: passing the parameter sep is not needed, since we use format=ul |
162 | | - |
163 | | - $link->setParameter('ul','format'); // always use ul, other formats hardly work as search page output |
| 169 | + if ($this->mSep != '') { |
| 170 | + $link->setParameter($this->mSep,'sep'); |
| 171 | + } |
| 172 | + $link->setParameter($this->mFormat,'format'); |
164 | 173 | if ($this->mTemplate != '') { |
165 | 174 | $link->setParameter($this->mTemplate,'template'); |
166 | 175 | if (array_key_exists('link', $this->m_params)) { // linking may interfere with templates |