r55875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55874‎ | r55875 | r55876 >
Date:13:33, 6 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
functionality of template resul printer now subsumed by list printer
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php (deleted) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php (modified) (history)

Diff [purge]

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('|', '&#x007C;',$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 @@
130130 $wgAutoloadClasses['SMWListResultPrinter'] = $smwgIP . '/includes/SMW_QP_List.php';
131131 $wgAutoloadClasses['SMWCategoryResultPrinter'] = $smwgIP . '/includes/SMW_QP_Category.php';
132132 $wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $smwgIP . '/includes/SMW_QP_Embedded.php';
133 - $wgAutoloadClasses['SMWTemplateResultPrinter'] = $smwgIP . '/includes/SMW_QP_Template.php';
134133 $wgAutoloadClasses['SMWRSSResultPrinter'] = $smwgIP . '/includes/SMW_QP_RSSlink.php';
135134 $wgAutoloadClasses['SMWCsvResultPrinter'] = $smwgIP . '/includes/SMW_QP_CSV.php';
136135 $wgAutoloadClasses['SMWJSONResultPrinter'] = $smwgIP . '/includes/SMW_QP_JSONlink.php';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php
@@ -250,7 +250,7 @@
251251 'broadtable' => 'SMWTableResultPrinter',
252252 'category' => 'SMWCategoryResultPrinter',
253253 'embedded' => 'SMWEmbeddedResultPrinter',
254 - 'template' => 'SMWTemplateResultPrinter',
 254+ 'template' => 'SMWListResultPrinter',
255255 'count' => 'SMWListResultPrinter',
256256 'debug' => 'SMWListResultPrinter',
257257 'rss' => 'SMWRSSResultPrinter',
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php
@@ -51,6 +51,11 @@
5252 }
5353
5454 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+ }
5560 // Determine mark-up strings used around list items:
5661 if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) {
5762 $header = '<' . $this->mFormat . '>';
@@ -58,31 +63,34 @@
5964 $rowstart = '<li>';
6065 $rowend = '</li>';
6166 $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
6474 $listsep = $this->mSep;
6575 $finallistsep = $listsep;
66 - } else { // default list ", , , and "
 76+ } elseif ('list' == $this->mFormat) { // make default list ", , , and "
6777 wfLoadExtensionMessages('SemanticMediaWiki');
6878 $listsep = ', ';
6979 $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' ';
 80+ } else { // no default separators for format "template"
 81+ $listsep = '';
 82+ $finallistsep = '';
7083 }
71 - $header = '';
72 - $footer = '';
73 - $rowstart = '';
74 - $rowend = '';
75 - $plainlist = true;
7684 }
7785 // Print header
7886 $result = $header;
7987
80 - // put all result rows into an array, for easier handling
 88+ // Put all result rows into an array, for easier handling
8189 $rows = array();
8290 while ($row = $res->getNext()) {
8391 $rows[] = $row;
8492 }
8593
86 - // set up floating divs, if there's more than one column
 94+ // Set up floating divs, if there's more than one column
8795 if ($this->mColumns > 1) {
8896 $column_width = floor(100 / $this->mColumns);
8997 $result .= '<div style="float: left; width: ' . $column_width . '%">' . "\n";
@@ -90,7 +98,7 @@
9199 $rows_in_cur_column = 0;
92100 }
93101
94 - // now print each row
 102+ // Now print each row
95103 foreach ($rows as $i => $row) {
96104 if ($this->mColumns > 1) {
97105 if ($rows_in_cur_column == $rows_per_column) {
@@ -132,7 +140,7 @@
133141 $result .= ' (';
134142 $found_values = true;
135143 } 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
137145 $result .= ', ';
138146 }
139147 if ($first_value) { // first value in any column, print header
@@ -157,9 +165,10 @@
158166 if ($this->getSearchLabel(SMW_OUTPUT_WIKI)) {
159167 $link->setCaption($this->getSearchLabel(SMW_OUTPUT_WIKI));
160168 }
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');
164173 if ($this->mTemplate != '') {
165174 $link->setParameter($this->mTemplate,'template');
166175 if (array_key_exists('link', $this->m_params)) { // linking may interfere with templates

Status & tagging log