r40325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40324‎ | r40325 | r40326 >
Date:15:52, 2 September 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Fixed problems with query printers that used sub-parsers. Moved many functions to parent class, simplifying sub-class code.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_CSV.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Embedded.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_iCalendar.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_vCard.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -15,20 +15,49 @@
1616 abstract class SMWResultPrinter {
1717
1818 protected $m_params;
 19+
 20+ /** Text to print before the output in case it is *not* empty; assumed to be wikitext.
 21+ * Normally this is handled in SMWResultPrinter and can be ignored by subclasses. */
 22+ protected $mIntro = '';
 23+
 24+ /** Text to use for link to further results, or empty if link should not be shown.
 25+ * Unescaped! Use SMWResultPrinter::getSearchLabel() and SMWResultPrinter::linkFurtherResults()
 26+ * instead of accessing this directly. */
 27+ protected $mSearchlabel = NULL;
 28+
 29+ /** Default return value for empty queries. Unescaped. Normally not used in sub-classes! */
 30+ protected $mDefault = '';
 31+
1932 // parameters relevant for printers in general:
2033 protected $mFormat; // a string identifier describing a valid format
21 - protected $mIntro = ''; // text to print before the output in case it is *not* empty
22 - protected $mSearchlabel = NULL; // text to use for link to further results, or empty if link should not be shown
2334 protected $mLinkFirst; // should article names of the first column be linked?
2435 protected $mLinkOthers; // should article names of other columns (besides the first) be linked?
25 - protected $mDefault = ''; // default return value for empty queries
2636 protected $mShowHeaders = true; // should the headers (property names) be printed?
2737 protected $mShowErrors = true; // should errors possibly be printed?
2838 protected $mInline; // is this query result "inline" in some page (only then a link to unshown results is created, error handling may also be affected)
2939 protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time.
30 -
3140
3241 /**
 42+ * If set, treat result as plain HTML. Can be used by printer classes if wiki mark-up is not enough.
 43+ * This setting is used only after the result text was generated.
 44+ * @note HTML query results cannot be used as parameters for other templates or in any other way
 45+ * in combination with other wiki text. The result will be inserted on the page literally.
 46+ */
 47+ protected $isHTML = false;
 48+
 49+ /**
 50+ * If set, take the necessary steps to make sure that things like {{templatename| ...}} are properly
 51+ * processed if they occur in the result. Clearly, this is only relevant if the output is not HTML, i.e.
 52+ * it is ignored if SMWResultPrinter::$is_HTML is true. This setting is used only after the result
 53+ * text was generated.
 54+ * @note This requires extra processing and may make the result less useful for being used as a
 55+ * parameter for further parser functions. Use only if required.
 56+ */
 57+ protected $hasTemplates = false;
 58+
 59+ private static $mRecursionDepth = 0; // increment while expanding templates inserted during printout; stop expansion at some point
 60+
 61+ /**
3362 * Constructor. The parameter $format is a format string
3463 * that may influence the processing details.
3564 */
@@ -42,17 +71,27 @@
4372 }
4473
4574 /**
46 - * Main entry point: takes an SMWQueryResult and parameters
47 - * given as key-value-pairs in an array, and returns the
48 - * serialised version of the results, formatted as HTML or Wiki
49 - * or whatever is specified. Normally this is not overwritten by
50 - * subclasses.
 75+ * Main entry point: takes an SMWQueryResult and parameters given as key-value-pairs in an array,
 76+ * and returns the serialised version of the results, formatted as HTML or Wiki or whatever is
 77+ * specified. Normally this is not overwritten by subclasses.
 78+ *
 79+ * If the outputmode is SMW_OUTPUT_WIKI, then the function will return something that is suitable
 80+ * for being used in a MediaWiki parser function, i.e. a wikitext strong *or* an array with flags
 81+ * and the string as entry 0. See Parser::setFunctionHook() for documentation on this. In all other
 82+ * cases, the function returns just a string.
 83+ *
 84+ * For outputs SMW_OUTPUT_WIKI and SMW_OUTPUT_HTML, error messages or standard "further results" links
 85+ * are directly generated and appended. For SMW_OUTPUT_FILE, only the plain generated text is returned.
5186 */
5287 public function getResult($results, $params, $outputmode) {
5388 $this->readParameters($params,$outputmode);
54 - if ($results->getCount() == 0) { // no results, take over processing
 89+
 90+ // Default output for normal printers:
 91+ if ( ($outputmode != SMW_OUTPUT_FILE) && // not in FILE context,
 92+ ($results->getCount() == 0) && // no results,
 93+ ($this->getMimeType($results) === false)) { // normal printer -> take over processing
5594 if (!$results->hasFurtherResults()) {
56 - return $this->mDefault . $this->getErrorString($results);
 95+ return $this->escapeText($this->mDefault,$outputmode) . $this->getErrorString($results);
5796 } elseif ($this->mInline) {
5897 $label = $this->mSearchlabel;
5998 if ($label === NULL) { //apply defaults
@@ -60,14 +99,47 @@
61100 $label = wfMsgForContent('smw_iq_moreresults');
62101 }
63102 if ($label != '') {
64 - $link = $results->getQueryLink($label);
 103+ $link = $results->getQueryLink($this->escapeText($label));
65104 $result = $link->getText($outputmode,$this->mLinker);
 105+ } else {
 106+ $result = '';
66107 }
67108 $result .= $this->getErrorString($results);
68109 return $result;
69110 }
70111 }
71 - return $this->getResultText($results,$outputmode) . $this->getErrorString($results);
 112+
 113+ // Get output from printer:
 114+ $result = $this->getResultText($results,$outputmode);
 115+ if ($outputmode == SMW_OUTPUT_FILE) { // just return result in file mode
 116+ return $result;
 117+ }
 118+ $result .= $this->getErrorString($results); // append errors
 119+ if ( (!$this->isHTML) && ($this->hasTemplates) ) { // preprocess embedded templates if needed
 120+ global $wgParser;
 121+ SMWResultPrinter::$mRecursionDepth++;
 122+ if (SMWResultPrinter::$mRecursionDepth <= 2) { // restrict recursion
 123+ $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]';
 124+ }
 125+ SMWResultPrinter::$mRecursionDepth--;
 126+ }
 127+
 128+ if ( ($this->isHTML) && ($outputmode == SMW_OUTPUT_WIKI) ) {
 129+ $result = array($result, 'isHTML' => true);
 130+ } elseif ( (!$this->isHTML) && ($outputmode == SMW_OUTPUT_HTML) ) {
 131+ global $wgParser;
 132+ $result = $wgParser->recursiveTagParse($result);
 133+ }
 134+
 135+ if ( ($this->mIntro) && ($results->getCount() > 0) ) {
 136+ if ($outputmode == SMW_OUTPUT_HTML) {
 137+ global $wgParser;
 138+ $result = $wgParser->recursiveTagParse($this->mIntro) . $result;
 139+ } else {
 140+ $result = $this->mIntro . $result;
 141+ }
 142+ }
 143+ return $result;
72144 }
73145
74146 /**
@@ -79,15 +151,9 @@
80152 $this->m_params = $params;
81153 if (array_key_exists('intro', $params)) {
82154 $this->mIntro = str_replace('_',' ',$params['intro']);
83 - if ($outputmode != SMW_OUTPUT_WIKI) {
84 - $this->mIntro = htmlspecialchars($this->mIntro);
85 - }
86155 }
87156 if (array_key_exists('searchlabel', $params)) {
88157 $this->mSearchlabel = $params['searchlabel'];
89 - if ($outputmode != SMW_OUTPUT_WIKI) {
90 - $this->mSearchlabel = htmlspecialchars($this->mSearchlabel);
91 - }
92158 }
93159 if (array_key_exists('link', $params)) {
94160 switch (strtolower($params['link'])) {
@@ -107,9 +173,6 @@
108174 }
109175 if (array_key_exists('default', $params)) {
110176 $this->mDefault = str_replace('_',' ',$params['default']);
111 - if ($outputmode != SMW_OUTPUT_WIKI) {
112 - $this->mDefault = htmlspecialchars($this->mDefault);
113 - }
114177 }
115178 if (array_key_exists('headers', $params)) {
116179 if ( 'hide' == strtolower(trim($params['headers']))) {
@@ -141,10 +204,16 @@
142205 }
143206
144207 /**
145 - * Some printers can produce not only embeddable HTML or Wikitext, but
146 - * can also produce stand-alone files. An example is RSS or iCalendar.
147 - * This function returns the mimetype string that this file would have,
148 - * or FALSE if no standalone files are produced.
 208+ * Some printers do not mainly produce embeddable HTML or Wikitext, but
 209+ * produce stand-alone files. An example is RSS or iCalendar. This function
 210+ * returns the mimetype string that this file would have, or FALSE if no
 211+ * standalone files are produced.
 212+ *
 213+ * If this function returns something other than FALSE, then the printer will
 214+ * not be regarded as a printer that displays in-line results. In in-line mode,
 215+ * queries to that printer will not be executed, but behave as if the user
 216+ * would have set limit=-1. This saves effort for printers that do not show
 217+ * results in-line anyway, even if they would be part of the result.
149218 */
150219 public function getMimeType($res) {
151220 return false;
@@ -156,6 +225,8 @@
157226 * This function returns a filename that is to be sent to the caller
158227 * in such a case (the default filename is created by browsers from the
159228 * URL, and it is often not pretty).
 229+ *
 230+ * See also SMWResultPrinter::getMimeType()
160231 */
161232 public function getFileName($res) {
162233 return false;
@@ -171,22 +242,48 @@
172243 }
173244
174245 /**
175 - * Change if errors should be shown-
 246+ * Set whether errors should be shown. By default they are.
176247 */
177248 public function setShowErrors($show) {
178249 $this->mShowErrors = $show;
179250 }
180251
181252 /**
182 - * @deprecated use SMWResultPrinter::getResult() in SMW >1.0
 253+ * If $outputmode is SMW_OUTPUT_HTML, escape special characters occuring in the
 254+ * given text. Otherwise return text as is.
183255 */
 256+ protected function escapeText($text, $outputmode) {
 257+ return ($outputmode == SMW_OUTPUT_HTML)?htmlspecialchars($text):$text;
 258+ }
 259+
 260+ /**
 261+ * Get the string the user specified as a text for the "further results" link,
 262+ * properly escaped for the current output mode.
 263+ */
 264+ protected function getSearchLabel($outputmode) {
 265+ return $this->escapeText($this->mSearchlabel, $outputmode);
 266+ }
 267+
 268+ /**
 269+ * Check whether a "further results" link would normally be generated for this
 270+ * result set with the given parameters. Individual result printers may decide to
 271+ * create or hide such a link independent of that, but this is the default.
 272+ */
 273+ protected function linkFurtherResults($results) {
 274+ return ($this->mInline && $results->hasFurtherResults() && ($this->mSearchlabel !== ''));
 275+ }
 276+
 277+
 278+ /**
 279+ * @deprecated Use SMWResultPrinter::getResult() in SMW >1.0. This method will last be available in SMW 1.3 and vanish thereafter.
 280+ */
184281 public function getResultHTML($results, $params) {
185282 return $this->getResult($results,$params,SMW_OUTPUT_HTML);
186283 }
187284
188285 /**
189286 * Return HTML version of serialised results.
190 - * @deprecated use SMWResultPrinter::getResultText() since SMW >1.0
 287+ * @deprecated Use SMWResultPrinter::getResultText() since SMW >1.0. This method will last be available in SMW 1.3 and vanish thereafter.
191288 */
192289 protected function getHTML($res) {
193290 return $this->getResultText($res,SMW_OUTPUT_HTML);
@@ -195,7 +292,7 @@
196293 /**
197294 * Generate a link to further results of the given query, using syntactic encoding
198295 * as appropriate for $outputmode.
199 - * @deprecated Since SMW>1.1 this function no longer does anything interesting. Intelligence moved to SMWInfolink. Directly use the code of this method instead of calling it!
 296+ * @deprecated Since SMW>1.1 this function no longer does anything interesting. Intelligence moved to SMWInfolink. Directly use the code of this method instead of calling it! This method will last be available in SMW 1.3 and vanish thereafter.
200297 */
201298 protected function getFurtherResultsLink($outputmode, $res, $label) {
202299 $link = $res->getQueryLink($label);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php
@@ -27,9 +27,6 @@
2828
2929 if (array_key_exists('sep', $params)) {
3030 $this->mSep = str_replace('_',' ',$params['sep']);
31 - if ($outputmode != SMW_OUTPUT_WIKI) {
32 - $this->mSep = htmlspecialchars($this->mSep);
33 - }
3431 }
3532 if (array_key_exists('template', $params)) {
3633 $this->mTemplate = trim($params['template']);
@@ -39,6 +36,7 @@
4037 }
4138 }
4239
 40+
4341 protected function getResultText($res,$outputmode) {
4442 global $smwgStoreActive, $wgParser;
4543 $parsetitle = $wgParser->getTitle();
@@ -47,10 +45,9 @@
4846 $parsetitle = $wgTitle;
4947 }
5048
51 - // print header
52 - $result = $this->mIntro;
 49+ // Determine mark-up strings used around list items:
5350 if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) {
54 - $result .= '<' . $this->mFormat . '>';
 51+ $header = '<' . $this->mFormat . '>';
5552 $footer = '</' . $this->mFormat . '>';
5653 $rowstart = "\n\t<li>";
5754 $rowend = '</li>';
@@ -59,38 +56,36 @@
6057 if ($this->mSep != '') {
6158 $listsep = $this->mSep;
6259 $finallistsep = $listsep;
63 - } else { // default list ", , , and, "
 60+ } else { // default list ", , , and "
6461 wfLoadExtensionMessages('SemanticMediaWiki');
6562 $listsep = ', ';
6663 $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' ';
6764 }
 65+ $header = '';
6866 $footer = '';
6967 $rowstart = '';
7068 $rowend = '';
7169 $plainlist = true;
7270 }
7371
74 - if ($this->mTemplate != '') {
75 - $parser_options = new ParserOptions();
76 - $parser_options->setEditSection(false); // embedded sections should not have edit links
77 - $parser = clone $wgParser;
78 - $usetemplate = true;
79 - } else {
80 - $usetemplate = false;
81 - }
 72+ // Print header:
 73+ $result = '';
 74+ $result .= $header;
8275
83 - // print all result rows
 76+ // Print all result rows:
8477 $first_row = true;
8578 $row = $res->getNext();
8679 while ( $row !== false ) {
8780 $nextrow = $res->getNext(); // look ahead
8881 if ( !$first_row && $plainlist ) {
89 - if ($nextrow !== false) $result .= $listsep; // the comma between "rows" other than the last one
90 - else $result .= $finallistsep;
91 - } else $result .= $rowstart;
 82+ $result .= ($nextrow !== false)?$listsep:$finallistsep; // the comma between "rows" other than the last one
 83+ } else {
 84+ $result .= $rowstart;
 85+ }
9286
9387 $first_col = true;
94 - if ($usetemplate) { // build template code
 88+ if ($this->mTemplate != '') { // build template code
 89+ $this->hasTemplates = true;
9590 $wikitext = ($this->mUserParam)?"|userparam=$this->mUserParam":'';
9691 $i = 1; // explicitly number parameters for more robust parsing (values may contain "=")
9792 foreach ($row as $field) {
@@ -102,14 +97,14 @@
10398 }
10499 $first_col = false;
105100 }
106 - $result .= '[[SMW::off]]{{' . $this->mTemplate . $wikitext . '}}[[SMW::on]]';
 101+ $result .= '{{' . $this->mTemplate . $wikitext . '}}';
107102 //str_replace('|', '&#x007C;', // encode '|' for use in templates (templates fail otherwise) -- this is not the place for doing this, since even DV-Wikitexts contain proper "|"!
108103 } else { // build simple list
109104 $first_col = true;
110105 $found_values = false; // has anything but the first column been printed?
111106 foreach ($row as $field) {
112107 $first_value = true;
113 - while ( ($text = $field->getNextText($outputmode, $this->getLinker($first_col))) !== false ) {
 108+ while ( ($text = $field->getNextText(SMW_OUTPUT_WIKI, $this->getLinker($first_col))) !== false ) {
114109 if (!$first_col && !$found_values) { // first values after first column
115110 $result .= ' (';
116111 $found_values = true;
@@ -120,7 +115,7 @@
121116 if ($first_value) { // first value in any column, print header
122117 $first_value = false;
123118 if ( $this->mShowHeaders && ('' != $field->getPrintRequest()->getLabel()) ) {
124 - $result .= $field->getPrintRequest()->getText($outputmode, $this->mLinker) . ' ';
 119+ $result .= $field->getPrintRequest()->getText(SMW_OUTPUT_WIKI, $this->mLinker) . ' ';
125120 }
126121 }
127122 $result .= $text; // actual output value
@@ -134,34 +129,13 @@
135130 $row = $nextrow;
136131 }
137132
138 - if ($usetemplate) {
139 - $old_smwgStoreActive = $smwgStoreActive;
140 - $smwgStoreActive = false; // no annotations stored, no factbox printed
141 - if ($outputmode == SMW_OUTPUT_WIKI) {
142 - if ( method_exists($parser, 'getPreprocessor') ) {
143 - $frame = $parser->getPreprocessor()->newFrame();
144 - $dom = $parser->preprocessToDom( $result );
145 - $result = $frame->expand( $dom );
146 - } else {
147 - $result = $parser->preprocess($result, $parsetitle, $parser_options);
148 - }
149 - } else { // SMW_OUTPUT_HTML, SMW_OUTPUT_FILE
150 - $parserOutput = $parser->parse($result, $parsetitle, $parser_options);
151 - $result = $parserOutput->getText();
152 - }
153 - $smwgStoreActive = $old_smwgStoreActive;
154 - }
155 -
156 - if ( $this->mInline && $res->hasFurtherResults() && ($this->mSearchlabel !== '') &&
157 - ( ('ol' != $this->mFormat) || ($this->mSearchlabel) ) ) {
 133+ // Make label for finding further results
 134+ if ( $this->linkFurtherResults($res) && ( ('ol' != $this->mFormat) || ($this->getSearchLabel(SMW_OUTPUT_WIKI)) ) ) {
158135 $link = $res->getQueryLink();
159 - if ($this->mSearchlabel) {
160 - $link->setCaption($this->mSearchlabel);
 136+ if ($this->getSearchLabel(SMW_OUTPUT_WIKI)) {
 137+ $link->setCaption($this->getSearchLabel(SMW_OUTPUT_WIKI));
161138 }
162 - // not needed for 'ul' (see below):
163 -// if ($this->mSep != '') {
164 -// $link->setParameter($this->mSep,'sep');
165 -// }
 139+ /// NOTE: passing the parameter sep is not needed, since we use format=ul
166140
167141 $link->setParameter('ul','format'); // always use ul, other formats hardly work as search page output
168142 if ($this->mTemplate != '') {
@@ -170,10 +144,10 @@
171145 $link->setParameter($this->m_params['link'],'link');
172146 }
173147 }
174 - $result .= $rowstart . $link->getText($outputmode,$this->mLinker) . $rowend;
 148+ $result .= $rowstart . $link->getText(SMW_OUTPUT_WIKI,$this->mLinker) . $rowend;
175149 }
176150
177 - // print footer
 151+ // Print footer:
178152 $result .= $footer;
179153 return $result;
180154 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_iCalendar.php
@@ -25,11 +25,6 @@
2626 }
2727 }
2828
29 - public function getResult($results, $params, $outputmode) { // skip checks, results with 0 entries are normal
30 - $this->readParameters($params,$outputmode);
31 - return $this->getResultText($results,$outputmode) . $this->getErrorString($results);
32 - }
33 -
3429 public function getMimeType($res) {
3530 return 'text/calendar';
3631 }
@@ -114,8 +109,8 @@
115110 }
116111 $result .= "END:VCALENDAR\r\n";
117112 } else { // just make link to feed
118 - if ($this->mSearchlabel) {
119 - $label = $this->mSearchlabel;
 113+ if ($this->getSearchLabel($outputmode)) {
 114+ $label = $this->getSearchLabel($outputmode);
120115 } else {
121116 wfLoadExtensionMessages('SemanticMediaWiki');
122117 $label = wfMsgForContent('smw_icalendar_link');
@@ -135,6 +130,7 @@
136131 }
137132
138133 $result .= $link->getText($outputmode,$this->mLinker);
 134+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
139135 }
140136
141137 return $result;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php
@@ -7,11 +7,11 @@
88
99 /**
1010 * Printer for creating a link to RSS feeds.
 11+ *
1112 * @author Denny Vrandecic
1213 * @author Markus Krötzsch
1314 * @note AUTOLOADED
1415 */
15 -
1616 class SMWRSSResultPrinter extends SMWResultPrinter {
1717 protected $m_title = '';
1818 protected $m_description = '';
@@ -26,11 +26,6 @@
2727 }
2828 }
2929
30 - public function getResult($results, $params, $outputmode) { // skip checks, results with 0 entries are normal
31 - $this->readParameters($params,$outputmode);
32 - return $this->getResultText($results,$outputmode) . $this->getErrorString($results);
33 - }
34 -
3530 public function getMimeType($res) {
3631 return 'application/rss+xml'; // or is rdf+xml better? Might be confused in either case (with RSS2.0 or RDF)
3732 }
@@ -101,8 +96,8 @@
10297 }
10398 $result .= "</rdf:RDF>";
10499 } else { // just make link to feed
105 - if ($this->mSearchlabel) {
106 - $label = $this->mSearchlabel;
 100+ if ($this->getSearchLabel($outputmode)) {
 101+ $label = $this->getSearchLabel($outputmode);
107102 } else {
108103 $label = wfMsgForContent('smw_rss_link');
109104 }
@@ -128,7 +123,7 @@
129124 }
130125
131126 $result .= $link->getText($outputmode,$this->mLinker);
132 -
 127+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
133128 smwfRequireHeadItem('rss' . $smwgIQRunningNumber, '<link rel="alternate" type="application/rss+xml" title="' . $this->m_title . '" href="' . $link->getURL() . '" />');
134129 }
135130
@@ -196,6 +191,7 @@
197192
198193 /**
199194 * Creates the RSS output for the single item.
 195+ * @bug This still clones $wgParser, change thisl
200196 */
201197 public function text() {
202198 global $wgServer, $wgParser, $smwgStoreActive, $smwgRSSWithPages;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
@@ -21,8 +21,7 @@
2222 if ('broadtable' == $this->mFormat)
2323 $widthpara = ' width="100%"';
2424 else $widthpara = '';
25 - $result = $this->mIntro .
26 - "<table class=\"smwtable\"$widthpara id=\"querytable" . $smwgIQRunningNumber . "\">\n";
 25+ $result = "<table class=\"smwtable\"$widthpara id=\"querytable" . $smwgIQRunningNumber . "\">\n";
2726 if ($this->mShowHeaders) { // building headers
2827 $result .= "\t<tr>\n";
2928 foreach ($res->getPrintRequests() as $pr) {
@@ -61,14 +60,15 @@
6261 }
6362
6463 // print further results footer
65 - if ( $this->mInline && $res->hasFurtherResults() && $this->mSearchlabel !== '') {
 64+ if ( $this->linkFurtherResults($res) ) {
6665 $link = $res->getQueryLink();
67 - if ($this->mSearchlabel) {
68 - $link->setCaption($this->mSearchlabel);
 66+ if ($this->getSearchLabel($outputmode)) {
 67+ $link->setCaption($this->getSearchLabel($outputmode));
6968 }
7069 $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText($outputmode,$this->mLinker) . "</td></tr>\n";
7170 }
7271 $result .= "</table>\n"; // print footer
 72+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
7373 return $result;
7474 }
7575
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Embedded.php
@@ -37,25 +37,23 @@
3838 }
3939
4040 protected function getResultText($res,$outputmode) {
41 - // handle factbox
42 - global $smwgStoreActive, $smwgEmbeddingList, $wgParser;
43 - $old_smwgStoreActive = $smwgStoreActive;
 41+ global $smwgEmbeddingList, $wgParser;
4442 $title = $wgParser->getTitle();
4543 if ($title === NULL) { // try that in emergency, needed in 1.11 in Special:Ask
4644 global $wgTitle;
4745 $title = $wgTitle;
4846 }
4947
50 - $smwgStoreActive = false; // no annotations stored, no factbox printed
5148 if (!isset($smwgEmbeddingList)) { // used to catch recursions, sometimes more restrictive than needed, but no major use cases should be affected by that!
52 - $smwgEmbeddingList = array($title);
53 - $oldEmbeddingList = array($title);
 49+ $smwgEmbeddingList = array($title->getPrefixedText());
 50+ $oldEmbeddingList = array($title->getPrefixedText());
5451 } else {
5552 $oldEmbeddingList = array_values($smwgEmbeddingList);
5653 }
5754
5855 // print header
59 - $result = $this->mIntro;
 56+ $result = '';
 57+ $this->hasTemplates = true;
6058
6159 switch ($this->m_embedformat) {
6260 case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6':
@@ -75,18 +73,14 @@
7674 break;
7775 }
7876
79 - // print all result rows
80 - $parser_options = new ParserOptions();
81 - $parser_options->setEditSection(false); // embedded sections should not have edit links
82 - $parser = clone $wgParser;
83 -
 77+ // Print all result rows:
8478 while ( $row = $res->getNext() ) {
8579 $first_col = true;
8680 foreach ($row as $field) {
8781 if ( $field->getPrintRequest()->getTypeID() == '_wpg' ) { // ensure that we deal with title-likes
8882 while ( ($object = $field->getNextObject()) !== false ) {
8983 $result .= $embstart;
90 - $text= $object->getLongText($outputmode,$this->getLinker(true));
 84+ $text= $object->getLongText(SMW_OUTPUT_WIKI,$this->getLinker(true));
9185 if ($this->m_showhead) {
9286 $result .= $headstart . $text . $headend;
9387 }
@@ -97,13 +91,7 @@
9892 } else {
9993 $articlename = $object->getLongWikiText();
10094 }
101 - if ($outputmode == SMW_OUTPUT_WIKI) {
102 -// $result .= '{{' . $articlename . '}}'; // fails in MW1.12 and later
103 - $result .= '[[SMW::off]]' . $parser->preprocess('{{' . $articlename . '}}', $title, $parser_options) . '[[SMW::on]]';
104 - } else { // SMW_OUTPUT_HTML, SMW_OUTPUT_FILE
105 - $parserOutput = $parser->parse('[[SMW::off]]{{' . $articlename . '}}[[SMW::on]]', $title, $parser_options);
106 - $result .= $parserOutput->getText();
107 - }
 95+ $result .= '{{' . $articlename . '}}';
10896 } else {
10997 $result .= '<b>' . $object->getLongWikiText() . '</b>';
11098 }
@@ -115,10 +103,10 @@
116104 }
117105
118106 // show link to more results
119 - if ( $this->mInline && $res->hasFurtherResults() && ($this->mSearchlabel !== '') ) {
 107+ if ( $this->linkFurtherResults($res) ) {
120108 $link = $res->getQueryLink();
121 - if ($this->mSearchlabel) {
122 - $link->setCaption($this->mSearchlabel);
 109+ if ($this->getSearchLabel(SMW_OUTPUT_WIKI)) {
 110+ $link->setCaption($this->getSearchLabel(SMW_OUTPUT_WIKI));
123111 }
124112 $link->setParameter('embedded','format');
125113 $format = $this->m_embedformat;
@@ -127,11 +115,10 @@
128116 if (!$this->m_showhead) {
129117 $link->setParameter('1','embedonly');
130118 }
131 - $result .= $embstart . $link->getText($outputmode,$this->mLinker) . $embend;
 119+ $result .= $embstart . $link->getText(SMW_OUTPUT_WIKI,$this->mLinker) . $embend;
132120 }
133121 $result .= $footer;
134122
135 - $smwgStoreActive = $old_smwgStoreActive;
136123 $smwgEmbeddingList = array_values($oldEmbeddingList);
137124 return $result;
138125 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_CSV.php
@@ -8,6 +8,7 @@
99 /**
1010 * Printer class for generating CSV output
1111 * @author Nathan R. Yergler
 12+ * @author Markus Krötzsch
1213 * @note AUTOLOADED
1314 */
1415 class SMWCsvResultPrinter extends SMWResultPrinter {
@@ -22,12 +23,6 @@
2324 }
2425 }
2526
26 - public function getResult($results, $params, $outputmode) {
27 - // skip checks, results with 0 entries are normal
28 - $this->readParameters($params,$outputmode);
29 - return $this->getResultText($results,$outputmode) . $this->getErrorString($results);
30 - }
31 -
3227 public function getMimeType($res) {
3328 return 'text/csv';
3429 }
@@ -37,7 +32,6 @@
3833 }
3934
4035 protected function getResultText($res, $outputmode) {
41 -
4236 global $smwgIQRunningNumber, $wgSitename, $wgServer, $wgRequest;
4337 $result = '';
4438
@@ -60,8 +54,8 @@
6155 rewind($csv);
6256 $result .= stream_get_contents($csv);
6357 } else { // just make link to feed
64 - if ($this->mSearchlabel) {
65 - $label = $this->mSearchlabel;
 58+ if ($this->getSearchLabel($outputmode)) {
 59+ $label = $this->getSearchLabel($outputmode);
6660 } else {
6761 wfLoadExtensionMessages('SemanticMediaWiki');
6862 $label = wfMsgForContent('smw_csv_link');
@@ -76,6 +70,7 @@
7771 $link->setParameter(100,'limit');
7872 }
7973 $result .= $link->getText($outputmode,$this->mLinker);
 74+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
8075 }
8176 return $result;
8277 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_vCard.php
@@ -16,18 +16,13 @@
1717 protected $m_title = '';
1818 protected $m_description = '';
1919
20 - public function getResult($results, $params, $outputmode) { // skip checks, results with 0 entries are normal
21 - $this->readParameters($params,$outputmode);
22 - return $this->getResultText($results,$outputmode) . $this->getErrorString($results);
23 - }
24 -
2520 public function getMimeType($res) {
2621 return 'text/x-vcard';
2722 }
2823
2924 public function getFileName($res) {
30 - if ($this->mSearchlabel != '') {
31 - return str_replace(' ', '_',$this->mSearchlabel) . '.vcf';
 25+ if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') {
 26+ return str_replace(' ', '_',$this->getSearchLabel(SMW_OUTPUT_WIKI)) . '.vcf';
3227 } else {
3328 return 'vCard.vcf';
3429 }
@@ -158,16 +153,16 @@
159154 $result .= $item->text();
160155 }
161156 } else { // just make link to vcard
162 - if ($this->mSearchlabel) {
163 - $label = $this->mSearchlabel;
 157+ if ($this->getSearchLabel($outputmode)) {
 158+ $label = $this->getSearchLabel($outputmode);
164159 } else {
165160 wfLoadExtensionMessages('SemanticMediaWiki');
166161 $label = wfMsgForContent('smw_vcard_link');
167162 }
168163 $link = $res->getQueryLink($label);
169164 $link->setParameter('vcard','format');
170 - if ($this->mSearchlabel != '') {
171 - $link->setParameter($this->mSearchlabel,'searchlabel');
 165+ if ($this->getSearchLabel(SMW_OUTPUT_WIKI) != '') {
 166+ $link->setParameter($this->getSearchLabel(SMW_OUTPUT_WIKI),'searchlabel');
172167 }
173168 if (array_key_exists('limit', $this->m_params)) {
174169 $link->setParameter($this->m_params['limit'],'limit');
@@ -175,6 +170,7 @@
176171 $link->setParameter(20,'limit');
177172 }
178173 $result .= $link->getText($outputmode,$this->mLinker);
 174+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
179175 }
180176 return $result;
181177 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php
@@ -190,6 +190,7 @@
191191
192192 // print footer
193193 $result .= "</div>";
 194+ $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed
194195 return $result;
195196 }
196197 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php
@@ -48,8 +48,9 @@
4949 $res->addErrors(array(wfMsgForContent('smw_notemplategiven')));
5050 return '';
5151 }
 52+ $this->hasTemplates = true;
5253
53 - $parserinput = $this->mIntro;
 54+ $result = '';
5455 while ( $row = $res->getNext() ) {
5556 $i = 1; // explicitly number parameters for more robust parsing (values may contain "=")
5657 $wikitext = ($this->m_userparam)?"|userparam=$this->m_userparam":'';
@@ -67,39 +68,21 @@
6869 }
6970 $firstcol = false;
7071 }
71 - $parserinput .= '[[SMW::off]]{{' . $this->m_template . $wikitext . '}}[[SMW::on]]';
 72+ $result .= '{{' . $this->m_template . $wikitext . '}}';
7273 }
7374
74 - $old_smwgStoreActive = $smwgStoreActive;
75 - $smwgStoreActive = false; // no annotations stored, no factbox printed
76 - $parser_options = new ParserOptions();
77 - $parser_options->setEditSection(false); // embedded sections should not have edit links
78 - $parser = clone $wgParser;
79 - if ($outputmode == SMW_OUTPUT_WIKI) {
80 - if ( method_exists($parser, 'getPreprocessor') ) {
81 - $frame = $parser->getPreprocessor()->newFrame();
82 - $dom = $parser->preprocessToDom( $parserinput );
83 - $result = $frame->expand( $dom );
84 - } else {
85 - $result = $parser->preprocess($parserinput, $parsetitle, $parser_options);
86 - }
87 - } else /* SMW_OUTPUT_HTML, SMW_OUTPUT_FILE */ {
88 - $parserOutput = $parser->parse($parserinput, $parsetitle, $parser_options);
89 - $result = $parserOutput->getText();
90 - }
91 - $smwgStoreActive = $old_smwgStoreActive;
9275 // show link to more results
93 - if ( $this->mInline && $res->hasFurtherResults() && ($this->mSearchlabel !== '') ) {
 76+ if ( $this->linkFurtherResults($res) ) {
9477 $link = $res->getQueryLink();
95 - if ($this->mSearchlabel) {
96 - $link->setCaption($this->mSearchlabel);
 78+ if ($this->getSearchLabel($outputmode)) {
 79+ $link->setCaption($this->getSearchLabel($outputmode));
9780 }
9881 $link->setParameter('template','format');
9982 $link->setParameter($this->m_template,'template');
10083 if (array_key_exists('link', $this->m_params)) { // linking may interfere with templates
10184 $link->setParameter($this->m_params['link'],'link');
10285 }
103 - $result .= $link->getText($outputmode,$this->mLinker);
 86+ $result .= $link->getText(SMW_OUTPUT_WIKI,$this->mLinker);
10487 }
10588 return $result;
10689 }

Status & tagging log