Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -15,20 +15,49 @@ |
16 | 16 | abstract class SMWResultPrinter { |
17 | 17 | |
18 | 18 | 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 | + |
19 | 32 | // parameters relevant for printers in general: |
20 | 33 | 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 |
23 | 34 | protected $mLinkFirst; // should article names of the first column be linked? |
24 | 35 | protected $mLinkOthers; // should article names of other columns (besides the first) be linked? |
25 | | - protected $mDefault = ''; // default return value for empty queries |
26 | 36 | protected $mShowHeaders = true; // should the headers (property names) be printed? |
27 | 37 | protected $mShowErrors = true; // should errors possibly be printed? |
28 | 38 | 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) |
29 | 39 | protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time. |
30 | | - |
31 | 40 | |
32 | 41 | /** |
| 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 | + /** |
33 | 62 | * Constructor. The parameter $format is a format string |
34 | 63 | * that may influence the processing details. |
35 | 64 | */ |
— | — | @@ -42,17 +71,27 @@ |
43 | 72 | } |
44 | 73 | |
45 | 74 | /** |
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. |
51 | 86 | */ |
52 | 87 | public function getResult($results, $params, $outputmode) { |
53 | 88 | $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 |
55 | 94 | if (!$results->hasFurtherResults()) { |
56 | | - return $this->mDefault . $this->getErrorString($results); |
| 95 | + return $this->escapeText($this->mDefault,$outputmode) . $this->getErrorString($results); |
57 | 96 | } elseif ($this->mInline) { |
58 | 97 | $label = $this->mSearchlabel; |
59 | 98 | if ($label === NULL) { //apply defaults |
— | — | @@ -60,14 +99,47 @@ |
61 | 100 | $label = wfMsgForContent('smw_iq_moreresults'); |
62 | 101 | } |
63 | 102 | if ($label != '') { |
64 | | - $link = $results->getQueryLink($label); |
| 103 | + $link = $results->getQueryLink($this->escapeText($label)); |
65 | 104 | $result = $link->getText($outputmode,$this->mLinker); |
| 105 | + } else { |
| 106 | + $result = ''; |
66 | 107 | } |
67 | 108 | $result .= $this->getErrorString($results); |
68 | 109 | return $result; |
69 | 110 | } |
70 | 111 | } |
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; |
72 | 144 | } |
73 | 145 | |
74 | 146 | /** |
— | — | @@ -79,15 +151,9 @@ |
80 | 152 | $this->m_params = $params; |
81 | 153 | if (array_key_exists('intro', $params)) { |
82 | 154 | $this->mIntro = str_replace('_',' ',$params['intro']); |
83 | | - if ($outputmode != SMW_OUTPUT_WIKI) { |
84 | | - $this->mIntro = htmlspecialchars($this->mIntro); |
85 | | - } |
86 | 155 | } |
87 | 156 | if (array_key_exists('searchlabel', $params)) { |
88 | 157 | $this->mSearchlabel = $params['searchlabel']; |
89 | | - if ($outputmode != SMW_OUTPUT_WIKI) { |
90 | | - $this->mSearchlabel = htmlspecialchars($this->mSearchlabel); |
91 | | - } |
92 | 158 | } |
93 | 159 | if (array_key_exists('link', $params)) { |
94 | 160 | switch (strtolower($params['link'])) { |
— | — | @@ -107,9 +173,6 @@ |
108 | 174 | } |
109 | 175 | if (array_key_exists('default', $params)) { |
110 | 176 | $this->mDefault = str_replace('_',' ',$params['default']); |
111 | | - if ($outputmode != SMW_OUTPUT_WIKI) { |
112 | | - $this->mDefault = htmlspecialchars($this->mDefault); |
113 | | - } |
114 | 177 | } |
115 | 178 | if (array_key_exists('headers', $params)) { |
116 | 179 | if ( 'hide' == strtolower(trim($params['headers']))) { |
— | — | @@ -141,10 +204,16 @@ |
142 | 205 | } |
143 | 206 | |
144 | 207 | /** |
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. |
149 | 218 | */ |
150 | 219 | public function getMimeType($res) { |
151 | 220 | return false; |
— | — | @@ -156,6 +225,8 @@ |
157 | 226 | * This function returns a filename that is to be sent to the caller |
158 | 227 | * in such a case (the default filename is created by browsers from the |
159 | 228 | * URL, and it is often not pretty). |
| 229 | + * |
| 230 | + * See also SMWResultPrinter::getMimeType() |
160 | 231 | */ |
161 | 232 | public function getFileName($res) { |
162 | 233 | return false; |
— | — | @@ -171,22 +242,48 @@ |
172 | 243 | } |
173 | 244 | |
174 | 245 | /** |
175 | | - * Change if errors should be shown- |
| 246 | + * Set whether errors should be shown. By default they are. |
176 | 247 | */ |
177 | 248 | public function setShowErrors($show) { |
178 | 249 | $this->mShowErrors = $show; |
179 | 250 | } |
180 | 251 | |
181 | 252 | /** |
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. |
183 | 255 | */ |
| 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 | + */ |
184 | 281 | public function getResultHTML($results, $params) { |
185 | 282 | return $this->getResult($results,$params,SMW_OUTPUT_HTML); |
186 | 283 | } |
187 | 284 | |
188 | 285 | /** |
189 | 286 | * 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. |
191 | 288 | */ |
192 | 289 | protected function getHTML($res) { |
193 | 290 | return $this->getResultText($res,SMW_OUTPUT_HTML); |
— | — | @@ -195,7 +292,7 @@ |
196 | 293 | /** |
197 | 294 | * Generate a link to further results of the given query, using syntactic encoding |
198 | 295 | * 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. |
200 | 297 | */ |
201 | 298 | protected function getFurtherResultsLink($outputmode, $res, $label) { |
202 | 299 | $link = $res->getQueryLink($label); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php |
— | — | @@ -27,9 +27,6 @@ |
28 | 28 | |
29 | 29 | if (array_key_exists('sep', $params)) { |
30 | 30 | $this->mSep = str_replace('_',' ',$params['sep']); |
31 | | - if ($outputmode != SMW_OUTPUT_WIKI) { |
32 | | - $this->mSep = htmlspecialchars($this->mSep); |
33 | | - } |
34 | 31 | } |
35 | 32 | if (array_key_exists('template', $params)) { |
36 | 33 | $this->mTemplate = trim($params['template']); |
— | — | @@ -39,6 +36,7 @@ |
40 | 37 | } |
41 | 38 | } |
42 | 39 | |
| 40 | + |
43 | 41 | protected function getResultText($res,$outputmode) { |
44 | 42 | global $smwgStoreActive, $wgParser; |
45 | 43 | $parsetitle = $wgParser->getTitle(); |
— | — | @@ -47,10 +45,9 @@ |
48 | 46 | $parsetitle = $wgTitle; |
49 | 47 | } |
50 | 48 | |
51 | | - // print header |
52 | | - $result = $this->mIntro; |
| 49 | + // Determine mark-up strings used around list items: |
53 | 50 | if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) { |
54 | | - $result .= '<' . $this->mFormat . '>'; |
| 51 | + $header = '<' . $this->mFormat . '>'; |
55 | 52 | $footer = '</' . $this->mFormat . '>'; |
56 | 53 | $rowstart = "\n\t<li>"; |
57 | 54 | $rowend = '</li>'; |
— | — | @@ -59,38 +56,36 @@ |
60 | 57 | if ($this->mSep != '') { |
61 | 58 | $listsep = $this->mSep; |
62 | 59 | $finallistsep = $listsep; |
63 | | - } else { // default list ", , , and, " |
| 60 | + } else { // default list ", , , and " |
64 | 61 | wfLoadExtensionMessages('SemanticMediaWiki'); |
65 | 62 | $listsep = ', '; |
66 | 63 | $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' '; |
67 | 64 | } |
| 65 | + $header = ''; |
68 | 66 | $footer = ''; |
69 | 67 | $rowstart = ''; |
70 | 68 | $rowend = ''; |
71 | 69 | $plainlist = true; |
72 | 70 | } |
73 | 71 | |
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; |
82 | 75 | |
83 | | - // print all result rows |
| 76 | + // Print all result rows: |
84 | 77 | $first_row = true; |
85 | 78 | $row = $res->getNext(); |
86 | 79 | while ( $row !== false ) { |
87 | 80 | $nextrow = $res->getNext(); // look ahead |
88 | 81 | 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 | + } |
92 | 86 | |
93 | 87 | $first_col = true; |
94 | | - if ($usetemplate) { // build template code |
| 88 | + if ($this->mTemplate != '') { // build template code |
| 89 | + $this->hasTemplates = true; |
95 | 90 | $wikitext = ($this->mUserParam)?"|userparam=$this->mUserParam":''; |
96 | 91 | $i = 1; // explicitly number parameters for more robust parsing (values may contain "=") |
97 | 92 | foreach ($row as $field) { |
— | — | @@ -102,14 +97,14 @@ |
103 | 98 | } |
104 | 99 | $first_col = false; |
105 | 100 | } |
106 | | - $result .= '[[SMW::off]]{{' . $this->mTemplate . $wikitext . '}}[[SMW::on]]'; |
| 101 | + $result .= '{{' . $this->mTemplate . $wikitext . '}}'; |
107 | 102 | //str_replace('|', '|', // encode '|' for use in templates (templates fail otherwise) -- this is not the place for doing this, since even DV-Wikitexts contain proper "|"! |
108 | 103 | } else { // build simple list |
109 | 104 | $first_col = true; |
110 | 105 | $found_values = false; // has anything but the first column been printed? |
111 | 106 | foreach ($row as $field) { |
112 | 107 | $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 ) { |
114 | 109 | if (!$first_col && !$found_values) { // first values after first column |
115 | 110 | $result .= ' ('; |
116 | 111 | $found_values = true; |
— | — | @@ -120,7 +115,7 @@ |
121 | 116 | if ($first_value) { // first value in any column, print header |
122 | 117 | $first_value = false; |
123 | 118 | if ( $this->mShowHeaders && ('' != $field->getPrintRequest()->getLabel()) ) { |
124 | | - $result .= $field->getPrintRequest()->getText($outputmode, $this->mLinker) . ' '; |
| 119 | + $result .= $field->getPrintRequest()->getText(SMW_OUTPUT_WIKI, $this->mLinker) . ' '; |
125 | 120 | } |
126 | 121 | } |
127 | 122 | $result .= $text; // actual output value |
— | — | @@ -134,34 +129,13 @@ |
135 | 130 | $row = $nextrow; |
136 | 131 | } |
137 | 132 | |
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)) ) ) { |
158 | 135 | $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)); |
161 | 138 | } |
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 |
166 | 140 | |
167 | 141 | $link->setParameter('ul','format'); // always use ul, other formats hardly work as search page output |
168 | 142 | if ($this->mTemplate != '') { |
— | — | @@ -170,10 +144,10 @@ |
171 | 145 | $link->setParameter($this->m_params['link'],'link'); |
172 | 146 | } |
173 | 147 | } |
174 | | - $result .= $rowstart . $link->getText($outputmode,$this->mLinker) . $rowend; |
| 148 | + $result .= $rowstart . $link->getText(SMW_OUTPUT_WIKI,$this->mLinker) . $rowend; |
175 | 149 | } |
176 | 150 | |
177 | | - // print footer |
| 151 | + // Print footer: |
178 | 152 | $result .= $footer; |
179 | 153 | return $result; |
180 | 154 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_iCalendar.php |
— | — | @@ -25,11 +25,6 @@ |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
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 | | - |
34 | 29 | public function getMimeType($res) { |
35 | 30 | return 'text/calendar'; |
36 | 31 | } |
— | — | @@ -114,8 +109,8 @@ |
115 | 110 | } |
116 | 111 | $result .= "END:VCALENDAR\r\n"; |
117 | 112 | } else { // just make link to feed |
118 | | - if ($this->mSearchlabel) { |
119 | | - $label = $this->mSearchlabel; |
| 113 | + if ($this->getSearchLabel($outputmode)) { |
| 114 | + $label = $this->getSearchLabel($outputmode); |
120 | 115 | } else { |
121 | 116 | wfLoadExtensionMessages('SemanticMediaWiki'); |
122 | 117 | $label = wfMsgForContent('smw_icalendar_link'); |
— | — | @@ -135,6 +130,7 @@ |
136 | 131 | } |
137 | 132 | |
138 | 133 | $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 |
139 | 135 | } |
140 | 136 | |
141 | 137 | return $result; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_RSSlink.php |
— | — | @@ -7,11 +7,11 @@ |
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Printer for creating a link to RSS feeds. |
| 11 | + * |
11 | 12 | * @author Denny Vrandecic |
12 | 13 | * @author Markus Krötzsch |
13 | 14 | * @note AUTOLOADED |
14 | 15 | */ |
15 | | - |
16 | 16 | class SMWRSSResultPrinter extends SMWResultPrinter { |
17 | 17 | protected $m_title = ''; |
18 | 18 | protected $m_description = ''; |
— | — | @@ -26,11 +26,6 @@ |
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
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 | | - |
35 | 30 | public function getMimeType($res) { |
36 | 31 | return 'application/rss+xml'; // or is rdf+xml better? Might be confused in either case (with RSS2.0 or RDF) |
37 | 32 | } |
— | — | @@ -101,8 +96,8 @@ |
102 | 97 | } |
103 | 98 | $result .= "</rdf:RDF>"; |
104 | 99 | } else { // just make link to feed |
105 | | - if ($this->mSearchlabel) { |
106 | | - $label = $this->mSearchlabel; |
| 100 | + if ($this->getSearchLabel($outputmode)) { |
| 101 | + $label = $this->getSearchLabel($outputmode); |
107 | 102 | } else { |
108 | 103 | $label = wfMsgForContent('smw_rss_link'); |
109 | 104 | } |
— | — | @@ -128,7 +123,7 @@ |
129 | 124 | } |
130 | 125 | |
131 | 126 | $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 |
133 | 128 | smwfRequireHeadItem('rss' . $smwgIQRunningNumber, '<link rel="alternate" type="application/rss+xml" title="' . $this->m_title . '" href="' . $link->getURL() . '" />'); |
134 | 129 | } |
135 | 130 | |
— | — | @@ -196,6 +191,7 @@ |
197 | 192 | |
198 | 193 | /** |
199 | 194 | * Creates the RSS output for the single item. |
| 195 | + * @bug This still clones $wgParser, change thisl |
200 | 196 | */ |
201 | 197 | public function text() { |
202 | 198 | global $wgServer, $wgParser, $smwgStoreActive, $smwgRSSWithPages; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
— | — | @@ -21,8 +21,7 @@ |
22 | 22 | if ('broadtable' == $this->mFormat) |
23 | 23 | $widthpara = ' width="100%"'; |
24 | 24 | 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"; |
27 | 26 | if ($this->mShowHeaders) { // building headers |
28 | 27 | $result .= "\t<tr>\n"; |
29 | 28 | foreach ($res->getPrintRequests() as $pr) { |
— | — | @@ -61,14 +60,15 @@ |
62 | 61 | } |
63 | 62 | |
64 | 63 | // print further results footer |
65 | | - if ( $this->mInline && $res->hasFurtherResults() && $this->mSearchlabel !== '') { |
| 64 | + if ( $this->linkFurtherResults($res) ) { |
66 | 65 | $link = $res->getQueryLink(); |
67 | | - if ($this->mSearchlabel) { |
68 | | - $link->setCaption($this->mSearchlabel); |
| 66 | + if ($this->getSearchLabel($outputmode)) { |
| 67 | + $link->setCaption($this->getSearchLabel($outputmode)); |
69 | 68 | } |
70 | 69 | $result .= "\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> ' . $link->getText($outputmode,$this->mLinker) . "</td></tr>\n"; |
71 | 70 | } |
72 | 71 | $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 |
73 | 73 | return $result; |
74 | 74 | } |
75 | 75 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Embedded.php |
— | — | @@ -37,25 +37,23 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | protected function getResultText($res,$outputmode) { |
41 | | - // handle factbox |
42 | | - global $smwgStoreActive, $smwgEmbeddingList, $wgParser; |
43 | | - $old_smwgStoreActive = $smwgStoreActive; |
| 41 | + global $smwgEmbeddingList, $wgParser; |
44 | 42 | $title = $wgParser->getTitle(); |
45 | 43 | if ($title === NULL) { // try that in emergency, needed in 1.11 in Special:Ask |
46 | 44 | global $wgTitle; |
47 | 45 | $title = $wgTitle; |
48 | 46 | } |
49 | 47 | |
50 | | - $smwgStoreActive = false; // no annotations stored, no factbox printed |
51 | 48 | 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()); |
54 | 51 | } else { |
55 | 52 | $oldEmbeddingList = array_values($smwgEmbeddingList); |
56 | 53 | } |
57 | 54 | |
58 | 55 | // print header |
59 | | - $result = $this->mIntro; |
| 56 | + $result = ''; |
| 57 | + $this->hasTemplates = true; |
60 | 58 | |
61 | 59 | switch ($this->m_embedformat) { |
62 | 60 | case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6': |
— | — | @@ -75,18 +73,14 @@ |
76 | 74 | break; |
77 | 75 | } |
78 | 76 | |
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: |
84 | 78 | while ( $row = $res->getNext() ) { |
85 | 79 | $first_col = true; |
86 | 80 | foreach ($row as $field) { |
87 | 81 | if ( $field->getPrintRequest()->getTypeID() == '_wpg' ) { // ensure that we deal with title-likes |
88 | 82 | while ( ($object = $field->getNextObject()) !== false ) { |
89 | 83 | $result .= $embstart; |
90 | | - $text= $object->getLongText($outputmode,$this->getLinker(true)); |
| 84 | + $text= $object->getLongText(SMW_OUTPUT_WIKI,$this->getLinker(true)); |
91 | 85 | if ($this->m_showhead) { |
92 | 86 | $result .= $headstart . $text . $headend; |
93 | 87 | } |
— | — | @@ -97,13 +91,7 @@ |
98 | 92 | } else { |
99 | 93 | $articlename = $object->getLongWikiText(); |
100 | 94 | } |
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 . '}}'; |
108 | 96 | } else { |
109 | 97 | $result .= '<b>' . $object->getLongWikiText() . '</b>'; |
110 | 98 | } |
— | — | @@ -115,10 +103,10 @@ |
116 | 104 | } |
117 | 105 | |
118 | 106 | // show link to more results |
119 | | - if ( $this->mInline && $res->hasFurtherResults() && ($this->mSearchlabel !== '') ) { |
| 107 | + if ( $this->linkFurtherResults($res) ) { |
120 | 108 | $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)); |
123 | 111 | } |
124 | 112 | $link->setParameter('embedded','format'); |
125 | 113 | $format = $this->m_embedformat; |
— | — | @@ -127,11 +115,10 @@ |
128 | 116 | if (!$this->m_showhead) { |
129 | 117 | $link->setParameter('1','embedonly'); |
130 | 118 | } |
131 | | - $result .= $embstart . $link->getText($outputmode,$this->mLinker) . $embend; |
| 119 | + $result .= $embstart . $link->getText(SMW_OUTPUT_WIKI,$this->mLinker) . $embend; |
132 | 120 | } |
133 | 121 | $result .= $footer; |
134 | 122 | |
135 | | - $smwgStoreActive = $old_smwgStoreActive; |
136 | 123 | $smwgEmbeddingList = array_values($oldEmbeddingList); |
137 | 124 | return $result; |
138 | 125 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_CSV.php |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | /** |
10 | 10 | * Printer class for generating CSV output |
11 | 11 | * @author Nathan R. Yergler |
| 12 | + * @author Markus Krötzsch |
12 | 13 | * @note AUTOLOADED |
13 | 14 | */ |
14 | 15 | class SMWCsvResultPrinter extends SMWResultPrinter { |
— | — | @@ -22,12 +23,6 @@ |
23 | 24 | } |
24 | 25 | } |
25 | 26 | |
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 | | - |
32 | 27 | public function getMimeType($res) { |
33 | 28 | return 'text/csv'; |
34 | 29 | } |
— | — | @@ -37,7 +32,6 @@ |
38 | 33 | } |
39 | 34 | |
40 | 35 | protected function getResultText($res, $outputmode) { |
41 | | - |
42 | 36 | global $smwgIQRunningNumber, $wgSitename, $wgServer, $wgRequest; |
43 | 37 | $result = ''; |
44 | 38 | |
— | — | @@ -60,8 +54,8 @@ |
61 | 55 | rewind($csv); |
62 | 56 | $result .= stream_get_contents($csv); |
63 | 57 | } else { // just make link to feed |
64 | | - if ($this->mSearchlabel) { |
65 | | - $label = $this->mSearchlabel; |
| 58 | + if ($this->getSearchLabel($outputmode)) { |
| 59 | + $label = $this->getSearchLabel($outputmode); |
66 | 60 | } else { |
67 | 61 | wfLoadExtensionMessages('SemanticMediaWiki'); |
68 | 62 | $label = wfMsgForContent('smw_csv_link'); |
— | — | @@ -76,6 +70,7 @@ |
77 | 71 | $link->setParameter(100,'limit'); |
78 | 72 | } |
79 | 73 | $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 |
80 | 75 | } |
81 | 76 | return $result; |
82 | 77 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_vCard.php |
— | — | @@ -16,18 +16,13 @@ |
17 | 17 | protected $m_title = ''; |
18 | 18 | protected $m_description = ''; |
19 | 19 | |
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 | | - |
25 | 20 | public function getMimeType($res) { |
26 | 21 | return 'text/x-vcard'; |
27 | 22 | } |
28 | 23 | |
29 | 24 | 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'; |
32 | 27 | } else { |
33 | 28 | return 'vCard.vcf'; |
34 | 29 | } |
— | — | @@ -158,16 +153,16 @@ |
159 | 154 | $result .= $item->text(); |
160 | 155 | } |
161 | 156 | } else { // just make link to vcard |
162 | | - if ($this->mSearchlabel) { |
163 | | - $label = $this->mSearchlabel; |
| 157 | + if ($this->getSearchLabel($outputmode)) { |
| 158 | + $label = $this->getSearchLabel($outputmode); |
164 | 159 | } else { |
165 | 160 | wfLoadExtensionMessages('SemanticMediaWiki'); |
166 | 161 | $label = wfMsgForContent('smw_vcard_link'); |
167 | 162 | } |
168 | 163 | $link = $res->getQueryLink($label); |
169 | 164 | $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'); |
172 | 167 | } |
173 | 168 | if (array_key_exists('limit', $this->m_params)) { |
174 | 169 | $link->setParameter($this->m_params['limit'],'limit'); |
— | — | @@ -175,6 +170,7 @@ |
176 | 171 | $link->setParameter(20,'limit'); |
177 | 172 | } |
178 | 173 | $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 |
179 | 175 | } |
180 | 176 | return $result; |
181 | 177 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php |
— | — | @@ -190,6 +190,7 @@ |
191 | 191 | |
192 | 192 | // print footer |
193 | 193 | $result .= "</div>"; |
| 194 | + $this->isHTML = ($outputmode == SMW_OUTPUT_HTML); // yes, our code can be viewed as HTML if requested, no more parsing needed |
194 | 195 | return $result; |
195 | 196 | } |
196 | 197 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php |
— | — | @@ -48,8 +48,9 @@ |
49 | 49 | $res->addErrors(array(wfMsgForContent('smw_notemplategiven'))); |
50 | 50 | return ''; |
51 | 51 | } |
| 52 | + $this->hasTemplates = true; |
52 | 53 | |
53 | | - $parserinput = $this->mIntro; |
| 54 | + $result = ''; |
54 | 55 | while ( $row = $res->getNext() ) { |
55 | 56 | $i = 1; // explicitly number parameters for more robust parsing (values may contain "=") |
56 | 57 | $wikitext = ($this->m_userparam)?"|userparam=$this->m_userparam":''; |
— | — | @@ -67,39 +68,21 @@ |
68 | 69 | } |
69 | 70 | $firstcol = false; |
70 | 71 | } |
71 | | - $parserinput .= '[[SMW::off]]{{' . $this->m_template . $wikitext . '}}[[SMW::on]]'; |
| 72 | + $result .= '{{' . $this->m_template . $wikitext . '}}'; |
72 | 73 | } |
73 | 74 | |
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; |
92 | 75 | // show link to more results |
93 | | - if ( $this->mInline && $res->hasFurtherResults() && ($this->mSearchlabel !== '') ) { |
| 76 | + if ( $this->linkFurtherResults($res) ) { |
94 | 77 | $link = $res->getQueryLink(); |
95 | | - if ($this->mSearchlabel) { |
96 | | - $link->setCaption($this->mSearchlabel); |
| 78 | + if ($this->getSearchLabel($outputmode)) { |
| 79 | + $link->setCaption($this->getSearchLabel($outputmode)); |
97 | 80 | } |
98 | 81 | $link->setParameter('template','format'); |
99 | 82 | $link->setParameter($this->m_template,'template'); |
100 | 83 | if (array_key_exists('link', $this->m_params)) { // linking may interfere with templates |
101 | 84 | $link->setParameter($this->m_params['link'],'link'); |
102 | 85 | } |
103 | | - $result .= $link->getText($outputmode,$this->mLinker); |
| 86 | + $result .= $link->getText(SMW_OUTPUT_WIKI,$this->mLinker); |
104 | 87 | } |
105 | 88 | return $result; |
106 | 89 | } |