Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -82,8 +82,19 @@ |
83 | 83 | * |
84 | 84 | * For outputs SMW_OUTPUT_WIKI and SMW_OUTPUT_HTML, error messages or standard "further results" links |
85 | 85 | * are directly generated and appended. For SMW_OUTPUT_FILE, only the plain generated text is returned. |
| 86 | + * |
| 87 | + * @note A note on recursion: some query printers may return wiki code that comes from other pages, |
| 88 | + * e.g. from templates that are used in formatting or from embedded result pages. Both kinds of pages |
| 89 | + * may contain \#ask queries that do again use new pages, so we must care about recursion. We do so |
| 90 | + * by simply counting how often this method starts a subparse and stopping at depth 2. There is one |
| 91 | + * special case: if this method is called outside parsing, and the concrete printer returns wiki text, |
| 92 | + * and wiki text is requested, then we may return wiki text with sub-queries to the caller. If the |
| 93 | + * caller parses this (which is likely) then this will again call us in parse-context and all recursion |
| 94 | + * checks catch. Only the first level of parsing is done outside and thus not counted. Thus you |
| 95 | + * effectively can get down to level 3. |
86 | 96 | */ |
87 | 97 | public function getResult($results, $params, $outputmode) { |
| 98 | + global $wgParser; |
88 | 99 | $this->isHTML = false; |
89 | 100 | $this->hasTemplates = false; |
90 | 101 | $this->readParameters($params,$outputmode); |
— | — | @@ -118,27 +129,37 @@ |
119 | 130 | } |
120 | 131 | $result .= $this->getErrorString($results); // append errors |
121 | 132 | if ( (!$this->isHTML) && ($this->hasTemplates) ) { // preprocess embedded templates if needed |
122 | | - global $wgParser; |
123 | | - SMWResultPrinter::$mRecursionDepth++; |
124 | | - if (SMWResultPrinter::$mRecursionDepth <= 2) { // restrict recursion |
125 | | - $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]'; |
| 133 | + if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) { |
| 134 | + SMWResultPrinter::$mRecursionDepth++; |
| 135 | + if (SMWResultPrinter::$mRecursionDepth <= 2) { // restrict recursion |
| 136 | + $result = '[[SMW::off]]' . $wgParser->replaceVariables($result) . '[[SMW::on]]'; |
| 137 | + } else { |
| 138 | + $result = ''; /// TODO: explain problem (too much recursive parses) |
| 139 | + } |
| 140 | + SMWResultPrinter::$mRecursionDepth--; |
| 141 | + } else { // not during parsing, no preprocessing needed, still protect the result |
| 142 | + $result = '[[SMW::off]]' . $result . '[[SMW::on]]'; |
126 | 143 | } |
127 | | - SMWResultPrinter::$mRecursionDepth--; |
128 | 144 | } |
129 | 145 | |
130 | 146 | if ( ($this->isHTML) && ($outputmode == SMW_OUTPUT_WIKI) ) { |
131 | 147 | $result = array($result, 'isHTML' => true); |
132 | 148 | } elseif ( (!$this->isHTML) && ($outputmode == SMW_OUTPUT_HTML) ) { |
133 | | - global $wgParser; |
| 149 | + SMWResultPrinter::$mRecursionDepth++; |
134 | 150 | // check whether we are in an existing parse, or if we should start a new parse for $wgTitle |
135 | | - if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) { |
136 | | - $result = $wgParser->recursiveTagParse($result); |
| 151 | + if (SMWResultPrinter::$mRecursionDepth <= 2) { // retrict recursion |
| 152 | + if ( ($wgParser->getTitle() instanceof Title) && ($wgParser->getOptions() instanceof ParserOptions) ) { |
| 153 | + $result = $wgParser->recursiveTagParse($result); |
| 154 | + } else { |
| 155 | + global $wgTitle; |
| 156 | + $popt = new ParserOptions(); |
| 157 | + $pout = $wgParser->parse($result, $wgTitle, $popt); |
| 158 | + $result = $pout->getText(); |
| 159 | + } |
137 | 160 | } else { |
138 | | - global $wgTitle; |
139 | | - $popt = new ParserOptions(); |
140 | | - $pout = $wgParser->parse($result, $wgTitle, $popt); |
141 | | - $result = $pout->getText(); |
| 161 | + $result = ''; /// TODO: explain problem (too much recursive parses) |
142 | 162 | } |
| 163 | + SMWResultPrinter::$mRecursionDepth--; |
143 | 164 | } |
144 | 165 | |
145 | 166 | if ( ($this->mIntro) && ($results->getCount() > 0) ) { |